Re: [xsl] incrementing a counter in XSL

Subject: Re: [xsl] incrementing a counter in XSL
From: becky.foley@xxxxxxxxxxxxxx
Date: Fri, 19 Apr 2002 09:39:01 -0400
Thanks! This worked much better.  Thanks Wendell for the other option as
well.



Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>@lists.mulberrytech.com
Thursday April 18, 2002 03:12 PM

Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx

Sent by:    owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx

To:    xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc:
Subject:    Re: [xsl] incrementing a counter in XSL


At 12:05 PM 4/18/2002, you wrote:
>I am selecting some nodes from an XML doc with an if statment in a
for-each
>loop.  Out of the set of nodes I am looping through, I am only selecting
>some in the if statment.  Each of these nodes that is selected by the if
>statement needs a sequence number.  Originally I was using :
>   <xsl:for-each select="Contract/TermRdr">
>     <xsl:if test="StatusCd='A' or StatusCd='F'">
>       <SequenceNum fieldType="Short" elementType="field">
>         <xsl:number value ="position()"/>
>       </SequenceNum>
>       ....
>     </xsl:if>
>   </xsl:for-each>

   First, don't try to implement a counter.  There's a different way to do
it in the XSLT mindset.  Assuming that the provided xsl:if is the only test
that you perform for each run through the xsl:for-each loop (I assume this
due to the position of the ellipses), you can select your exact nodes
during the xsl:for-each and forget about the xsl:if.

   <xsl:for-each select="Contract/TermRdr[StatusCd='A' or StatusCd='F']">
     <SequenceNum fieldType="Short" elementType="field">
       <xsl:number value ="position()"/>
     </SequenceNum>
     ....
   </xsl:for-each>

   position() gives the position of the current element in relation to the
others of the selected node-set, not the absolute value from the document
order.


Greg Faron
Integre Technical Publishing Co.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list









 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread