|
Subject: Re: [xsl] Sorting seems not to work completely From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Wed, 27 Jul 2011 20:24:25 +0100 |
On 27 July 2011 19:59, Mark <mark@xxxxxxxxxxxx> wrote:
> Hello Michael,
> I'm not sure I understood the '+' in <xsl:for-each
> select+"current-group()">
typo... :)
> I tried the below template. [1] gives me the <Stamp> elements grouped under
> <Date> but not sorted by value. [2] gives me the <Stamp> elements sorted by
> value but not grouped under <Date>. Clearly I am missing something as I am
> quite week in XPath. Where am I going wrong.
The code below does what you need. Directly within the for-each-each
group the context is the sequence of <Stamp> elements all with the
same year/month/day. The sort there sorts on that value. Then the
for-each inside there processes that seqeunce (that all have the same
year/month/day one at a time, sorted by the value. I've used a
different wrapper element for each group to help show what is going
on.
<xsl:template match="List">
<xsl:element name="List">
<xsl:for-each-group select="Item/Stamp"
group-by="Date/concat(@year, @month, @day)">
<xsl:sort select="current-grouping-key()" data-type="number"/>
<xsl:element name="Group{position()}">
<xsl:for-each select="current-group()">
<xsl:sort select="@value" order="descending"
data-type="number"></xsl:sort>
<xsl:copy-of select="." copy-namespaces="no"/>
</xsl:for-each>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:template>
--
Andrew Welch
http://andrewjwelch.com
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Sorting seems not to work, Mark | Thread | Re: [xsl] Sorting seems not to work, Mark |
| Re: [xsl] Sorting seems not to work, Murray McDonald | Date | Re: [xsl] Sorting seems not to work, Michael Kay |
| Month |