Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Grouping Sub Elements with XSLT

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent