Subject: Re: [xsl] Grouping and then more grouping From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 15 Aug 2011 18:08:49 -0500 |
I'm trying to group the identical groups by id together such that given ...
I'll get a result that merges the like groups together and copies items ...
I've written the following which groups the first level and played around with getting something that moves to lower group levels as I need however I'm not sure what to do to descend through each group joining them together by id.
t:\ftemp>type alex.xml <?xml version="1.0" encoding="UTF-8"?> <root> <group xml:id="MILHIS_Yes"> <name>Yes</name> <group xml:id="MILHIS_Vehicles"> <name>Vehicles</name> <group xml:id="MILHIS_Air"> <name>Air</name> <group xml:id="MILHIS_Aeroplane"> <name>Aeroplane</name> <item xml:id="MILHIS_Attack_Aircraft"> <name>Attack Aircraft</name> </item> </group> </group> </group> </group> <group xml:id="MILHIS_Yes"> <name>Yes</name> <group xml:id="MILHIS_Vehicles"> <name>Vehicles</name> <group xml:id="MILHIS_Air"> <name>Air</name> <group xml:id="MILHIS_Aeroplane"> <name>Aeroplane</name> <item xml:id="MILHIS_Bomber_Aircraft"> <name>Bomber Aircraft</name> </item> </group> </group> </group> </group> <group xml:id="MILHIS_Yes"> <name>Yes</name> <group xml:id="MILHIS_Vehicles"> <name>Vehicles</name> <group xml:id="MILHIS_Sea"> <name>Sea</name> <group xml:id="MILHIS_Ship"> <name>Ship</name> <item xml:id="MILHIS_Aircraft_Carrier"> <name>Aircraft Carrier</name> </item> </group> </group> </group> </group> </root> t:\ftemp>call xslt2 alex.xml alex.xsl <?xml version="1.0" encoding="UTF-8"?> <group xml:id="MILHIS_Yes"> <name>Yes</name> <group xml:id="MILHIS_Vehicles"> <name>Vehicles</name> <group xml:id="MILHIS_Air"> <name>Air</name> <group xml:id="MILHIS_Aeroplane"> <name>Aeroplane</name> <item xml:id="MILHIS_Attack_Aircraft"> <name>Attack Aircraft</name> </item> <item xml:id="MILHIS_Bomber_Aircraft"> <name>Bomber Aircraft</name> </item> </group> </group> <group xml:id="MILHIS_Sea"> <name>Sea</name> <group xml:id="MILHIS_Ship"> <name>Ship</name> <item xml:id="MILHIS_Aircraft_Carrier"> <name>Aircraft Carrier</name> </item> </group> </group> </group> </group> t:\ftemp>type alex.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/> <xsl:template match="root"> <xsl:call-template name="CopyGroup"> <xsl:with-param name="groups" select="group"/> </xsl:call-template> </xsl:template> <xsl:template name="CopyGroup"> <xsl:param name="groups"/> <xsl:for-each-group select="$groups" group-by="@xml:id"> <group> <!--copy the common information about this group--> <xsl:copy-of select="@xml:id, name, $groups/item"/> <!--process subgroups based on all children of group members--> <xsl:call-template name="CopyGroup"> <xsl:with-param name="groups" select="current-group()/group"/> </xsl:call-template> </group> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> t:\ftemp>rem Done!
-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping and then more groupi, Alex Muir | Thread | Re: [xsl] Grouping and then more gr, Alex Muir |
Re: [xsl] Grouping problem, G. Ken Holman | Date | Re: [xsl] Grouping and then more gr, Alex Muir |
Month |