xsl-list
[Top] [All Lists]

Re: [xsl] grouping and counting of elements

2007-04-22 03:43:14
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(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> 
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

--~------------------------------------------------------------------
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>