[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Question about generating a full tree from a tree
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
|
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
|