xsl-list
[Top] [All Lists]

Re: [xsl] Trouble grouping with for-each-group and sort

2010-03-17 13:24:24
At 2010-03-17 13:58 -0400, mlcook(_at_)Wabtec(_dot_)com wrote:
I have a collection of data that I'm trying to sort, but am having
difficulty with the for-each-group and sort operations.
...
<xsl:for-each-group select="current-group()" group-by="myns:E">
  <xsl:sort select="current-grouping-key()" data-type="number"/>
  <xsl:sort select="myns:G/myns:sub3/myns:inner" data-type="number"/>
  <xsl:call-template name="process-data" >
    <xsl:with-param name="data-set" select="current-group()"/>
  </xsl:call-template>
</xsl:for-each-group>
...
All the other data is grouped and sorted fine, except for the last
sort on "inner".

Right.

Any ideas why the last sort doesn't appear to work?

You are missing that your second sort above is sorting the first member of each group, it isn't sorting the group as a whole. You have coded the above as if the <xsl:sort> is rearranging the group in advance of the called template, and that is not the case.

A group is processed in sorted order ... a group is never sorted as is and then used. In the above I get the impression that you are trying to pass the data-set parameter *in sorted order*, and that isn't the way XSLT works. The group is as it is, the processing of the groups is ordered by your two sort instructions but the group contents themselves are not sorted.

In your process-data template you will have to process them in sorted order ... you cannot pass the set of nodes in sorted order.

Sets of nodes in XSLT are in document order. When you want the information ordered, you process them in sorted order.

Does a data-type of "number" for sorting correctly process numbers
with decimal points?

Absolutely.

Am I using the wrong select on the parameter for process-data?

Yes, but there is no select that will pass the set of nodes in sorted order. Sets of nodes are in always in document order. Sets of nodes can be processed in sorted order when you wish.

Is current-group() at that point not the sorted data that I think it
should be?

Correct. I should have read ahead. Your sort instructions are only impacting the processing of the groups, not the members of the group. The members are in document order.

Is there a limit on nested for-each-group operations?

Not at all.

I hope this helps.

. . . . . . . . . . . Ken

--
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>