Subject: RE: [xsl] Transforming tabular information to hierarchical From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 13 Feb 2007 17:12:59 -0000 |
Write a stylesheet that has the same structure as a normal one: start with a template that processes the root node, and call apply-templates when you want to process its children. The only difference is that the children are not physical XML children, but logical children found by using a key. Define a key for nodes based on the ParentID property, and to find the logical children of a node, use key('parentKey', @ID). Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Simon Shutter [mailto:simon@xxxxxxxxxxx] > Sent: 13 February 2007 16:32 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Transforming tabular information to hierarchical > > If I have a tabular data set that defines parent-child > relationships, is it possible to transform this into a > hierarchical tree format using XSLT? > > eg source: > > ID ParentID Name col1 col2 col3 > 1 null One bla1 bla1 bla1 > 2 1 Two bla2 bla2 bla2 > 3 2 Three bla3 bla3 bla3 > 4 3 Four bla4 bla4 bla4 > 5 1 Five bla5 bla5 bla5 > 6 4 Six bla6 bla6 bla6 > 7 4 Seven bla7 bla7 bla7 > 8 7 Eight bla8 bla8 bla8 > 9 3 Nine bla9 bla9 bla9 > 10 9 Ten bla10 bla10 bla10 > > desired output: > > <?xml version="1.0" encoding="utf-8"?> > <ul id='root' xmlns:bla="http://www.blablabla.com/bla"> > <li id='1' bla:col1='bla1' bla:col2='bla1' bla:col3='bla1'> > One > <ul> > <li bla:col1='bla2' bla:col2='bla2' bla:col3='bla2'> > Two > <ul> > <li bla:col1='bla3' bla:col2='bla3' bla:col3='bla3' />Three > <ul> > <li id='4' bla:col1='bla4' bla:col2='bla4' > bla:col3='bla4' />Four > <ul> > <li id='6' bla:col1='bla6' bla:col2='bla6' > bla:col3='bla6'>Six</li> > <li id='7' bla:col1='bla7' bla:col2='bla7' > bla:col3='bla7'> > Seven > <ul> > <li id='8' bla:col1='bla8' bla:col2='bla8' > bla:col3='bla8'>Eight</li> > </ul> > </li> > </ul> > <li id='9' bla:col1='bla9' bla:col2='bla9' bla:col3='bla9'> > Nine > <ul> > <li id='10' bla:col1='bla10' bla:col2='bla10' > bla:col3='bla10'>Ten</li> > </ul> > </li> > </ul> > </ul> > </li> > <li id='5' bla:col1='bla5' bla:col2='bla5' > bla:col3='bla5'>Five</li> > </ul> > </li> > </ul> > > > Thanks, Simon
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Transforming tabular info, Simon Shutter | Thread | RE: [xsl] Transforming tabular info, Simon Shutter |
Re: [xsl] Transforming tabular info, Andrew Welch | Date | Re: [xsl] how to test previous node, Florent Georges |
Month |