[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSL, SQL, and trees (again)
Hi Phill, Here is a XSLT 1.0 solution to convert, <directories> <item> <id>1</id> <name>About</name> <path>1</path> </item> <item> <id>2</id> <name>Services</name> <path>2</path> </item> <item> <id>3</id> <name>Environmental</name> <path>2.1</path> </item> <item> <id>4</id> <name>Landscaping</name> <path>2.2</path> </item> </directories> into, <directories> <directory name="About"/> <directory name="Services"> <directory name="Environmental"/> <directory name="Landscaping"/> </directory> </directories> <?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="/directories"> <directories> <xsl:for-each select="item[(string-length(path) - string-length(translate(path, '.', ''))) = 0]"> <directory name="{name}"> <xsl:call-template name="re-arrange"> <xsl:with-param name="nodeset" select="../item" /> <xsl:with-param name="curr-path" select="path" /> <xsl:with-param name="no-of-dots" select="1" /> </xsl:call-template> </directory> </xsl:for-each> </directories> </xsl:template> <xsl:template name="re-arrange"> <xsl:param name="nodeset" /> <xsl:param name="curr-path" /> <xsl:param name="no-of-dots" /> <xsl:for-each select="$nodeset[((string-length(path) - string-length(translate(path, '.', ''))) = $no-of-dots) and (starts-with(path, $curr-path))]"> <directory name="{name}"> <xsl:call-template name="re-arrange"> <xsl:with-param name="nodeset" select="$nodeset" /> <xsl:with-param name="curr-path" select="path" /> <xsl:with-param name="no-of-dots" select="$no-of-dots + 1" /> </xsl:call-template> </directory> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul http://gandhimukul.tripod.com On 7/27/06, Phillip B Oldham <phillip.oldham@xxxxxxxxxx> wrote: Hi all
|
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
|