RE: About position() in xsl:for-each-group
@country is a property of a node. position() is not a property of a node, it
[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.
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
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 "./@country", if the context item is a group.
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format