Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an incremental count variable in XSLT / XPath when using Xpath for..in..return?

I am using the XPath for loop equivalent -

<xsl:for-each select="for $i in 1 to $length return $i">...

And I really need a count variable, how would I achieve this?

Thanks,

Ash.

like image 332
Ash Avatar asked Nov 29 '22 12:11

Ash


2 Answers

Inside of the

<xsl:for-each select="for $i in 1 to $length return $i">...</xsl:for-each>

the context item is the integer value so you simply need to access . or current().

like image 22
Martin Honnen Avatar answered Dec 09 '22 17:12

Martin Honnen


First note that

for $i in 1 to $length return $i

is just a long-winded way of writing

1 to $length

Within the for-each, you can access the current integer value as "." or as position().

like image 134
Michael Kay Avatar answered Dec 09 '22 17:12

Michael Kay