[xsl] Expandeable Tree!

Subject: [xsl] Expandeable Tree!
From: "Adam J Knight" <adam@xxxxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 09:21:10 +1000
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_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"/>

I am seeking to create a similar control to the one seen here:

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.

Here is the beginning of my stylesheet.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.1"

    <xsl:param name="css"/>
    <xsl:param name="c_node"/>
    <xsl:param name="url"/>

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="tree">
        <table class="{$css}" align="center">
            <xsl:apply-templates />

    <xsl:template match="//tree_node">
            <td width="{(@depth + 1) * 20}" align="right">
                <a href="{$url}&amp;node={@id}">+</a>
                <xsl:value-of select="@value"/>
      <xsl:apply-templates select="*[descendant-or-self::*/@id=$c_node]"/>


I am only acquainted with xsl, so I would sure appreciate any suggestions on
how to do this. I cant get past displaying the level (depth) 0 nodes, even
when I click the appropriate link.


Current Thread