[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: Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx>
Date: Sun, 10 Feb 2008 17:38:31 +0000
Re:  About position() in xsl:for-each-group
>>>>> "Christian" == Christian Rinderknecht <rinderkn@xxxxxxxxxxxx> writes:

    Christian> <xsl:for-each-group select="cities/city"
    Christian> group-by="@country"> <xsl:value-of select="position()/>
    Christian> </xsl:for-each-group>

    Christian> which prints the positions of each group as determined
    Christian> by the document order of the first item of each group,
    Christian> and

This returns the context position, which is defined as:

"the context position is the position of this item within the set of
initial items (that is, one item for each group in the population) in
population order, "

so effectively it is the position of the group within the sequence of
groups.


    Christian> <xsl:for-each-group select="cities/city"
    Christian> group-by="@country"> <xsl:value-of
    Christian> select="./position()/> </xsl:for-each-group>

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

The context item (.) is defined as "the context item is the initial item
of the group". This is a sequence of 1 item. So ./position() is giving
the context position within a sequence of 1 item, so it will always be 1.


    Christian> But

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

    Christian> and

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

    Christian> return the same value.

Yes. Because you are asking for the country attribute:

a) of the first item in each group, and
b) of each item in a sequence of one (the first item in the group)

    Christian> Does this mean that, in general, an XPath expression
    Christian> "p" is NOT equivalent to "./p"? (Philip Wadler (2001),

The / operator changes the context item, so yes.

    Christian> in his paper entitled "A formal semantics of patterns
    Christian> in XSLT" at
    Christian> http://homepages.inf.ed.ac.uk/wadler/topics/xml.html#xsl-semantics
    Christian> wrote, about his formalisation of a fragment of XPath
    Christian> 1.0 that `It follows immediately that the patterns
    Christian> p/. and p and ./p are all equivalent.')

Expressions are not patterns - the latter are syntactically a subset
of the former, but the semantics of pattern matching are not those of
expression evaluation.

    Christian> Moreover, you say that "position()" (i.e., the context
    Christian> position) is not a property of a node, but the XPath
    Christian> 2.0 standard says that "It changes whenever the context
    Christian> item changes." The only related standard where I found
    Christian> the word "iteration" is in 14.1 of the XSLT 2.0
    Christian> Standard, about the notion of "Current Group". In
    Christian> particular, it is not found in XPath nor the Data
    Christian> Model, so I am not sure what you mean, since position()
    Christian> can be used as

    Christian> <xsl:value-of select="cities/city/position()"/>

    Christian> where I do not see any iteration (in a loopish sense).

That is correct. of course, the implementation may well involve a
loop, but it does not have to.

    Christian> Also, the constructor sequence in the
    Christian> xsl:for-each-group element could be evaluated in
    Christian> concurrent threads having a different context item,

Or concurrent processes. Or for that matter a sequential evaluation in
a different order from that of the sequence, results being
subsequently re-ordered to preserve the semantics.

    Christian> that is, there is no sequentiality implied when
    Christian> evaluating the sequence

Correct. That is, there is a sequential ordering of results that must
be observed, but no temporal evaluation order.

    Christian> and the iteration you refer to
    Christian> seems to me more a concept related to the serialisation
    Christian> of the output (the side effect of the evaluation). (The

Serialization does not necessarily take place.

-- 
Colin Adams
Preston Lancashire

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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