[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Recursion Examples

Subject: Re: Recursion Examples
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Mon, 30 Apr 2001 22:05:43 -0700 (PDT)
recursion examples in c
>I need to be able to build a tree that represents the data

XML is basically a tree from the get go, so it is a little
unclear what 'tree' you want to build. I interpreted you problem
to basically ask how to build the containment hierarchy
of modules that included other modules based on the relationship
joining <id> to <parentid>. Also, I fleshed out your input XML 
to be three-deep and three-wide versus your original four-deep
and one-wide example. To show the module containment clearly, I 
pushed your <id> and <name> tags into attributes.

Regards,

Dan
-------------------------------------------
File: VersionModule20APril2001.out
<?xml version="1.0" encoding="utf-8"?>
<module id="0" name="foo">
   <module id="1" name="bar">
      <module id="4" name="saz"/>
      <module id="5" name="war"/>
      <module id="6" name="doo"/>
   </module>
   <module id="2" name="baz">
      <module id="7" name="daz"/>
      <module id="8" name="diz"/>
      <module id="9" name="wat"/>
   </module>
   <module id="3" name="bat">
      <module id="a" name="yat"/>
      <module id="b" name="yoo"/>
      <module id="c" name="sor"/>
   </module>
</module>

File: VersionModule20APril2001.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="VersionModule20APril2001.xsl"?>

<version>
 <module><id>0</id><name>foo</name><parentid>root</parentid></module>
 <module><id>1</id><name>bar</name><parentid>0</parentid></module>
 <module><id>2</id><name>baz</name><parentid>0</parentid></module>
 <module><id>3</id><name>bat</name><parentid>0</parentid></module>
 <module><id>4</id><name>saz</name><parentid>1</parentid></module>
 <module><id>5</id><name>war</name><parentid>1</parentid></module>
 <module><id>6</id><name>doo</name><parentid>1</parentid></module>
 <module><id>7</id><name>daz</name><parentid>2</parentid></module>
 <module><id>8</id><name>diz</name><parentid>2</parentid></module>
 <module><id>9</id><name>wat</name><parentid>2</parentid></module>
 <module><id>a</id><name>yat</name><parentid>3</parentid></module>
 <module><id>b</id><name>yoo</name><parentid>3</parentid></module>
 <module><id>c</id><name>sor</name><parentid>3</parentid></module>
</version>

File: VersionModule20APril2001.xsl 
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
 <xsl:output indent="yes"/>
 
 <xsl:template match="/">
  <xsl:apply-templates select="version"/>
 </xsl:template>
   
 <xsl:template match="version">
  <xsl:apply-templates select="module[parentid='root']">
   <xsl:with-param name="ParentId" select="'root'"/>
  </xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="module">
  <xsl:param name="ParentId"/>
  <xsl:variable name="Id" select="id"/>
  <xsl:copy>
   <xsl:attribute name="id"><xsl:value-of select="id"/></xsl:attribute>
   <xsl:attribute name="name"><xsl:value-of select="name"/></xsl:attribute>
   <xsl:apply-templates select="parent::*/module[parentid=$Id]">
    <xsl:with-param name="ParentId" select="parentid"/>
   </xsl:apply-templates>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.