xsl-list
[Top] [All Lists]

RE: [xsl] Multiple Grouping & Muenchian Method

2006-07-21 12:17:44
Is it possible to have a group within a group. 

Hi, Steve,

You were really close in your code.  The concept that you were missing is to
define one xsl:key with two parameters using the concat function.

If you change your key declaration to be
<xsl:key name="byDateAndCountry" match="entry"
use="concat(parent::group/parent::date/text(), country)" />
or more succinctly:
<xsl:key name="byDateAndCountry" match="entry" use="concat(../../text(),
country)" />

You can then call one key indexed by an entry's date as well as country.

A full stylesheet is below.  Please let us know if you have any other questions.
This all becomes a lot easier in 2.0 with xsl:for-each-group.  Hopefully someone
will post the 2.0 solution so we can see how much simpler it is.

-Peter

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"
encoding="UTF-8"/>

<xsl:key name="byDateAndCountry" match="entry" use="concat(../../text(),
country)" />

<xsl:template match="/">
        <table border="1">
                <xsl:apply-templates select="report/table/date"/>
        </table>
</xsl:template>

<xsl:template match="date">
        <tr>
                <td>
                        <xsl:value-of select="normalize-space(text())" />
                </td>
        </tr>
        
        <xsl:for-each select="group/entry[generate-id() =
generate-id(key('byDateAndCountry', concat(../../text(), country))[1])]">
                <tr>
                        <td>
                                <xsl:value-of select="country" />
                        </td>
                </tr>
                <tr>
                        <td>Group</td>
                        <td>Name</td>
                        <td>ID</td>
                </tr>
                <xsl:apply-templates select="key('byDateAndCountry',
concat(../../text(), country))" />
        </xsl:for-each>
</xsl:template>

<xsl:template match="entry">
        <tr>
                <td>
                        <xsl:value-of select="../@type" />
                </td>
                <td>
                        <xsl:value-of select="name" />
                </td>
                <td>
                        <xsl:value-of select="id" />
                </td>
        </tr>
</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>
--~--

<Prev in Thread] Current Thread [Next in Thread>