RE: [xsl] Fwd: XSLT 2.0 Determining Position of Sequence Item During "for expression" evaluation

Subject: RE: [xsl] Fwd: XSLT 2.0 Determining Position of Sequence Item During "for expression" evaluation
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 16 Mar 2007 21:10:57 -0000
> I have a simple xpath expression like this
> 
> for $x in (10 to 20) return $x
> 
> which simply return the sequence of integers between 10 and 20
> 
> Now, what if I wanted to return something like this instead 
> from the same sequence
> 
> 1 2 3 4 ... 11
> 
> I want to get access to the "position" of $x in the sequence, 
>  and also the total number of items in the sequence.
> 
> I tried something like this
> 
> for $x in (10 to 20) return $x/position()

XQuery has 

for $x at $p in (10 to 20) return $p

where $x will range from 10 to 20 while $p ranges from 1 to 11. But that's
not available in XPath. In XPath you have to resort to

for $p in 1 to 11 ...

But if you really want to use position(), you can go back to

<xsl:for-each select="10 to 20">
  ....


Michael Kay
http://www.saxonica.com/

Current Thread