inside the for-each loop in xsl, it works fine for an upstream counter. Is...">

Xsl decrease counter

If i use

<xsl:value-of select="position()" /> 

inside the for-each loop in xsl, it works fine for an upstream counter. Is there a way to change it to a down counter?

thanks

+4
source share
2 answers

How simple ...

 <xsl:value-of select="last()-position()+1" /> 

As fn: last returns the size of the context and fn: position is the position of the current processed element, you just need to subtract 1 from their difference (since position starts counting from 1, not 0).

+5
source

You may not need a downstream counter at all (I think this counter is used to index node-set to process it in reverse order) - just use:

 <xsl:for-each select="yourNodeSet"> <xsl:sort select="position()" order="descending" data-type="number"/> <!-- Your processing here --> </xsl:for-each> 
+2
source

Source: https://habr.com/ru/post/1445573/


All Articles