[xsl] Merging two xml files using a template file.

Subject: [xsl] Merging two xml files using a template file.
From: "Bhaskar Reddy" <bhaskar_reddy@xxxxxxxxxxx>
Date: Mon, 12 Jan 2004 22:02:09 +0530
Hi,
I have many sets of data in xml files. Each set has three xml files. And each set has different tree structure. So I am looking for some general solution.


I want to merge file 1 and file 2, depending on the attribute"src" from file 3( template file) of the set.

Sample files for a set are as shown below..

the "src" attribute tells from where to get the value of that element.

file 1: xml
-------------
<Data>
    <Name> Peter Radke </Name>
    <Age> 34 </Age>
    <Address>
               <Street> 34 Peter Ave </Street>
               <City> Chicago</City>
               <Country> USA </Country>
    </Address>
</Data>

file 2: xml : Has very similar structure but different values

<Data>
    <Name> Peter </Name>
    <Age> 38 </Age>
    <Address>
               <Street> 38 Bradway st</Street>
               <City> NewYork</City>
               <Country> USA </Country>
    </Address>
</Data>

file 3: xml :
<Data>
    <Name src="file1"> </Name>
    <Age src="file2"></Age>
    <Address src="file2">
    </Address>
</Data>

file 3 is a template file for merging file 1 and file 2. the src attribute in this file tells from where to get the element value from. For example the Name element value should be read from the file1 and the Age should be from the file 2. And the whole <Address> structure should be read from the file 2.

So the result should look like

Result FILE:
----------------
<Data>
    <Name> Peter Radke </Name>
    <Age> 38 </Age>
    <Address>
               <Street> 38 Bradway st</Street>
               <City> NewYork</City>
               <Country> USA </Country>
    </Address>
</Data>

The structure of these xml files are not predefined. So I can't hard code any element names.
Can any one help me how to do it using XSLT.


Thanks
Bhaskar

_________________________________________________________________
Free transactions in any ATM across India. http://server1.msn.co.in/msnleads/suvidha/dec03.asp?type=hottag Click here.



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread