Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 13th, 2007, 05:09 AM
Authorized User
 
Join Date: Feb 2007
Location: CHENNAI, TAMILNADU, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SOMANATHAN10
Default CALLING A TEMPLATE WITHIN JAVA SCRIPT

I'm trying to call an xsl:template within a java script.
But the template "simp" is not called.
Please Follow the code snippet I am trying to implement.
If anybody have ideas on how to work xsl with javascript,please share.

<script language="javascript">
          var a=0;
          function s()
          {
    alert("hai");
    <xsl:call-template name="simp">
    <xsl:with-param name="a" select="2"/>
    </xsl:call-template>
              }
      </script>

    <xsl:template name="simp">
    <xsl:param name="a"/>
    <xsl:value-of select="$a"/>
    </xsl:template>

C.SOMA
__________________
C.SOMA
Reply With Quote
  #2 (permalink)  
Old February 13th, 2007, 05:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You'll have to explain the context a bit more. If you are trying to construct client-side script using XSLT then that's perfectly valid. If you are trying to apply templates whilst running the script then that's not possible.

Make sure you've got the process clear in your mind
  • XSLT transforms XML to HTML
  • HTML interpreted by browser and client-side script executed
Once you move to step two then XSLT is a distant memory.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old February 13th, 2007, 06:13 AM
Authorized User
 
Join Date: Feb 2007
Location: CHENNAI, TAMILNADU, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SOMANATHAN10
Default

My requirement is like this.

I need to repeat the header between every 10th line in my xsl.
For most of the files I have done it with <xsl:if test="position() mod 10 = 1">
and succeded.
In one of the file I am not able to implement the same logic since the position() is changing frequently.

I know that in xsl reassigning of variable is not possible.

Since the for-loop is followed by a if condition the position value changes.

I want to find out how many times this if condition gets satisfied?

 <xsl:for-each select="/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary/rs:sunAlertId[generate-id()=generate-id(key(&apos;distinct-segcode&apos;,.))]">
                                    <xsl:sort order="ascending" select="."/>
                                    <xsl:variable name="SA" select="."/>
                                    <xsl:if test="count(/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary[rs:sunAlertId=$SA]/rs:oriNext/rs:oriNextList/rs:oriRule[rs:severity = 'Critical']) &gt; 0">




C.SOMA
Reply With Quote
  #4 (permalink)  
Old February 13th, 2007, 07:29 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try changing the <xsl:if> condition to be a predicate on the select expression of the xsl:for-each, so position() counts the elements that satisfy the condition.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old February 13th, 2007, 08:04 AM
Authorized User
 
Join Date: Feb 2007
Location: CHENNAI, TAMILNADU, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SOMANATHAN10
Default

Michael,

I am new to xsl.Can I see any example on how to use this predicate?

C.SOMA
Reply With Quote
  #6 (permalink)  
Old February 13th, 2007, 09:18 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Wherever you see something like

<xsl:for-each select="x/y/z">
  <xsl:if test="a = b">
    ... something ...
  </xsl:if>
</xsl:for-each>

it can be replaced by

<xsl:for-each select="x/y/z[a = b]">
    ... something ...
</xsl:for-each>

The only difference is that it changes the values of position() and last() to reflect the items you are actually processing.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old February 14th, 2007, 02:10 AM
Authorized User
 
Join Date: Feb 2007
Location: CHENNAI, TAMILNADU, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SOMANATHAN10
Default

Mich,

I tried as you told. But it seems like the if condition is not satisfied if we used like
this.

Previously it was like this:

<xsl:for-each select="/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary/rs:sunAlertId[generate-id()=generate-id(key(&apos;distinct-segcode&apos;,.))]">
                                    <xsl:sort order="ascending" select="."/>
                                    <xsl:variable name="SA" select="."/>
<xsl:if test="count(/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary[rs:sunAlertId=$SA]/rs:oriNext/rs:oriNextList/rs:oriRule[rs:severity = 'Critical']) &gt; 0">


After change:
=============


 <xsl:for-each select="/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary/rs:sunAlertId[generate-id()=generate-id(key(&apos;distinct-segcode&apos;,.))][count(/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary/rs:sunAlertId/rs:oriNext/rs:oriNextList/rs:oriRule[rs:severity = 'Critical']) &gt; 0]">


C.SOMA
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling template with javascript smys123 XSLT 3 November 22nd, 2007 04:13 AM
template calling kgoldvas XSLT 1 August 1st, 2007 10:20 AM
template calling kgoldvas XSLT 1 July 10th, 2007 07:16 AM
Java script function is not calling in Mozilla mouli_sam ASP.NET 1.0 and 1.1 Professional 0 May 9th, 2006 01:44 AM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM



All times are GMT -4. The time now is 01:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.