[xsl] Skeleton Merge

Subject: [xsl] Skeleton Merge
From: Saran Toochinda <sarantoo@xxxxxxxxx>
Date: Tue, 23 Aug 2005 15:42:22 +0700
I'm using XForms to collect XML data (company data, 1 file per
company). A skeleton of blank XML file which is based on a schema is
use to present the data input forms. Our schema is change from time to
time with additional data structure as well as corresponding XForms
control. There is no problem with the new file because it always based
on a new skeleton file. The problem arise on the existing files
because XForms bound it's control to existance of data element in
existing document. The newly added XForms controls don't get display
because there is no such data exist before.

My question is how can I merge newly added, blank element to an
existing file using XSLT to reflect the new data structure. For
example: merging existing.xml with skeleton.xml and looking for
somethink like the output below:

File existing.xml:

<company id="123">
   <name>ABC</name>
   <address>NJ</address>
   <phone>123456</phone>
   <fax>56789</fax>
   <branches>
        <branch>
            <name>Branch A</name>
        </branch>
        <branch>
            <name>Branch B</name>
        </branch>
   </branch>
</company>

File skeleton.xml with newly added element:

<company id="">
   <name/>
   <address/>
   <phone/>
   <fax/>
   <email/>              <!-- added -->
   <website/>           <!-- added -->
   <branches>
        <branch>
            <name/>
            <address/>    <!-- added -->
        </branch>
   </branch>
</company>

This is a needed output:

<company id="123">
   <name>ABC</name>
   <address>NJ</address>
   <phone>123456</phone>
   <fax>56789</fax>
   <email/>                           <!-- added -->
   <fax/>                               <!-- added -->
   <branches>
        <branch>
            <name>Branch A</name>
            <address/>               <!-- added -->
        </branch>
        <branch>
            <name>Branch B</name>
            <address/>               <!-- added -->
        </branch>
   </branch>
</company>


The actual schema is very complex and there are many schemas so
looking for a universal transform solution rather than hard coded per
element/file.

Many thanks in advance!

Current Thread