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

RE: Recursion Examples

Subject: RE: Recursion Examples
From: "Jon Wynacht" <jwynacht@xxxxxxxxx>
Date: Tue, 1 May 2001 05:47:23 -0700
tree recursion example
All,

Good advice thus far. However. I want to be able to display the results as a
tree in html...for example:

root module
|--modulue1
|---module4
|---module5
|---module6
|--module2
|---module7
|---module8
|---module9

Or maybe I used nice icons in place of the words. Regardless, I need to
physically show with icons or text what Dan is showing in the xml structure.

Thoughts?

Jon

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Dan Diebolt
Sent: Monday, April 30, 2001 10:06 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Recursion Examples


>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



 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.