This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]