Re: [xsl] current() and position()?

Subject: Re: [xsl] current() and position()?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 Dec 2019 08:11:34 -0000
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"

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',
>         <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 <>
> EasyUnsubscribe <> (by
email <>)

Current Thread