[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Context inside brackets

Subject: Re: [xsl] Context inside brackets
From: "John Lumley john@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 May 2015 16:03:05 -0000

On 21/05/2015 11:46, Jorge . chocolate.camera@xxxxxxxxx wrote:
<xsl:variable name="POSITION" select="position()" as="xs:integer"/>
<xsl:sequence select="$FOO[$POSITION]"/>

but I somehow feel that there must be a way to call the `position()`
of the current node from inside those brackets

Interestingly my immediate reaction, "$FOO[current()/position()]" isn't right. current() does indeed give the XSLT context item, but as a sequence of item(), i.e. a singleton sequence, so it has a position of 1 within the scope of the /.

Thus the top-level XPath expression position() = current()/position(), within some XSLT iteration is not (usually) true.

Michael Kay states "in practice it's very rare to write an expression on the right-hand side of <</>> that depends upon the context position or size" on p 603 of the 4th Edition of his XSLT2.0 Programmer's Reference.

In years of working with XSLT I hadn't looked at this issue in any detail. When something didn't work as anticipate either I used the XSLT variable binding or in XSLT 3 use a local let, as Martin Honnen suggested. ;-)

*John Lumley* MA PhD CEng FIEE
john@xxxxxxxxxxxx <mailto:john@xxxxxxxxxxxx>
on behalf of Saxonica Ltd

Current Thread