xsl-list
[Top] [All Lists]

[xsl] current() and position()?

2019-12-01 19:05:17
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/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>