Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 8th, 2005, 03:23 AM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Merging 2 Xml docs

Hi all,
  i need to merge two xml documents(can be any two having the same structure). Since I am pretty new to xslt I cannot figure out I can possibly generalise the case for a node containing any number of child nodes. would deeply appreciate any help..

Regards,
Neeraj

 
Old December 8th, 2005, 04:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to explain what you mean by merge. If you can't write a specification, try giving a few examples of what you want to achieve. For example, what would be the result of merging the two documents

<a/>

and

<b/>

?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 8th, 2005, 05:15 AM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ya sure, giving two example documents:

1.xml********************************************* ******************************
<?xml version="1.0" ?>
<catalog>
    <book id="bk101">
        <author>
            <firstname>Gambardella</firstname>
            <secondname>Matthew</secondname>
        </author>
        <title>XML Developer's Guide</title>
    </book>
</catalog>
************************************************** **************************
2.xml********************************************* **************************
<?xml version="1.0" ?>
<catalog>
        <book id="bk102">
        <author>
            <firstname>Jeanette</firstname>
            <secondname>Dasha</secondname>
        </author>
        <title>Quack the Duck</title>
    </book>
</catalog>
************************************************** *************************
result.xml**************************************** *************************
<?xml version="1.0" ?>
<catalog>
    <book id="bk101">
        <author>
            <firstname>Gambardella</firstname>
            <secondname>Matthew</secondname>
        </author>
        <title>XML Developer's Guide</title>
    </book>
        <book id="bk102">
        <author>
            <firstname>Jeanette</firstname>
            <secondname>Dasha</secondname>
        </author>
        <title>Quack the Duck</title>
    </book>
</catalog>
************************************************** *************
Please note that I want to do this for any 2 xml docs and not the ones presented above. So the tags and number of nodes,child and sibling may vary...



 
Old December 8th, 2005, 05:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

OK, you've given one example, where the two documents use the same element names for the outermost element. Now please say what should happen if the two input documents are <a/> and <b/>.

You can solve your given example with:

<xsl:template match="/*">
<xsl:copy>
  <xsl:copy-of select="*"/>
  <xsl:copy-of select="document('two.xml')/*/*"/>
</xsl:copy>
</xsl:template>

But I've no idea whether this solves your general requirement, because you haven't explained the general requirement.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
2 XML Docs > 1 XSLT Stylesheet kwilliams XSLT 3 September 12th, 2005 11:22 AM
How to compare nodes from 2 XML docs kwilliams XSLT 0 August 30th, 2005 01:43 PM
Multiple XML Docs/One XSLT Stylesheet kwilliams XSLT 5 August 4th, 2005 11:54 AM
transformNode w/2 source XML docs? kwilliams XSLT 0 July 25th, 2005 03:38 PM
Handling remote XML docs in ASP delbarcr XML 1 March 25th, 2004 11:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.