[xsl] counting and grouping issue

Subject: [xsl] counting and grouping issue
From: "Charles Ohana" <charles.ohana@xxxxxxxxxxxxxx>
Date: Tue, 8 May 2007 14:19:19 -0400
Hello,
I'm having an issue while counting and aggregating nodes that have similar subnodes value within the same category.
In other words I'm trying to do something like a group by (in sql)
I must be doing something wrong somewhere. Please see my xml, stylesheet and output to see what I'am trying to accomplish.


Thank you all 4 ur help.

OUTPUT
ONE : 4 : Gary Numan : Are Friends Electric
ONE : 4 : Gary Numan : We Are Glass
ONE : 4 : Gary Numan : I Die You Die
TWO : 4 : Gary Numan : Unknown
TWO : 1 : Bob MArley : Jammin

EXPECTED OUTPUT
ONE : 3 : Gary Numan : Are Friends Electric
ONE : 3 : Gary Numan : We Are Glass
ONE : 3 : Gary Numan : I Die You Die
TWO : 1 : Gary Numan : Unknown
TWO : 1 : Bob MArley : Jammin

XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ApplicationCatalogue>
  <Category name="category 1" description="ONE">
     <Product code="TT000002630">
        <Attributes>
           <title>Are Friends Electric</title>
           <author>Gary Numan</author>
        </Attributes>
     </Product>
     <Product code="TT000002631">
        <Attributes>
           <title>We Are Glass</title>
           <author>Gary Numan</author>
        </Attributes>
     </Product>
     <Product code="TT000002632">
        <Attributes>
           <title>I Die You Die</title>
           <author>Gary Numan</author>
        </Attributes>
     </Product>
  </Category>

  <Category name="category 2" description="TWO">
     <Product code="TT000002632">
        <Attributes>
           <title>Unknown</title>
           <author>Gary Numan</author>
        </Attributes>
     </Product>

     <Product code="TT000002669">
        <Attributes>
           <title>Jammin</title>
           <author>Bob Marley</author>
        </Attributes>
     </Product>
  </Category>
</ApplicationCatalogue>


XSL
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text" indent="no"/>
<xsl:key name="itemsByAuthor" match="Product" use="Attributes/author"/>
<xsl:template match="/ApplicationCatalogue">
<xsl:for-each select="Category">
<xsl:for-each select="Product/Attributes/author[not(.=preceding::Product/Attributes/author)]">
<xsl:variable name="cnt"><xsl:value-of select="count(key('itemsByAuthor', .))" /></xsl:variable>
<xsl:for-each select="key('itemsByAuthor', .)">
<xsl:value-of select="../@description" />
<xsl:text> : </xsl:text>
<xsl:value-of select="$cnt" />
<xsl:text> : </xsl:text>
<xsl:value-of select="Attributes/author" />
<xsl:text> : </xsl:text>
<xsl:value-of select="Attributes/title"/>
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:transform>


Current Thread