[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Identity Transform Grouping Question
Hi Ethan,
Here's an updated version of the stylesheet I sent you in a previous thread (sep 29). It does Muenchian grouping on the cities, just like in the previous version but with country information added to the key, to make sure cities with the same name in different countries are grouped correctly. I suppose that's why you used msxml:node-set()? Then it groups the offices by their english name, and adds the location elements. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- keys for grouping --> <xsl:key name="cities" match="city" use="concat(ancestor::country/@name,'-',.)"/> <xsl:key name="offices" match="office" use="concat(ancestor::country/@name,'-',names/name[@lang='en'])"/> <!-- 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> <!-- reorganize 'country' elements --> <xsl:template match="country"> <country> <xsl:copy-of select="@*"/> <cities> <!-- group 'city' elements --> <xsl:apply-templates select="offices/office/cities/city [count(.|key('cities',concat(ancestor::country/@name,'-',.))[1])=1]"> <xsl:sort select="."/> </xsl:apply-templates> </cities> </country> </xsl:template> <!-- new 'city' elements --> <xsl:template match="city"> <city> <name><xsl:value-of select="."/></name> <offices> <!-- group 'office' elements by their english name --> <xsl:apply-templates select="ancestor::offices/office [count(.|key('offices',concat(ancestor::country/@name,'-',names/name[@lang='en']))[1])=1]"> <xsl:sort select="names/name[@lang='en']"/> </xsl:apply-templates> </offices> </city> </xsl:template> <!-- new office elements --> <xsl:template match="office"> <office> <xsl:apply-templates select="names"/> <!-- add locations for each office with this name --> <xsl:apply-templates select="key('offices', concat(ancestor::country/@name,'-',names/name[@lang='en']))" mode="location"/> </office> </xsl:template> <!-- new location elements --> <xsl:template match="office" mode="location"> <location> <xsl:copy-of select="@*"/><!-- this will copy @id from office to location --> <xsl:apply-templates select="address|phone"/> </location> </xsl:template> </xsl:stylesheet> If you still have problems with this, let me know. (I'm especially curious if there's any noticable performance loss as compared to your approach with node-set) Best, Anton ethan.kalfus@xxxxxxx wrote: <<Node trees don't contain markup, so don't have tags, and you can't have half a node, so you can never insert a closing tag anywhere, in particular you can't insert one at the location of this comment. The way to put a group of nodes as child elements of another node is to first create the wrapper node <foo> then inside that select all the elements that should go in the group </foo>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|