RE: [xsl] Help with staregies for outputting an incremental number in xslt

Subject: RE: [xsl] Help with staregies for outputting an incremental number in xslt
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 29 Nov 2007 16:29:43 -0000
I don't understand what you mean by "omitted nodes" (I have trouble
discussing non-existent objects). If position() counts it, then it must be
there. Please show us your XML to illustrate what you are talking about.

Incidentally, please don't do this:

>    <xsl:variable name="description">
>      <xsl:value-of select="../../expensys:ItemDescription"/>
>    </xsl:variable>

when you mean this:

>    <xsl:variable name="description"
select="../../expensys:ItemDescription"/>

It's the kind of thing that gives XSLT an undeserved reputation for being
verbose and slow.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Adam Lipscombe [mailto:adam.lipscombe@xxxxxxxxxx] 
> Sent: 29 November 2007 16:16
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Help with staregies for outputting an 
> incremental number in xslt
> 
> Hello
> 
> 
> Firstly, I am an inexperienced xslt user, so please forgive 
> me if this a no-brainer.
> 
> My problem is this:
> I have a list of nodes, and I need to output a node count 
> with each node.
> I use the position() function to output the node count. So 
> far so good.
> 
> Recently however, the requirement has changed: under certain 
> circumstances a node is ommited from the output.  When a node 
> is ommitted, the node count of the subsequent node is 
> incorrect - because the position() function counts all nodes, 
> including the omitted ones.
> 
> 
> e.g.:
> 
> <xsl:for-each 
> select="expensys:Lines/expensys:Line/expensys:Accruals/expensy
> s:Accrual">
> 
>    <xsl:variable name="description">
>      <xsl:value-of select="../../expensys:ItemDescription"/>
>    </xsl:variable>
> 
>    <!-- Node ommission
>         Set includeLine=false for personal spend lines with 
> CorpCardRec personal settlement
>         as we dont want to output these -->
>     <xsl:variable name="includeLine">
>       <xsl:choose>
>         <xsl:when test="$description = 'Personal Spend'">
>           <xsl:if test="$transactionType = 
> 'CorporateCardReconciliation'">				
>            <xsl:if 
> test="$corporateCardSettlementType = 'corporate'">		
> 			             <xsl:value-of 
> select="true()"/>						
> 		           </xsl:if>				
> 							        
>    <xsl:if 
> test="$corporateCardSettlementType = 'personal'">		
> 			             <xsl:value-of 
> select="false()"/>						
> 		           </xsl:if>
>           </xsl:if>
>           <xsl:if test="$transactionType != 
> 'CorporateCardReconciliation'">				 
> <xsl:value-of select="true()"/>
>           </xsl:if>
>         </xsl:when>
>         <xsl:otherwise>					
> 						         
> <xsl:value-of select="true()"/>
>         </xsl:otherwise>
>       </xsl:choose>
>     </xsl:variable>
> 
>     <xsl:if test="$includeLine='true'">
>       <txn:Line>						
> 					
>         <txn:Number>						
> 					         <xsl:value-of 
> select="position()"/>
>         <txn:Number>
> 
>         <!-- More data from node is output here..... --!>
> 
>       </txn:Line>						
> 					
>     </xsl:if>
> 
> 
> 
> I need the value of txn:Number to increment contigously, but 
> this recent node ommission has thrown a spanner in the works :-(
> 
> I have searched through the forums and discovered its not 
> possible to increment a variable in a for-each loop.  Can 
> anyone guide me to a solution?.
> 
> 
> 
> Many thanks in advance....
> 
> Adam

Current Thread