Subject: Re: [xsl] Question about generating a full tree from a tree with xrefs using xslt ? From: David Carlisle <davidc@xxxxxxxxx> Date: Wed, 10 Dec 2003 14:07:57 GMT |
I'll assume a wrapper element x so your input is well formed <x> <elem id="a1" type="w"> <text>aa</text> </elem> <elem id="a2" type="x"> <text>bb</text> <ref>a1</ref> </elem> <elem id="a3" type="y"> <text>cc</text> <ref>a2</ref> </elem> <elem id="a4" type="x"> <text>dd</text> <ref>a1</ref> </elem> </x> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:key name="ref" match="elem" use="ref"/> <xsl:template match="x"> <xsl:apply-templates select="elem[@type='w']"/> </xsl:template> <xsl:template match="elem[@type='w']"> process node <xsl:value-of select="@id"/> with text <xsl:value-of select="text"/> <xsl:apply-templates select="key('ref',@id)[@type='x']"/> </xsl:template> <xsl:template match="elem[@type='x']"> process node <xsl:value-of select="@id"/> with text <xsl:value-of select="text"/> <xsl:apply-templates select="key('ref',@id)[@type='y']"/> </xsl:template> <xsl:template match="elem[@type='y']"> process node <xsl:value-of select="@id"/> with text <xsl:value-of select="text"/> <xsl:apply-templates select="key('ref',@id)[@type='z']"/> </xsl:template> <xsl:template match="elem[@type='z']"> none of these should be there </xsl:template> </xsl:stylesheet> $ saxon tree.xml tree.xsl process node a1 with text aa process node a2 with text bb process node a3 with text cc process node a4 with text dd Note the above stylesheet is enforcing that it only looks for elements of a specified type at each level. If you know that only type y eleemnts are going to refer to type x elements then you could compress all these templates down to just one. David -- http://www.dcarlisle.demon.co.uk/matthew ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Question about generating a f, Peter Biechele | Thread | Re: [xsl] Question about generating, Peter Biechele |
Re: [xsl] Removing Duplicates & For, JCS | Date | Re: [xsl] Removing Duplicates & For, David Carlisle |
Month |