[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: About position() in xsl:for-each-group

Subject: RE: About position() in xsl:for-each-group
From: Christian Rinderknecht <rinderkn@xxxxxxxxxxxx>
Date: Mon, 11 Feb 2008 00:35:19 +0900
RE:  About position() in xsl:for-each-group
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()/>

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()/>

which prints the position of the first item in each group, i.e., 1.


<xsl:value-of select="@country"/>


<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 Rinderknecht +82 2 450-4058 Assistant Professor http://konkuk.ac.kr/~rinderkn Konkuk University Seoul Gwanjin-gu Hwayang-dong 143-701 South Korea

Current Thread


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.
First Name
Last Name
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.