[xsl] second level grouping in XSLT 1.0

Subject: [xsl] second level grouping in XSLT 1.0
From: "Susan Campbell" <SCampbell@xxxxxxxxxxxxxx>
Date: Fri, 6 Aug 2004 12:56:51 -0400
Greetings,
I am unable to get second level grouping to work.  I suspect I need to use the
second key I have defined, but I'm not sure how to use it.  I now get more
information than I want/need but I don't know how to limit it and when I do,
I'm not sure how to count it.  Any help will be greatly appreciated.
Thanks,
Susan

Here's what I want (in a table):
Jacksonville
Audio-Visual	2
Circulation	1
Miami
Circulation	1
Melbourne
Children's	1
Orlando
Reserves	1
Tampa
Circulation 	2
Reference	1

My xml looks like this:
<section-02>
<number>57189<number>
<library>TAMPA<library>
<collection>Circulation<collection>
<section-02>
<section-02>
<number>57199<number>
<library>TAMPA<library>
<collection>Circulation<collection>
<section-02>
<section-02>
<number>57179<number>
<library>TAMPA<library>
<collection>Reference<collection>
<section-02>
<section-02>
<number>57169<number>
<library>JACKSONVILLE<library>
<collection>Audio-Visual<collection>
<section-02>
<section-02>
<number>57159<number>
<library>JACKSONVILLE<library>
<collection>Circulation<collection>
<section-02>
<section-02>
<number>57159<number>
<library>JACKSONVILLE<library>
<collection>Audio-Visual<collection>
<section-02>
<section-02>
<number>57109<number>
<library>ORLANDO<library>
<collection>Reserves<collection>
<section-02>
<section-02>
<number>57239<number>
<library>MIAMI<library>
<collection>Circulation<collection>
<section-02>
<section-02>
<number>57000<number>
<library>MELBOURNE<library>
<collection>Children's<collection>
<section-02>

And the xslt I've been trying with looks like this (comment show where I know
I'm wrong):
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:include href="funcs.xsl"/>
<xsl:key name="kCampus" match="section-02" use="library"/>
<xsl:key name="kCollection" match="section-02" use="concat(library, ':',
collection)"/>

<xsl:template match="/">
    <xsl:call-template name="header"/>
    <xsl:call-template name="BuildGrid"/>
</xsl:template>

<xsl:template name="header">
    <xsl:call-template name="header-gen">
       <xsl:with-param name="title" select="'Number of loans by campus and
collection'"/>
    </xsl:call-template>
</xsl:template>


<xsl:template name="BuildGrid">
 <center>
  <table border='1'>
   <xsl:for-each select="//section-02[generate-id() =
generate-id(key('kCampus', library))]">
		<xsl:sort select="library" order="ascending"/>
			 <tr>
			 <td colspan='3' align='center'>
				 <xsl:value-of select="."/>
			 </td>
			 </tr>
			 <!-- not what I need, I need each collection only once
			 per campus when relevant and then a count for each collection -->
         <xsl:apply-templates
	select="//section-02[library = current()/library]"
	mode="collection">
	<xsl:sort select="collection" order="ascending"/>
				 </xsl:apply-templates>
	 </xsl:for-each>
  </table>
 </center>
</xsl:template>

<xsl:template  match="section-02" mode="collection">
	<tr>
	<td>
	<xsl:value-of select="collection"/>
	</td>
	<td>
	<!-- placeholder for count of nodes by collection/campus -->
	<xsl:value-of select="'loans'"/>
	</td>
	</tr>
	</xsl:template>
</xsl:stylesheet>

Current Thread