[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

second level grouping in XSLT 1.0

Subject: second level grouping in XSLT 1.0
From: "Susan Campbell" <SCampbell@xxxxxxxxxxxxxx>
Date: Fri, 6 Aug 2004 12:56:51 -0400
second level grouping xslt
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.