[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Creating Hierarchy

Subject: RE: Creating Hierarchy
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 12 Oct 2008 19:44:16 +0100
RE:  Creating Hierarchy
You'll find a description of an XSLT 2.0 stylesheet that does this (and some
other things besides) at

http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Rowan Sylvester-Bradley [mailto:rowan@xxxxxxxxxxxxxxxxxxxxx] 
> Sent: 12 October 2008 18:44
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Creating Hierarchy
> 
> Hi,
> 
> I have an XML file that represents a tree of data elements, 
> similar to a directory tree. The structure of the file has 
> every node in the tree represented by a <node> element, all 
> children of the root, with the hierarchy defined by a <level> 
> element within each node. So the <node> with <level> = 0 is 
> the root of the tree, its children have <level> = 1, their 
> children have <level> = 2 etc. Here's an example:
> 
> <mytree>
>   <node>
>     <name>Root of my tree</name>
>     <level>0</level>
>   </node>
>   <node>
>     <name>Child of root</name>
>     <level>1</level>
>   </node>
>   <node>
>     <name>Another child of root</name>
>     <level>1</level>
>   </node>
>   <node>
>     <name>Grandchild of root</name>
>     <level>2</level>
>   </node>
>   <node>
>     <name>Yet another child of root</name>
>     <level>1</level>
>   </node>
> </mytree>
> 
> I want to transform this into a hierarchical file like this:
> 
> <newnode>
>   <name>Root of my tree</name>
>   <newnode>
>     <name>Child of root</name>
>   </newnode>
>   <newnode>
>     <name>Another child of root</name>
>     <newnode>
>       <name>Grandchild of root</name>
>     </newnode>
>   </newnode>
>   <newnode>
>     <name>Yet another child of root</name>
>   </newnode>
> </newnode>
> 
> How do I write a stylesheet to do this?
> 
> Thanks - Rowan 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.