Subject: Re: [xsl] Re-Organize and Sort Source Tree (Muenchian Method) From: Anton Triest <anton@xxxxxxxx> Date: Wed, 29 Sep 2004 21:53:56 +0200 |
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>
<!-- keys by city name --> <xsl:key name="cities" match="city" use="."/> <xsl:key name="offices" match="office" use="cities/city"/>
<!-- identity transform: copy all elements --> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<!-- sort divisions by @id --> <xsl:template match="divisions"> <divisions> <xsl:apply-templates select="division"> <xsl:sort select="@id"/> </xsl:apply-templates> </divisions> </xsl:template>
<!-- sort regions and countries by @name --> <xsl:template match="regions|countries"> <xsl:copy> <xsl:apply-templates select="region|country"> <xsl:sort select="@name"/> </xsl:apply-templates> </xsl:copy> </xsl:template>
<!-- new 'city' elements --> <xsl:template match="city"> <city> <name><xsl:value-of select="."/></name> <offices> <xsl:apply-templates select="key('offices',.)"> <xsl:sort select="name"/> </xsl:apply-templates> </offices> </city> </xsl:template>
<!-- new office elements --> <xsl:template match="office"> <office> <xsl:copy-of select="@*"/> <!-- copy all children except 'cities' --> <xsl:apply-templates select="*[local-name()!='cities']"/> </office> </xsl:template>
Cheers, Anton
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re-Organize and Sort Source T, ethan.kalfus | Thread | Re: [xsl] Re-Organize and Sort Sour, ethan.kalfus |
Re: [xsl] Re: [xslt transform & gro, Michael PG | Date | RE: [xsl] Output escaped characters, Michael Kay |
Month |