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

Re: current() and position()?

Subject: Re: current() and position()?
From: "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 Dec 2019 16:53:39 -0000
Re:  current() and position()?
Dear David and XSL-List,

Mike points out this isn't about current(): it is a red herring. Nonetheless
it might help to keep in mind that while position() is an XPath expression,
current() is not. It is defined only by XSLT.

This is because its entire purpose is to refer from inside an XPath expression
- that is, from a processing context that has changed from the context at the
start of the path - back out to the calling context. XPath without XSLT has no
such context (by definition, it is provided), so it does not define this
function. Other languages embedding XPath offer other ways of dealing with
this issue. Mostly this is by providing for variable bindings to be made
outside the path, permitting us to reference back out to some context that
way. Or simply by not supporting relative XPaths from arbitrary locations, so
the calling context is always the document root.

Indeed, since we can bind variables in XSLT, as in XQuery, we don't (mostly)
need current() in XSLT either. Most always we could rewrite it (apologies for
smart keyboard making dumb syntax errors):

<xsl:variable name="letters" as="xs:string+" select="'a', 'b', 'c'"/>
<xsl:for-each select="$letters">
    <xsl:variable name="current" select="."/>
    <xsl:message select="position(), $current ! position()"/>
</xsl:for-each>

This might suggest why the expression "current() ! position()" behaves the way
it does. It is the same as "for $c in (.) return position()".

So position() is not different in XPath from XSLT. The difference is only
where the processing context is defined, which includes position along with a
context node (or item as here), context size (returned by last()) and variable
bindings in scope. Where the XPath is called, this context - it can be thought
of as a set of properties used to initialize the XPath evaluation - is defined
by the calling context in the XSLT. But deeper inside an XPath is a different
matter, since each step provides context(s) for the next one (changes focus).
The difference is not how position() works but whose position within which
sequence is being asked for.

Cheers, Wendell

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.