[xsl] regroup/collate like nodes

Subject: [xsl] regroup/collate like nodes
From: Ramon Buckland <ramon@xxxxxxxxxxxxxxx>
Date: Mon, 25 Oct 2004 01:43:15 +1000
Hi, 

I've been tackling this for a bit now but I seem
to be going in circles 

Examples are always best 

Given a document
<root>
  <a>
     <b>
        <c>
           <node1>hello</node1>
        </c>
        <d1>foo</d1>
     </b>
  </a>
  <a>
     <b>
        <c>
           <node2>world</node2>
        </c>
        <d2>bar</d2>
     </b>
  </a>
</root>

I need to group/collate the name like nodes such as

<root>
  <a>
     <b>
        <c>
           <node1>hello</node1>
           <node2>world</node2>
        </c>
        <d1>foo</d1>
        <d2>bar</d2>
     </b>
  </a>
</root>

notes...
The node names are not known so it needs to be generic.
The deepest child node is guaranteed to be unique for it's full
path .. ie, there will only be one
a/b/c/node1
but there could just easily be 
a/b/x/node1

I can see I need to walk the tree recursivley and
for each node, select/copy all other nodes that match the same
parent path and copy them in, but, also have a check that
stops it walking down a path, matched by name, that it has already done.

:-) just can't translate that to XSL..

any help would be appreciated
cheers
ramon

Current Thread