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'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Merging two XML documents
- From: Simon Reed <simon dot reed at webx dot co dot uk>
- Date: Fri, 9 Mar 2001 13:50:02 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks for the response the output required would be as shown below.
Needs to follow some form of pattern matching with optional elements as
there may not be any addresses or items when the xslt is first run any more
suggestions gratefully accepted.
Simon Reed.
<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>
<address>
<addressline1>34 th Street</addressline1>
<addressline2>USA</addressline2>
</address>
</type>
</page>
-----Original Message-----
From: cutlass [mailto:cutlass@secure0.com]
Sent: 09 March 2001 13:37
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Merging two XML documents
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
**********************************************************************
The information in this E-Mail is confidential and may be
legally privileged. It may not represent the views of
WebX Limited. It is intended solely for the addressees.
Access to this E-Mail by anyone else is unauthorised. If you
are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. Any
unauthorised recipient should advise the sender immediately
of the error in transmission.
**********************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list