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

Subject: [xsl] RE: Trouble grouping with for-each-group and sort
From: <mlcook@xxxxxxxxxx>
Date: Thu, 18 Mar 2010 15:35:51 -0400
Super!  Thanks to Michael Kay and Ken Holman for more instruction on
processing groups.

I used Mr. Kay's suggestion about defining a variable using
perform-sort.  I then passed the variable to process-data, and things
almost worked as advertised.  I needed to use
	as="item() *"
with an asterisk in the variable definition, since the groups contain
several elements.

I was unaware of perform-sort, and was wondering how I was going to sort
the data.  I was only aware of sort being applicable to apply-templates
and for-each constructs.

Thanks for the concise, concrete, and very useful solution.  I was able
to process my data as I expected.

Thanks for taking the time in this forum to help others.

-- Mike Cook

P.S. Not only with this nested for-each-group processing, but for XSL
processing as a whole, it boggles my mind at what must happen behind the
scenes with Saxon or other processors.  All the bookkeeping, let alone
the myriad of constructs and expressions that could be used!  I've had
some experience spent on compiler code generation, I'm sure glad Mr. Kay
has put in the tremendous effort at supplying a worthy tool.

> Date: Wed, 17 Mar 2010 18:11:14 -0000
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> From: "Michael Kay" <mike@xxxxxxxxxxxx>
> Subject: RE: [xsl] Trouble grouping with for-each-group and sort
> Message-ID: <BF158FD61904461FB25DBECFA951D8D6@Sealion>
> I can't immediately see the answer, but I can see the problem:
> <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"/>
> The second sort key is only used when two things have the
> same primary sort
> key. But by definition each group has a different
> current-grouping-key, so
> this will never happen (remember at this level you are
> sorting the groups,
> not the content of a particular group).
> I suspect that you want to use the second sort key to sort
> the contents of
> current-group().
> >
> >                         <xsl:call-template name="process-data" >
> >                             <xsl:with-param name="data-set"
> > select="current-group()"/>
> >                         </xsl:call-template>
> >
> You could do that within the process-data template, or you could do
> <xsl:variable name="temp" as="item()">
>   <xsl:perform-sort select="current-group()">
>     <xsl:sort select="myns:G/myns:sub3/myns:inner"
> data-type="number"/>
> and then pass the variable to the template.
> Regards,
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay

This email and any attachments are only for use by the intended recipient(s)
and may contain legally privileged, confidential, proprietary or otherwise
private information.  Any unauthorized use, reproduction, dissemination,
distribution or other disclosure of the contents of this e-mail or its
attachments is strictly prohibited.  If you have received this email in error,
please notify the sender immediately and delete the original.

Current Thread