[xsl] Display Tree Nodes Incrementally based on ID.

Subject: [xsl] Display Tree Nodes Incrementally based on ID.
From: "Adam J Knight" <adam@xxxxxxxxxxxxxxxxx>
Date: Mon, 14 Feb 2005 21:02:09 +1000
Hi all,

Still laboring over this style sheet. I have started reading up on axis'

XML STRUCTURE:
<?xml version="1.0"?>
<tree>
  <tree_node id="7" value="Test">
    <tree_node id="8" value="Test Sub"/>
    <tree_node id="9" value="Test Sub One">
      <tree_node id="10" value="Test Sub Two">
        <tree_node id="11" value="Test Sub Three"/>
             <tree_node id="12" value="Test Sub Four"/>
        </tree_node>
      </tree_node>
    </tree_node>
  </tree_node>
</tree>

I want to display children and ancestor node of tree branch incrementally.

1) If node with id=7 is selected, it childrens are displayed.
2) If node with 10 is selected, Nodes with id 10,9,8,7 are display. Node 
With id=12 is not.

The template below appears to go some way to achieving this, however it
displays all nodes at once.

Would appreciate any help achieving my desired result.    

<xsl:template match="tree_node">
      
  <xsl:if test="parent::tree or ancestor::tree_node[@id=$id]">
    <table width="100%">
      <tr>
	  <td align="right" width="{count(ancestor-or-self::*) * 10}">
          <a href="{$url}&amp;node={@id}">+</a>
        </td>
	  <td>
	    <xsl:value-of select="@value"/>
	  </td>
	</tr>
    </table> 
    <xsl:apply-templates/> 
  </xsl:if>
	  
  </xsl:template>

Cheers, 
Adam 

Current Thread