Click to See Complete Forum and Search --> : Merging different XML files with XSLt


xsltbeginner
11-30-2008, 02:07 PM
Hi all,
I want to merge data from one file into another using xslt, i am totally new with xslt so don't know how to do it and has to do it for 10 records having same id's in both files.
files are:

filexml1:
<ListRecords>
<record>
<header>
<identifier>some value herer</identifier>
<datestamp>2008-07-14T09:23:25Z</datestamp>
</header>
<metadata>
<group xsi:schemaLocation="some url">
<title>User manipulating this</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<!--Here <guid> is unique id used to merge record from both files based on it...>
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid>
<events>
<event>
<dateTime>2008-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
</record>
<!....More Records here....>
</ListRecords>

filexml2:
<ListRecords>
<record>
<header>
<!... Here <identifer> is unique id to merge records based on this id....>
<identifier>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</identifier>
<datestamp>2007-05-29T15:55:00Z</datestamp>
<datestampasdatetime>2007-05-29T17:55:00+02:00</datestampasdatetime>
</header>
<metadata>
<lom xsi:schemaLocation="some url">
<general >
<identifier>
<catalog>oai</catalog>
<entry>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</entry>
</identifier
<title>
<langstring>
<value>Graduation mw. S. de Caralt</value>
<language>en</language>
</langstring>
</title>
<catalogentry>
<catalog>nl.wur.wurtv</catalog>
<entry>
<langstring>
<value>2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</value>
<language>x-none</language>
</langstring>
</entry>
</catalogentry>
<grouplanguage>en</grouplanguage>
<description>
<langstring>
<value>Sponge Culture: Learning from Biology and Ecology</value>
<language>en</language>
</langstring>
</description>
</general>
<lifecycle xmlns="" />
<metametadata >
<metadatascheme>LORENET</metadatascheme>
</metametadata>
</lom>
</metadata>
</record>
<….More Records here…..!>
</ListRecords>

I want to merge all elements after <header> ( starting from element <metadata> and ending at </metadata> ) from filexml2 into filexml1 after its </metadata> element at the very end before </record> and finally </LIstRecords> elements based on unique id's in both files. Output file might look like.

fileoutput:
<ListRecords>
<record>
<header>
<identifier>some value herer</identifier>
<datestamp>2008-07-14T09:23:25Z</datestamp>
</header>
<metadata>
<group xsi:schemaLocation="some url">
<title>User manipulating this</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<!--Here <guid> is unique id used to merge record from both files based on it...>
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid>
<events>
<event>
<dateTime>2008-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
<!...Here starts the merged part from filxml2...>
<metadata>
<group xsi:schemaLocation="some url">
<title>User manipulating this</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<!--Here <guid> is unique id used to merge record from both files based on it...>
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid>
<events>
<event>
<dateTime>2008-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
<!....Here ends the merged part from filexml2....>
</record>
<!....More Records here....>
</ListRecords>


Plese help me how i will perform it in xslt.

Thanx...

xsltbeginner
12-01-2008, 07:58 AM
Any XSLT expert here ?
Please help me to solve the problem..
Thnx.

Charles
12-01-2008, 08:11 AM
XSLT really ins't the best choice here. What else do you have available? PHP? Perl? If you're using a Windows box then you can do it with VB or JScript which you should already have available.

xsltbeginner
12-01-2008, 08:14 AM
Actually i am asked to do it with Java alone or by using XSLT and java together so i dont have any other choice..

Why is it not possible with XSLT?

Charles
12-01-2008, 08:27 AM
XSLT transforms one document according to a set of instructions. You've got multiple files that you are trying to aggregate. If you are allowed to use Java as the glue there are some hacks that you could put together. You could aggregate the files into one and then transform with XSLT. Yolu would have to strip out any processing instructions at the start of each file and the result would have a new root with each file contained in a child of that root element. Then you could use XSLT and transform away. Or you could use Java with any old parser to step through your files and output the result. I would go with this one and often do. Except that I use JScript and MSXML instead of Java and Xerces (http://xerces.apache.org/xerces2-j/) because it's easy and portable. But then I feel all dirty for supporting Microsoft.

xsltbeginner
12-01-2008, 08:49 AM
Thnx. a lot and yes that is a possibility that to merge both files using Java but then have to define a new root element as both files have same root elements: <ListRecords> and then next element <record> and after merging them an xslt transformation would be possible but again i am totally new to xslt so will need some time to study xslt but have a deadline to meet :-(