[xsl] Constructing a tree from leaf nodes (knowing the tree structure)?

Subject: [xsl] Constructing a tree from leaf nodes (knowing the tree structure)?
From: "Simon Shutter" <simon@xxxxxxxxxxx>
Date: Thu, 19 Apr 2007 13:01:58 -0700
This is probably a poorly posed question but essentially I am trying to
determine if XSLT is suited to the following problem.

Say I have a node fragment that defines a tree structure in which each
element appears only once eg.

<a>
  <b>
    <c/>
    <d/>
  </b>
  <e>
    <f/>
    <g>
      <h/>
	<i/>
    </g>
  </e>
</a>

I then have data for some of the leaf nodes ie.

<c complete="true" result="true"/>
<d complete="true" result="false"/>
<h complete="true" result="true"/>
<i complete="true" result="true"/>

In this example the leaf node </f> is missing.

Is it possible to create a node fragment that mimics the tree structure and
sets ancestor attributes according to the presence or absence of leaf nodes
and their attributes?

The desired output would be:

<a complete="false" result="false">
  <b complete="true" result="false">
    <c complete="true" result="true"/>
    <d complete="true" result="false"/>
  </b>
  <e complete="false" result="true"> 
    <f complete="false" result=""/>
    <g complete="true" result="true"/>
      <h complete="true" result="true"/>
      <i complete="true" result="true"/>
    </g>
  </e>
</a>

Current Thread