473,626 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML transfrom: merge 2 or more different XML file into one

Hi,

I need to merge XML from different sources to 1 XML file.
I am wondering if XSLT could do this job as usually it is used to perform
1 to 1 file transfrom

eg.
src1.xml
<?xml version="1.0" encoding="UTF-8"?>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>

src2.xml
<?xml version="1.0" encoding="UTF-8"?>
<nickname>Fre d</nickname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>

result.xml

<?xml version="1.0" encoding="UTF-8"?>
<addressbook>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>
</addressbook>
Jacinle
Jul 20 '05 #1
3 4177
Cat
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 23 Jun 2004 20:32:22 -0700, Jacinle Young wrote:
Hi,

I need to merge XML from different sources to 1 XML file.
I am wondering if XSLT could do this job as usually it is used to perform
1 to 1 file transfrom

eg.
src1.xml
<?xml version="1.0" encoding="UTF-8"?>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>

src2.xml
<?xml version="1.0" encoding="UTF-8"?>
<nickname>Fre d</nickname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>

result.xml

<?xml version="1.0" encoding="UTF-8"?>
<addressbook>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>
</addressbook>

I haven't done any work on a problem of that sort but I'd say XInclude would be
the solution.
http://www.w3.org/TR/xinclude/

You definitely can't do it in vanilla xslt. You could try some ugly programming
hacks but I'd go with XInclude.
- --
Cat

http://www.ratrobot.com/writing/charity/ What is charity?
Is it charitable to give people a blanket but not a job? In this
article I will explore exactly what charity is.
Fri Jun 25 22:34:29 UTC 2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA3Kh1KHR jYtwQ1QARAvI4AK DfQnELC0FGOTPC2 0dP68O5yNle8gCf X2G1
NTlH6Y9gJ8XsqvV +S0vUMpw=
=35Yk
-----END PGP SIGNATURE-----

Jul 20 '05 #2
Cat
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 23 Jun 2004 20:32:22 -0700, Jacinle Young wrote:
Sorry, there is a simple way to do it in vanilla xslt, and here it is.

=============== ==== XSLT =============== ========
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

<xsl:template match="root">
<addressbook>
<xsl:copy-of select="child:: *"/>
<xsl:copy-of select="documen t('test2.xml')/root/*[name(.)!='nickn ame']"/>
</addressbook>
</xsl:template>
</xsl:stylesheet>
=============== == TEST1.XML =============== ====
<?xml version="1.0" encoding="UTF-8"?>
<root>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>
</root>
=============== = TEST2.XML =============== ====
<?xml version="1.0" encoding="UTF-8"?>
<root>
<nickname>Fre d</nickname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>
</root>

=============== = OUTPUT =============== =======

<?xml version="1.0" encoding="UTF-8"?>
<addressbook>
<nickname>Fre d</nickname>
<email>fr**@bar neys.house</email>
<html>TRUE</html>
<firstname>Fred </firstname>
<lastname>Flint stone</lastname>
<work>999-Quarry</work>
<home>999-BedrockLane</home>
<fax>888-Squawk</fax>
<pager>777-pager</pager>
<cell>555-cell</cell>
</addressbook>
Quite a neat trick? And I wouldn't have know about it without your question
8^).
- --
Cat

http://www.ratrobot.com/java/menu/ Simple menu applet that lets you
set colors,fonts and use it with a tiled background. It is completely FREE
for any use.
Sun Jun 27 21:12:05 UTC 2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA3zglKHR jYtwQ1QARAtwMAK DacBKFEsI4lsCl/xLWqqb+Hy13mQCf T5iF
3qypgKEWF/Oop3EzNFIL5S8=
=sW2r
-----END PGP SIGNATURE-----

Jul 20 '05 #3
Cat,

It works! Thank you!

Jacinle
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2544
by: Hunter Hou | last post by:
Folks, I am just curious why standard library doesn't provide a "merge" operation without sorting, because sometimes I don't require sorting, just merge. I looked at list.merge() and merge() algorithm, both require sorted sequenece. Thanks, Hunter
5
4563
by: stemc © | last post by:
Hi there, In work, we often mail merge letters and post them to contacts. But more and more, we've been emailing information to people instead. So far, I've been writing a single generic email, then copying and pasting the email addresses into the address fields. I start the email off with 'Dear all...' But is there a way to 'email merge' this directly into outlook emails, in the same way we do for normal printed letters? This...
3
5577
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm having trouble with step 2. It opens the word document fine but does not perform the mail merge of...
4
21664
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of items that don't do anything. MDI Container.IsMdiContainer = true MenuStrip.AllowMerge = true /// First menu items this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
4
4949
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on the ordered or unordered xml node tree of the compared documents? - what identifiers/criteria should be used by default to match elements of the same type in different documents? - should a diff tool consider move operations or only insert/delete
13
4025
by: ralphedge | last post by:
These sorts work fine on 100000 ints but if I go much higher they will both segmentation fault **************************MERGESORT********************* mergesort(int *a, int size) //a is pointer to the array, size is # of elements { int b;
4
7220
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a compile error stating that it cannot find: "C:\Program Files\Common Files\Merge Modules\Crystal_regwiz2003.msm" I am not sure where to get this file or even if it is appropriate (i.e., should there be a newer version for Visual Studio 2005).
2
1553
by: Matt | last post by:
Hi All, I want to do the following: 1). Create a Word Document that has set text and placeholders for information in my database. 2.) Write a query that returns some records. 3.) Fill the word document with these records. So, for example, if the query returns 100 records, I want to create a word document for each record. This word document will be the same
7
7233
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking for any comments about the use of the docmd.transfertext method instead of the code Albert used for creating the text file. Also, perhaps some ideas for coding the Subject Line of each email so
0
8268
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.