XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ken TamSubject: transform from flat to hierarchical
Author: Ken Tam
Date: 26 Nov 2006 11:47 PM
Hi all,

I need to transform flat and somewhat unstructured XML to a more structual format. The following is a sample:

<logs>
<log>a</log>
<log>sub b</log>
<log>c</log>
<log>sub d</log>
<log>e</log>
<log>f</log>
<log>end of d</log>
<log>g</log>
<log>end of b</log>
<log>h</log>
<log>i</log>
<logs>

into a more structured content with nesting:

<logs>
<log name="a">
<log name="b">
<log name="c">
<log name="d">
<log name="e"/>
<log name="f"/>
</log>
</log>
<log name="g"/>
</log>
</log>
<log name="h"/>
<log name="i"/>
</logs>

Is this doable by using XSLT/XPATH?. If yes, please share some sample code.

Thanks,
kkt

Postnext
Tony LavinioSubject: transform from flat to hierarchical
Author: Tony Lavinio
Date: 27 Nov 2006 12:46 AM
Try typing "flat to hierarchical using xslt" into Google.
In the first 20 entries, you'll find several pointers.

Postnext
Ken TamSubject: transform from flat to hierarchical
Author: Ken Tam
Date: 27 Nov 2006 01:13 AM
I've done the same search but all the examples dealt with nestings that are determines by a single node (i.e. a row with an attribute "level") instead of begin-end node pair which is where I am stuck as I don't know how to group by two separate nodes.

Postnext
Ken TamSubject: transform from flat to hierarchical
Author: Ken Tam
Date: 27 Nov 2006 01:19 AM
Added spaces to show the nesting in the output.

From:

<logs>
<log>a</log>
<log>sub b</log>
<log>c</log>
<log>sub d</log>
<log>e</log>
<log>f</log>
<log>end of d</log>
<log>g</log>
<log>end of b</log>
<log>h</log>
<log>i</log>
<logs>

into a more structured content with nesting:

<logs>
<log name="a">
<log name="b">
<log name="c">
<log name="d">
<log name="e"/>
<log name="f"/>
</log>
</log>
<log name="g"/>
</log>
</log>
<log name="h"/>
<log name="i"/>
</logs>

Posttop
Tony LavinioSubject: transform from flat to hierarchical
Author: Tony Lavinio
Date: 27 Nov 2006 09:00 AM
This is a forum for supporting customers of Stylus Studio; from your
email I can't tell if you are one or not. General XSLT questions
should go to the xsl-list run by Mulberry Tech.

However...

You might find some useful information over at
http://www.jenitennison.com/xslt/index.xml
specifically under "Grouping" and "Constructing Hierarchies".

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.