Re: [xsl] Multiple Grouping & Muenchian Method

Subject: Re: [xsl] Multiple Grouping & Muenchian Method
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 22 Jul 2006 15:02:47 +0530
Here is a XSLT 2.0 solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:output method="html" indent="yes"/>
	
  <xsl:template match="/report">
      <html>
          <head>
             <title/>
          </head>
          <body>
               <table border="1">
                  <xsl:for-each-group select="//entry" group-by="date">
                     <tr>
	         <td><xsl:value-of select="date" /></td>
	      </tr>
	      <xsl:for-each-group select="current-group()" group-by="country">
	         <tr>
	            <td><xsl:value-of select="country" /></td>
           	         </tr>
           	         <tr>
	            <td>Group</td>
	            <td>Name</td>
	            <td>id</td>
	         </tr>
	         <xsl:for-each select="current-group()">
   	            <tr>
	              <td><xsl:value-of select="../@type" /></td>
	              <td><xsl:value-of select="name" /></td>
	              <td><xsl:value-of select="id" /></td>
	            </tr>
	         </xsl:for-each>
	      </xsl:for-each-group>
                 </xsl:for-each-group>
               </table>
            </body>
      </html>
  </xsl:template>
	
</xsl:stylesheet>

Regards,
Mukul

On 7/21/06, Steve Sze <steveyksze@xxxxxxxxx> wrote:
Hi All

Is it possible to have a group within a group.  I did look at
http://www.biglist.com/lists/xsl-list/archives/200101/msg00070.html
but I either get a date with data from both dates or the same date for
each data set.

Thank You
Steve


Desire Sample Output -------------------- 07-13-2006 USA Group Name id AAA Adel 12345 AAA Barry 12346 AAA Carl 12347 BBB Dave 12345 BBB Ethel 12346 BBB Fred 12347

EUR
Group    Name         id
CCC      George       24567
CCC      Harold        23458
CCC      Jennifer      23459

07-14-2006
USA
Group     Name        id
BBB       Dave          12345
BBB       Ethel          12346
BBB       Fred           12347

EUR
Group    Name         id
CCC      George       24567
CCC      Harold        23458
CCC      Jennifer      23459



=====================================

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="html" indent="yes" />

 <xsl:key name="by-date" match="entry" use="date" />
 <xsl:key name="by-country" match="entry" use="country" />

 <xsl:template match="/report">
 <html>
 <head>
   <title/>
 </head>
 <body>
   <table border="1">
     <xsl:variable name="break_by_date"
select="//entry[key('by-date', date)]"/>
     <xsl:variable name="break_by_country" select="key('by-country',
currency)"/>
     <xsl:for-each select="$break_by_date[generate-id() =
generate-id(key('by-country', country)[1])]">
       <tr>
         <td><xsl:value-of select="date"/></td>
       </tr>
       <tr>
         <td><xsl:value-of select="country" /></td>
       </tr>
       <tr>
         <td>Group</td>
         <td>Name</td>
         <td>id</td>
       </tr>
       <xsl:for-each select="key('by-country', country)">
         <tr>
           <td><xsl:value-of select="../@type" /></td>
           <td><xsl:value-of select="name" /></td>
           <td><xsl:value-of select="id" /></td>
         </tr>
       </xsl:for-each>
     </xsl:for-each>
   </table>
 </body>
 </html>
 </xsl:template>

</xsl:stylesheet>

Sample XML file
<report>
     <table>
             <date>07-13-2006
                     <group type="AAA">111111
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Adel</name>
                                     <country>USA</country>
                                     <id>12345</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Barry</name>
                                     <country>USA</country>
                                     <id>12346</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Carl</name>
                                     <country>USA</country>
                                     <id>12347</id>
                             </entry>
                     </group>
                     <group type="BBB">111111
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Dave</name>
                                     <country>USA</country>
                                     <id>12345</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Ethel</name>
                                     <country>USA</country>
                                     <id>12346</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Fred</name>
                                     <country>USA</country>
                                     <id>12347</id>
                             </entry>
                     </group>
                     <group type="CCC">111111
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>George</name>
                                     <country>EUR</country>
                                     <id>24567</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Harold</name>
                                     <country>EUR</country>
                                     <id>23458</id>
                             </entry>
                             <entry>
                                     <date>07-13-2006</date>
                                     <name>Jennifer</name>
                                     <country>EUR</country>
                                     <id>23459</id>
                             </entry>
                     </group>
             </date>
             <date>07-14-2006
                     <group type="BBB">111111
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>Dave</name>
                                     <country>USA</country>
                                     <id>12345</id>
                             </entry>
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>Ethel</name>
                                     <country>USA</country>
                                     <id>12346</id>
                             </entry>
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>Fred</name>
                                     <country>USA</country>
                                     <id>12347</id>
                             </entry>
                     </group>
                     <group type="CCC">111111
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>George</name>
                                     <country>EUR</country>
                                     <id>24567</id>
                             </entry>
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>Harold</name>
                                     <country>EUR</country>
                                     <id>23458</id>
                             </entry>
                             <entry>
                                     <date>07-14-2006</date>
                                     <name>Jennifer</name>
                                     <country>EUR</country>
                                     <id>23459</id>
                             </entry>
                     </group>
             </date>
     </table>
</report>

Current Thread