This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Merging two XML documents
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Merging two XML documents
- From: cutlass <cutlass at secure0 dot com>
- Date: Fri, 09 Mar 2001 13:37:16 +0000
- References: <2B67AB21CA6AD411A1660008C70D3679051462@WEBXCOMMS01>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Simon Reed wrote:
> Being relatively new to xml I have come across a problem, which is as
> follows:
> What is the best method to merge and/or update 2 XML's with the same
> structure. The merging/updating XML will only contain a section of a larger
> XML it is to be merged into but the structure will be identical from the
> root node. Examples are shown below:
> XML to merge
> <page>
> <type>
> <address>
> <addressline1>34 th Street</addressline1>
> <addressline2>USA</addressline2>
> </address>
> </type>
>
faq on using document() function
http://www.dpawson.co.uk/xsl/N2602.html#N18697
faq on merging
http://www.dpawson.co.uk/xsl/merge.html
depending on what u mean by 'merge', this can be done using one xml file
as your list of files to process ( note-with sablot xsl parser u must
use file://// for filepaths), then having the xsl recurse through this
list, loading test1, test2, and so on...... and doing a xsl:copy.
what i could not get from your email was if u wanted to merge records
from different documents, might be able to help more if u give an ex of
required output.
test.xsl( as adopted from Steve Tinney from XSLT FAQ )
-----------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="file">
<xsl:variable name="pathname" select="."/>
<xsl:variable name="contents" select="document($pathname)"/>
<xsl:copy-of select="$contents"/>
</xsl:template>
</xsl:stylesheet>
test.xml ( as adopted from Steve Tinney from XSLT FAQ )
-----------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mother>
<file>test1.xml</file>
<file>test2.xml</file>
</mother>
test1.xml
-------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<page>
<order>
<item cost="100">CD-ROM</item>
</order>
<type>
<name>abc</name>
<name>jkl</name>
<name>mno</name>
<name>pqr</name>
<address>
<addressline1>43 sdfsdf</addressline1>
</address>
<address>
<addressline1>64 The Road</addressline1>
<addressline2>Big City</addressline2>
<addressline3>UK</addressline3>
</address>
</type>
</page>
test2.xml
-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<page>
<type>
<address>
<addressline1>34 th Street</addressline1>
<addressline2>USA</addressline2>
</address>
</type>
</page>
cheers, jim fuller
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list