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

Subject: [xsl] Help with staregies for outputting an incremental number in xslt
From: Adam Lipscombe <adam.lipscombe@xxxxxxxxxx>
Date: Thu, 29 Nov 2007 16:15:37 +0000

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.


<xsl:for-each select="expensys:Lines/expensys:Line/expensys:Accruals/expensys:Accrual">

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

<!-- 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: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 test="$transactionType != 'CorporateCardReconciliation'"> <xsl:value-of select="true()"/>
<xsl:otherwise> <xsl:value-of select="true()"/>

   <xsl:if test="$includeLine='true'">
       <txn:Number>											         <xsl:value-of select="position()"/>

<!-- More data from node is output here..... --!>


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....


Current Thread