Reputation: 5573
In a for-each Im using to send 1,2,3,4 for each loop. I would like the count to start at 2 instead of 1. Is that possible?
<xsl:for-each select="BidFeeList/BidFee">
<xsl:call-template name="chargeField">
<xsl:with-param name="fieldIndex"><xsl:number/></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
So the for each would call chargeField template with 2 and then 3,4,5... etc
Upvotes: 0
Views: 136
Reputation: 464
If I understand you correctly, you have n BidFeeList/BidFee
items and you want to call the chargeField
template n times with the parameter fieldIndex
set to 2, 3, ..., n+1. This can be achieved with the following XSLT fragment:
<xsl:for-each select="BidFeeList/BidFee">
<xsl:call-template name="chargeField">
<xsl:with-param name="fieldIndex" select="position() + 1"/>
</xsl:call-template>
</xsl:for-each>
Explanation: The XPath function position()
returns the context position which in XSLT terminology is the one-based index of the current node in the current node list. In an xsl:for-each
the current node list is set to the list of processed nodes and the current node is set to the currently processed node. Thus, position()
itself yields 1, 2, ..., n. The + 1
takes care of counting from 2 to n+1 instead.
Upvotes: 1