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

counting and grouping issue

Subject: counting and grouping issue
From: "Charles Ohana" <charles.ohana@xxxxxxxxxxxxxx>
Date: Tue, 8 May 2007 14:19:19 -0400
 counting and grouping issue
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

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-2011 All Rights Reserved.