Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - grouping by attribute. >Thread Next - Re: grouping by attribute. Re: grouping by attribute.To: NULL Date: 5/10/2007 3:04:00 PM
Gobinath wrote:
> How do I group xml nodes by their attributes.
Here is an example stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="App-By-Status" match="App" use="concat(generate-id(..),
'_', @Status)"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Root/*">
<xsl:copy>
<xsl:apply-templates select="App[generate-id() =
generate-id(key('App-By-Status', concat(generate-id(current()), '_',
@Status))[1])]" mode="group"/>
</xsl:copy>
</xsl:template>
<xsl:template match="App" mode="group">
<xsl:element name="{@Status}">
<xsl:apply-templates select="key('App-By-Status',
concat(generate-id(..), '_', @Status))"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
You can find more explanations about grouping in XSLT here:
<http://www.jenitennison.com/xslt/grouping/index.xml>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
