xsl-list
[Top] [All Lists]

RE: Re: [xsl] XSLT 2.0 multi-level grouping challenge/problem

2007-05-24 09:20:48
Thanks, I knew a was wandering around in some tall grass. There had to be a 
simpler answer. Heretofore I had only used the for-each-group construct in 
fairly simple problems. I hadn't used the "current-group()" function before, 
and that proved to be the key in clearing things up.
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com>
Sent:     Thu, 24 May 2007 16:13:49 +0100
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  Re: [xsl] XSLT 2.0 multi-level grouping challenge/problem

On 5/24/07, cknell(_at_)onebox(_dot_)com <cknell(_at_)onebox(_dot_)com> wrote:
Consider this multi-level grouping problem for XSLT 2.0.

Here you go:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:template match="/">
        <table>
            <tr>
                <td>State</td>
                <td>City</td>
                <td>Organ</td>
                <td>Count</td>
            </tr>
            <xsl:for-each-group select="/donors/donor" group-by="state">
                <xsl:sort select="current-grouping-key()"/>
                <tr>
                    <td><xsl:value-of select="state"/></td>
                    <td/>
                    <td/>
                    <td/>
                </tr>
                <xsl:for-each-group select="current-group()" group-by="city">
                    <xsl:sort select="current-grouping-key()"/>
                    <tr>
                        <td/>
                        <td><xsl:value-of select="city"/></td>
                        <td/>
                        <td/>
                    </tr>
                    <xsl:for-each-group select="current-group()"
group-by="organ">
                        <xsl:sort select="current-grouping-key()"/>

                        <tr>
                            <td/>
                            <td/>
                            <td><xsl:value-of select="organ"/></td>
                            <td><xsl:value-of
select="count(current-group())"/></td>
                        </tr>
                    </xsl:for-each-group>
                </xsl:for-each-group>
            </xsl:for-each-group>
        </table>
    </xsl:template>

</xsl:stylesheet>

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




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