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

Grouping by key

Subject: Grouping by key
From: gopinath.emmidisetty@xxxxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 4 Nov 2004 15:08:32 +0000
xsl grouping
Hello,

I have XML document like below.  I am trying to present the data 
categorised by say for eg. town like as in expected output section.  I am 
not getting the expected output when using the xsl file as given below.  I 
am obviously missing something.  Can somebody correct me to get the above 
output.

Many thanks.

XML Docment:

<documents>
<account>
<accountnumber>0001></accountnumber>
<companyname>ABC Ltd</companyname>
<town>Ford</town>
<postcode>FD13QG</postcode>
</account>
<account>
<accountnumber>0002></accountnumber>
<companyname>XYZ Ltd</companyname>
<town>Ford</town>
<postcode>XY13QZ</postcode>
</account>
...
...
...
</documents>

Expected output: 

Ford
        0001    ABC Ltd FD13QG
        0002    XYZ Ltd         XY13QZ

 xsl file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:key name="categorise" match="account" use="town" />

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

  <xsl:template match="documents">
    <table>
      <xsl:apply-templates select="account[generate-id() = generate-id( 
key( 'categorise', town ) )]" mode="catcols" />
    </table>
  </xsl:template>
 
  <xsl:template match="account" mode="catcols">
    <tr>
      <td><xsl:value-of select="town" /></td>
      <xsl:apply-templates select="//account[generate-id() = generate-id( 
key( 'categorise', town ) )]" mode="catrows" />
    </tr>
  </xsl:template>

  <xsl:template match="account" mode="catrows">
    <tr>
      <td><xsl:value-of select="accountnumber" /></td>
      <td><xsl:value-of select="companyname" /></td>
      <td><xsl:value-of select="postcode" /></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.