Re: [xsl] grouping and counting of elements

Subject: Re: [xsl] grouping and counting of elements
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sun, 22 Apr 2007 16:12:52 +0530
The OP wrote, "Each <Result> has the same list of sub-elements, some
might not have a text value". Which means, I am perhaps right in not
thinking of this improvement.

But definitely, your solution will make the program more resilient.

On 4/21/07, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
Heres another way which doesn't rely on all elements being present in
the first <Result>:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
       <Totals>
               <xsl:for-each-group
select="/All_Results/Result/*[normalize-space()]" group-by="name()">
                       <xsl:element name="{current-grouping-key()}">
                               <xsl:for-each-group select="current-group()" group-by=".">
                                       <Tag value="{current-grouping-key()}" count="{count(current-group())}"/>
                               </xsl:for-each-group>
                       </xsl:element>
               </xsl:for-each-group>
       </Totals>
</xsl:template>
</xsl:stylesheet>


--
Regards,
Mukul Gandhi

Current Thread