Variables in XSLT are actually constants. You can only apply different values to variables if you use recursion. To obtain what you want, you can simply print the position()
of the node replacing the if
test with a predicate in the loop:
<tripSequence>
<xsl:for-each select="BODY/DBOUT/TRIP/PLANCOMPONENTS/*[starts-with(name(),'NO')][TYPE = 'PICKUP' or TYPE = 'DELIVERY']">
<numberInSequence><xsl:number value="position()"/></numberInSequence>
</xsl:for-each>
</tripSequence>
This will count only the actual nodes that match the for-each
. If you use position()
with the if
test instead of the predicate, it will also record the positions of the elements that match the predicate and not the if
, and may not be sequential.
The count starts at 1. If you want to count from zero, you have to subtract 1.