Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSL TREE LIKE STRUCTURE

From: "Joris Gillis" <roac@-------.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent