[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: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 Dec 2019 08:11:34 -0000
Re:  current() and position()?
Basically, if X is a sequence of N items, then X ! position() will return the
integer sequence 1 to N. Which means that if X is a singleton (which current()
always is) then X! position() will always be 1. This has nothing to do with
the peculiarities of the current() function.

Within any subexpression that's evaluated with a changed focus, such as X[Y]
or X!Y, the "outer" context position is not accessible within the "inner"
expression.

Michael Kay

> On 2 Dec 2019, at 01:05, David Birnbaum djbpitt@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Dear xsl-list,
>
> With apologies for what I suspect is a naive question, I am confused about
the context position in:
>
>         <xsl:variable name="letters" as="xs:string+" select="'a', 'b',
'c'"/>
>         <xsl:for-each select="$letters">
>             <xsl:message select="position(), current() ! position()"/>
>         </xsl:for-each>
>
> position() returns what I expect (1, then 2, then 3), but the value of
current() ! position() is always 1. In this test it doesn't matter because I
can just use position(), but the real use case requires me to refer the
position of the item selected by the <xsl:for-each> at a lower depth (inside a
predicate on a different sequence). I can save the value of position() to a
variable and use it at that lower depth, so as far as getting the job done
there isn't a problem, but getting the job done is less interesting than
understanding why my expectation was wrong.
>
> I thought that inside an <xsl:for-each> the function current() would refer
to the sequence item being processed at the moment (that is, within the parent
<xsl:for-each>), and its position would be the context position, that is, its
offset into the sequence over which <xsl:for-each> was ranging by means of its
@select attribute. I think what I'm seeing instead is that current() !
position() returns the position of the current item inside the one-item
sequence being processed at the moment, which is why the value is always 1.
Does this mean that the context position (within the sequence selected by the
@select attribute on <xsl:for-each>) of the item being processed is not
accessible once the processing is deep enough that position() by itself is not
longer suitable? If current() is still the current context *item*, where and
why does it lose contact with its original context *position*?
>
> Best,
>
> David
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

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.