Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Grouping Sub Elements with XSLT [Thread Next] Re: Grouping Sub Elements with XSLTTo: NULL Date: 10/14/2008 6:28:00 PM Nick Heppleston wrote: > Can you offer any advice on the best method using XSLT 1.0 > (unfortunately, I can't use 2.0 :-() > > I have tried looking into Muenchian Method to perform the grouping, > but I'm getting horribly lost - any advice is greatly appreciated. You need two keys then for Muenchian grouping, one to group by the Country name, the second to find the distinct CentreNo to avoid duplicates: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:key name="by-country" match="CentreNo" use="../../Country"/> <xsl:key name="unique-centre" match="CentreNo" use="concat(../../Country, '_', .)"/> <xsl:template match="/FlatFileSchema"> <Grouping> <xsl:apply-templates select="Line/Centres/CentreNo[generate-id() = generate-id(key('by-country', ../../Country)[1])]" mode="group"/> </Grouping> </xsl:template> <xsl:template match="CentreNo" mode="group"> <Country name="{../../Country}"> <xsl:apply-templates select="key('by-country', ../../Country)[generate-id() = generate-id(key('unique-centre', concat(../../Country, '_', .))[1])]"> <xsl:sort select="."/> </xsl:apply-templates> </Country> </xsl:template> <xsl:template match="CentreNo"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
