Subject: Re: [xsl] Identity Transform Grouping Question From: Anton Triest <anton@xxxxxxxx> Date: Fri, 15 Oct 2004 09:30:45 +0200 |
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>
<!-- 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>
Best, Anton
<<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>
Perhaps my comments are misleading. My intent _is_ to explicitly wrap each unique group of <location> nodes -- that is, <location> nodes belonging to a unique <office> node -- with a surrounding <office></office> node (I said "tags" because my result tree is saved as an new xml file as input to another process -- so I am conceptualizing what that resulting xml file will look like, markup and all). My comments include complete markup (opening and closing tags) for this wrapper node; it is commented out because I could not successfully generate the wrapper node for each unique group, but wanted to show where the wrapper node should exist within the result tree. <<actually I'm not sure _why_ you are using msxsl:node-set() >>
Some of the XSLT, including this technique, was provided to me by another person on another site in order to assist me with using the Muenchian method for grouping <office> nodes within unique <city> nodes. A somewhat general explanation of my goal is that I want to sort the source tree according to several sort levels, then perform an identity transform that would reverse the parent-child relationship between the <city> and <office> nodes, and, finally, group <office> nodes according to their English name (office/names/name[@lang='en']), with each <office> node having one or more new <location> nodes to wrap the location-specific information, thus eliminating duplicate office/names nodes with the same name child. (I hope this is somewhat helpful!)
As I said, the current XSLT works wonderfully (transforming a 3MB file in 2 seconds) until the point of detail where I need to eliminate the duplicate office/names nodes. My XSLT seems to fail based on the mistaken idea that the use of preceding-sibling works with sorted nodes, which I now know it does not. So, the question is...once I have a sorted node set, what technique can I use to group those nodes according to a specific node value? Specifically, how do I ensure that the result tree contains office/names nodes with a unique name child (determined by the 'lang' attribute value = 'en')?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identity Transform Groupi, Wendell Piez | Thread | [xsl] Identity Transform Grouping Q, ethan.kalfus |
RE: [xsl] problem with image path, Jarno.Elovirta | Date | RE: [xsl] xsl:variable and node lis, Jarno.Elovirta |
Month |