Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XSL TREE LIKE STRUCTURE >Thread Next - Re: XSL TREE LIKE STRUCTURE Re: XSL TREE LIKE STRUCTURETo: NULL Date: 2/8/2005 12:17:00 PM On Tue, 8 Feb 2005 03:29:02 -0800, AJ <AJ@d...> wrote:
> I have an xml file with a data structure like:
> <?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>
> The xsl stylesheet will need to output the node selected and all its
> ancestors.
Hi,
If I understood correctly, you'd like to have thsi output:
<tree>
<tree_node id="7" depth="0" parent="0" value="Test">
<tree_node id="9" depth="1" parent="7" value="Test Sub One"/>
</tree_node>
</tree>
if the node with id 9 was the 'selected node'.
That can be achieved with a stylesheet like this:
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="id" match="*" use="@id"/>
<xsl:param name="id" select="9"/>
<xsl:variable name="mynode" select="key('id',$id)"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()[descendant-or-self::*=$mynode]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
regards,
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
