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

Problem with grouping multi level nodes

Subject: Problem with grouping multi level nodes
From: "Nguyen, Mike (Contractor)" <Mike.Nguyen@xxxxxxxxxxxxx>
Date: Tue, 16 Mar 2004 16:17:57 -0500
student grouping
Hi,

I have the following problem with grouping and wonder if anyone can tell me
what I am doing wrong: 

Sample xml:

<students>
   <student>
      <name>Student 1</name>    
      <classes>            
         <class>            
            <title>soccer</title>        
            <category>sport</category>                   
         </class>            
         <class>            
            <title>football</title>        
            <category>sport</category>                   
         </class>            
      </classes>            
   </student>
   <student>
      <name>Student 2</name>    
      <classes>            
         <class>            
            <title>soccer</title>        
            <category>sport</category>                   
         </class>            
      </classes>            
   </student>
</students>


Expected output:

Student group by title

soccer
   Student 1   
   Student 2

football
   Student 1

Student group by category

sport
   Student 1
   Student 2

Student group by title and category

soccer - sport
   Student 1
   Student 2

football - sport
   Student 1


Current xsl:

<xsl:key name="titles" match="class" use="title"/>
<xsl:key name="categories" match="class" use="category"/> <xsl:key
name="titles-categories" match="class" use="concat(title,'-',category)"/>

<xsl:template match="/">
   <xsl:apply-templates/>
</xsl:template">

<xsl:template match="/students">

   <p>Student group by Title</p>
   <xsl:for-each select="/title[not(. = preceding::title)]">
      <p><xsl:value-of select="."/></p>

      <xsl:for-each select="key('titles',.)">
         <p><xsl:value-of select="../../name"/></p>
      </xsl:for-each>

   </xsl:for-each>

   <p>Student group by Category</p>
   <xsl:for-each select="/category[not(. = preceding::category)]">
      <p><xsl:value-of select="."/></p>

      <xsl:for-each select="key('categories',.)">
         <p><xsl:value-of select="../../name"/></p>
      </xsl:for-each>

   </xsl:for-each>

   <p>Student group by Title-Category</p>
   <xsl:for-each select="/class[count(. | key('titles-categories',
concat(title,'-',category))[1]) =1]">
      <p><xsl:value-of select="title"/> - <xsl:value-of
select="category"/></p>

      <xsl:for-each select="key('titles-categories',
concat(title,'-',category))">
         <p><xsl:value-of select="../../name"/></p>
      </xsl:for-each>

   </xsl:for-each>

</xsl:template">   


Output using the above xsl:


Student group by title

soccer
   Student 1   
   Student 2

football
   Student 1

Student group by category

sport
   Student 1
   Student 1
   Student 2

Student group by title and category

soccer - sport
   Student 1
   Student 2

football - sport
   Student 1


As you can see from the output above, I got a duplicate Student 1 in sport
category.  I am not sure how to eliminate this duplicate row.  Sorry for the
long email and thanks in advance for any helps.  


Mike

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.