[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Context inside brackets

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.