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

Re: Expandeable Tree!

Subject: Re: Expandeable Tree!
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Thu, 10 Feb 2005 15:46:14 -0800
mysql parent
Adam J Knight wrote:
Hi all,

First time posting, so I hope I am doing ok.

I have a xml document that gets generated from a database (MySql).
<?xml version="1.0"?>
<tree>
  <tree_node id="7" depth="0" parent="0" value="Test">
    <tree_node id="8" depth="1" parent="7" value="Test Sub"/>
    <tree_node id="9" depth="1" parent="7" value="Test Sub One">
      <tree_node id="10" depth="2" parent="9" value="Test Sub Two"/>
    </tree_node>
  </tree_node>
</tree>


First, the depth and parent attributes are not necessary because you have that information in the XML hierarchy.


However all xsl processing is done server side (Using PHP 4 XSLT Processor).
Default view is all level (depth) 0 nodes displayed. A user clicks a html
link that sends the id of the node clicked to the xsl file as a parameter
and all children nodes are displayed. If depth is greater than one, all
ancestor nodes will need to be displayed also.

You could do something like:


<xsl:template match="/">
  <ul class="nav">
    <xsl:apply-templates/>
  </ul>
</xsl:template>

<xsl:template match="*">
  <xsl:choose>
    <xsl:when test="child::*">
      <li class="folder">
        <a href="my.php?id={@id}">
          <xsl:value-of select="@value"/>
        </a>
        <ul>
          <xsl:apply-templates/>
        </ul>
      </li>
    </xsl:when>
    <xsl:otherwise>
      <li class="page">
        <a href="my.php?id={@id}">
          <xsl:value-of select="@value"/>
        </a>
      </li>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

best,
-Rob

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.