Subject: RE: [xsl] Display children of node with given id!! From: <Jarno.Elovirta@xxxxxxxxx> Date: Tue, 15 Feb 2005 13:19:38 +0200 |
Hi, > I have had it. I don't have a clue. > I want to display all the children of node with id (ie: 7) > should be: 8,9. > > COMPLETE XML STRUCTURE: > > <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> > </tree_node> > <tree_node id="11" value="Test 2"/> > </tree> > > > COMPLETE XSL STRUCTURE: > > <?xml version="1.0"?> > <xsl:stylesheet version="1.1" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:param name="css"/> > <xsl:param name="url"/> > <xsl:param name="id"/> > <xsl:output method="html" indent="yes"/> > > <xsl:template match="/"> > <table cellspacing="0" cellpadding="2" class="{$css}"> > <tr> > <td class="ui_tree_bar"> > <a href="{$url}&action=add">add</a> > </td> > </tr> > <xsl:apply-templates/> > </table> > </xsl:template> > > <xsl:template match="tree_node[parent::tree or > child::tree_node[@id=$id]]"> Variables cannot be used in patterns in XSLT 1.0. (In XSLT 2.0 they can be used.) Now you "select all and match only those elements that qualify" (and let the rest be handled by build-in templates). How about changing the approach to "select the qualifying elements only". <xsl:template match="/"> <table cellspacing="0" cellpadding="2" class="{$css}"> <tr> <td class="ui_tree_bar"> <a href="{$url}&action=add">add</a> </td> </tr> <xsl:apply-templates select="tree/descendant::tree_node[@id = $id]/tree_node"/> </table> </xsl:template> <xsl:template match="tree_node"> <tr> <td> <table width="100%"> <tr> <td align="right" width="{count(ancestor-or-self::*) * 10}"> <a href="{$url}&node={@id}">+</a> </td> <td> <xsl:value-of select="@value"/> </td> <td width="25%"> <a href="{$url}&action=edit&node={@id}">edit</a> <a href="{$url}&action=delete&node={@id}">delete</a> </td> </tr> </table> </td> </tr> </xsl:template> Cheers, Jarno - Billy Bunter: Promo Mix
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Display children of node , David Carlisle | Thread | [xsl] Bug in Schema for XSLT 2.0?, Peter Gerstbach |
Re: [xsl] Display children of node , David Carlisle | Date | RE: [xsl] Bug in Schema for XSLT 2., Michael Kay |
Month |