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

RE: current-group()[1] within xsl:for-each-group

Subject: RE: current-group()[1] within xsl:for-each-group
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 2 Mar 2005 20:45:18 -0000
current group position
The nodes within each group should be in "population order", that is, the
order of the original sequence, which in this case is document order.

I notice that you are doing something a little unusual, you are sorting the
groups using something other than the grouping key. The sort key (for
sorting the groups) mb3e:prim_sort_key is evaluated against the first item
in each group - if its value differs from one member of the group to another
this could be quite confusing.

The xsl:sort within the apply-templates should affect the order in which the
items within each group are processed, but it doesn't affect the result of
current-group() - at least, it shouldn't!

Michael Kay
http://www.saxonica.com/ 

> 
> Now if the unintended output had come from applying the matching
> template to the group's first node (in terms of document 
> order), I would
> have immediately realized that.  But for some reason the nodes in the
> group are not in document order.  Why is that?

As I say, I think they should be in document order as far as current-group()
is concerned; but not processed in document order, because of the xsl:sort
within apply-templates.
> 
> Here is a more concrete question: Would it make a difference
> semantically or performance-wise if I changed this
> 
>       <xsl:for-each-group select="mb3e:document" 
> group-by="mb3e:fam_id">
> to this
>       <xsl:for-each-group select="mb3e:document" 
> group-by="text(mb3e:fam_id)">

There's no text() function - you probably meant string() or data() - but
either way, you're only doing explicitly what the system is doing anyway.
> 
> or is that effectively what is done when the each node's grouping key
> sequence is atomized and the resulting values compared?
> 
> > >   <xsl:variable name="structured-number"
> > >                 select="if (position() = 1)
> > >                         then $family-structured-number
> > >                         else esd:structured-number(.)"/>
> > 
> > Where is this variable declared, and where is it used? The 
> reference to
> > position() makes it highly context-sensitive. 
> 
> As I tried to express, it is declared within the xsl:template that is
> applied above (within xsl:for-each-group).  position() seems 
> to work as
> I assumed, returning the matched node's position within the group.

OK, I understand now. It should return the position in the actual order of
processing, that is, the sorted order.
> 
> But again I wonder: Would it make a difference if I changed . (dot) to
> current():
> 
>   <xsl:variable name="structured-number"
>                 select="if (position() = 1)
>                         then $family-structured-number
>                         else esd:structured-number(current())"/>
> 

No, in this context . and current() are synonyms.

Michael Kay
http://www.saxonica.com/

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.