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

grouping by attribute

Subject: grouping by attribute
From: "Sargeant, Richard (GEIS)" <Richard.Sargeant@xxxxxxxxxxx>
Date: Mon, 23 Aug 1999 13:50:33 +0200
xsl group table by category
Can anyone suggest a better way to achieve the following... I need to group
the xml elements category and place each category in a separate table. For
example: my xml file is...

<test>
  <item category="aaa">1xxxxxxxaaa</item>
  <item category="bbb">2xxxxxxxbbb</item>
  <item category="zzz">3xxxxxxxzzz</item>
  <item category="bbb">4xxxxxxxbbb</item>
  <item category="yyy">5xxxxxxxyyy</item>
</test>

   Currently I use the following XSL which works but it requires I hardcode
each attribute. Is this where I should use a xsl:variable?

<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  xmlns="http://www.w3.org/TR/REC-html40" 
  result-ns="">
  <xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

  <xsl:template match="test">
  <xsl:sort select="item@category"/>
    <p/><table border="1">
    <xsl:apply-templates select="item[@category='aaa']"/>
    </table>
    <p/><table border="1">
    <xsl:apply-templates select="item[@category='bbb']"/>
    </table>
    <p/><table border="1">
    <xsl:apply-templates select="item[@category='yyy']"/>
    </table>
    <p/><table border="1">
    <xsl:apply-templates select="item[@category='zzz']"/>
    </table>
  </xsl:template>

  <xsl:template match="item[@category='aaa']">
    <tr><td><xsl:value-of select="."/></td></tr>
  </xsl:template>
  <xsl:template match="item[@category='bbb']">
    <tr><td><xsl:value-of select="."/></td></tr>
  </xsl:template>
  <xsl:template match="item[@category='yyy']">
    <tr><td><xsl:value-of select="."/></td></tr>
  </xsl:template>
  <xsl:template match="item[@category='zzz']">
    <tr><td><xsl:value-of select="."/></td></tr>
  </xsl:template>

  <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>


regards   Richard


 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.