On 10 Feb 2008, Michael Kay wrote:
@country is a property of a node. position() is not a property of a
node, it
is a property of an iteration over a sequence. So it's reasonable that
they
should behave differently [in a xsl:for-each-group element].
[Sorry if I look like nit-picking, but I have a theoretical streak and
I do not use XSLT for making a living but as a pet project of mine. I
have a background in functional programming and compilers, and XSLT
looks like quite a challenge.]
Ah! There is indeed a difference between
<xsl:for-each-group select="cities/city" group-by="@country">
<xsl:value-of select="position()/>
</xsl:for-each-group>
which prints the positions of each group as determined by the document
order of the first item of each group, and
<xsl:for-each-group select="cities/city" group-by="@country">
<xsl:value-of select="./position()/>
</xsl:for-each-group>
which prints the position of the first item in each group, i.e., 1.
But
<xsl:value-of select="@country"/>
and
<xsl:value-of select="./@country"/>
return the same value.
Does this mean that, in general, an XPath expression "p" is NOT
equivalent to "./p"? (Philip Wadler (2001), in his paper entitled "A
formal semantics of patterns in XSLT" at
http://homepages.inf.ed.ac.uk/wadler/topics/xml.html#xsl-semantics
wrote, about his formalisation of a fragment of XPath 1.0 that `It
follows immediately that the patterns p/. and p and ./p are all
equivalent.')
Moreover, you say that "position()" (i.e., the context position) is not
a property of a node, but the XPath 2.0 standard says that "It changes
whenever the context item changes." The only related standard where I
found the word "iteration" is in 14.1 of the XSLT 2.0 Standard, about
the notion of "Current Group". In particular, it is not found in XPath
nor the Data Model, so I am not sure what you mean, since position()
can be used as
<xsl:value-of select="cities/city/position()"/>
where I do not see any iteration (in a loopish sense).
Also, the constructor sequence in the xsl:for-each-group element could
be evaluated in concurrent threads having a different context item,
that is, there is no sequentiality implied when evaluating the sequence
and the iteration you refer to seems to me more a concept related to
the serialisation of the output (the side effect of the evaluation).
(The verb "to change" above supposes a state, though. Mmmm...)
In other words, I was expecting either a kind of
"current-group-position()", if the context item is a "city" element, or
else ".[1]/@country", if the context item is a group.
Best regards,
Christian
----------------------------------------------------------------------
Christian Rinderknecht +82 2 450-4058
Assistant Professor http://konkuk.ac.kr/~rinderkn
Konkuk University Seoul Gwanjin-gu Hwayang-dong 143-701 South Korea