[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: building a hierarchical classification out of flat
I seem to be able to find all information that needs to be generated in output XML, in the *last document element*. Here is a XSLT 1.0 solution based on a recursive named template: <?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" indent="yes"/> <xsl:template match="/documents"> <!-- processing the last document element --> <xsl:apply-templates select="document[not(following-sibling::document)]" /> </xsl:template> <xsl:template match="document"> <xsl:call-template name="PrintNodes"> <xsl:with-param name="nodeset" select="*" /> </xsl:call-template> </xsl:template> <xsl:template name="PrintNodes"> <xsl:param name="nodeset" /> <xsl:if test="$nodeset[1]"> <node id="{$nodeset[1]}" name="{$nodeset[2]}"> <xsl:call-template name="PrintNodes"> <xsl:with-param name="nodeset" select="$nodeset[position() > 2]" /> </xsl:call-template> </node> </xsl:if> </xsl:template> </xsl:stylesheet> This when applied to the following XML: <?xml version="1.0" ?> <documents> <document> <tag1>3</tag1> <tag1a>Social Sciences</tag1a> </document> <document> <tag1>3</tag1> <tag1a>Social Sciences</tag1a> <tag2>32</tag2> <tag2a>Politics</tag2a> </document> <document> <tag1>3</tag1> <tag1a>Social Sciences</tag1a> <tag2>32</tag2> <tag2a>Politics</tag2a> <tag3>326</tag3> <tag3a>Slavery</tag3a> </document> </documents> Produces wanted output: <?xml version="1.0" encoding="UTF-8"?> <node id="3" name="Social Sciences"> <node id="32" name="Politics"> <node id="326" name="Slavery"/> </node> </node> I seem to have a different view of this problem, than David and Mike! Can you please confirm whether you need this kind of solution, or need what David and Mike have suggested? Regards, Mukul http://gandhimukul.tripod.com On 7/24/06, Georg Hohmann <georg.hohmann@xxxxxxxxx> wrote: Dear XSLT-Community,
|
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
|