473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to merge two XML documents?

How can I merge the following two XML documents:

Persons.xml
<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person>
<name>Albert</name>
<department_id>1</department_id>
</person>
<person>
<name>Barry</name>
<department_id>2</department_id>
</person>
<person>
<name>Charlie</name>
<department_id>3</department_id>
</person>
</persons>

Departments.xml
<?xml version="1.0" encoding="UTF-8"?>
<departments>
<department>
<id>1</id>
<name>Management</name>
</department>
<department>
<id>2</id>
<name>Sales</name>
</department>
<department>
<id>3</id>
<name>Support</name>
</department>
</departments>

To generate the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person>
<name>Albert</name>
<department>Management</department>
</person>
<person>
<name>Barry</name>
<department>Sales</department>
</person>
<person>
<name>Charlie</name>
<department>Support</department>
</person>
</persons>

Jul 4 '08 #1
1 2628
Please try this stylesheet (by applying to, Persons.xml):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/
Transform"
version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:variable name="dep" select="document('Departments.xml')" />

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>

<xsl:template match="department_id">
<xsl:variable name="dep_id" select="." />
<department>
<xsl:value-of select="$dep/departments/department[id = $dep_id]/
name" />
</department>
</xsl:template>

</xsl:stylesheet>
Jul 5 '08 #2

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

Similar topics

2
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want...
3
by: Richard Fritzler | last post by:
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the...
9
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access...
8
by: Darryl Kerkeslager | last post by:
I hope that although this is 25% Access and 75% Word, that someone will know ... The whole problem here arises because 1) Microsoft acknowledges an 'issue' wherein TextInput type FormFields are...
3
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...
0
by: Reb | last post by:
Hi Apart from using dataset to merge 2 xml documents, is there any other way to merge 2 similar xml documents. Because when i get an error message when I am using dataset to merge the xml...
2
by: nickdu | last post by:
Is there a tool that will merge XML documents? We also need the reverse, we need to be able to create a Diff of two documents. What we're trying to do is just store differences of documents at...
4
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...
0
by: mbbostwick | last post by:
I have a problem with a mail merge procedure I used to use with Access '97. We recently converted to Office XP (2002) and I now have an issue I am unfamilliar with and have been unable to...
9
by: atc | last post by:
Sorry but another question from a newbie. I am trying to create a mail merge based on a query. I have a button on a form (form is based on query). I found this code in one of the discussions and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.