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

Re: second level grouping in XSLT 1.0

Subject: Re: second level grouping in XSLT 1.0
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Sat, 7 Aug 2004 00:35:24 -0700 (PDT)
xslt 1.0 sort
Hi Susan,
  Please try this stylesheet. It uses the nodeset
extension function.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="html" indent="yes"/>
	
<xsl:key name="by-library" match="section-02"
use="library" />
<xsl:key name="by-collection" match="temp/section-02"
use="collection" />

<xsl:template match="/root">
   <html>
     <head>
       <title></title>
     </head>
     <body>
       <table border="1">
          <xsl:for-each
select="section-02[generate-id(.) =
generate-id(key('by-library', library)[1])]">	   
<xsl:sort select="library" />
	    <tr>
	      <td><xsl:value-of select="library" /></td>
	    </tr>
	    <xsl:variable name="rtf">
	       <temp>
	         <xsl:copy-of select="key('by-library',
library)" />
	       </temp>
	    </xsl:variable>  
	    <xsl:for-each
select="xalan:nodeset($rtf)/temp/section-02[generate-id(.)
= generate-id(key('by-collection', collection)[1])]">
	      <xsl:sort select="collection" />
	      <tr>
	        <td><xsl:value-of select="collection" /></td>
                <td><xsl:value-of
select="count(key('by-collection', collection))"
/></td>
	      </tr>
	    </xsl:for-each>
	  </xsl:for-each>
	</table>   
      </body>
    </html>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

--- Susan Campbell <SCampbell@xxxxxxxxxxxxxx> wrote:

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



		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

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.