[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] converting flat xml data into heirarchy structure
Subject: RE: [xsl] converting flat xml data into heirarchy structure From: "Michael Kay" <mhk@xxxxxxxxx> Date: Mon, 9 Feb 2004 11:29:48 -0000 |
The general solution to this requirement is to use xsl:apply-templates to walk the tree recursively as you would normally do, but instead of selecting the physical children of a node, select the logical children, which you can do using ../scope[@parent-id = current()/@id] Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > David Buddrige > Sent: 09 February 2004 09:18 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] converting flat xml data into heirarchy structure > > > Hi all, > > I have a source document that is currently being > generated from an Oracle database - it is effectively > a table dump in xml format of the "scope" table.. It > has the following structure. > > <scopes> > <scope id="1" parent_id="0" details="some data"/> > <scope id="2" parent_id="1" details="more data"/> > <scope id="3" parent_id="1" details="info"/> > <scope id="4" parent_id="2" details="blah"/> > <scope id="5" parent_id="1" details="foo"/> > <scope id="6" parent_id="2" details="log"/> > <scope id="7" parent_id="4" details="ogg"/> > <scope id="8" parent_id="4" details="abcd"/> > <scope id="9" parent_id="2" details="xyz"/> > </scopes> > > What I want to do is to re-organise this data so that > the xml properly represents its structure. It forms a > tree using the parent_id to identify the parent scope > in a tree structure. > > What I want to wind up with from the above data is > this: > > > <scopes> > <scope id="1" parent_id="0" details="some data"/> > <scopes> > <scope id="2" parent_id="1" details="more data"/> > <scopes> > <scope id="4" parent_id="2" details="blah"/> > <scopes> > <scope id="7" parent_id="4" details="ogg"/> > <scope id="8" parent_id="4" details="abcd"/> > </scopes> > <scope id="6" parent_id="2" details="log"/> > <scope id="9" parent_id="2" details="xyz"/> > </scopes> > <scope id="3" parent_id="1" details="info"/> > <scope id="5" parent_id="1" details="foo"/> > </scopes> > </scopes> > > Where each <scope> record has an associated <scopes> > that lists each of the <scope> > records that are related to the first scope as a > child/parent in the following format: > > > <scope> > <scopes> > ...list of child scopes here... > </scopes> > > > I have been trying to fathom how to go about this, > mucking around with parameters, trying to write some > kind of recursive routine that will automatically sort > the scope records into this format, but thus far have > not been successful. Could anyone give any hints as > to how I would go about this? > > thanks heaps > > David Buddrige > > > > __________________________________ > Do you Yahoo!? > Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] converting flat xml data , Andreas L. Delmelle | Thread | RE: [xsl] converting flat xml data , David Buddrige |
RE: [xsl] Re: text() word lists, Michael Kay | Date | Re: [xsl] outputting unknown amount, David Elsmore |
Month |
Keywords