File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Tranformning multiple XML docs to a single XML doc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Tranformning multiple XML docs to a single XML doc" Watch "Tranformning multiple XML docs to a single XML doc" New topic

Tranformning multiple XML docs to a single XML doc

Christian Schnepf

Joined: Sep 25, 2001
Posts: 28
Good morning,
I have need to take two xml documents and run them through a single xsl document to produce a single xml document.
I am currently using xalan to do single xml document transformation, but do not see anything about multiples. Should I be looking to a different set of classes?
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
Since your are converting using XSL, you can try using document() function which could help you load external xml document.
Here a sample that I cut and pasted from another site.
Two xml files
file 1
<a name="a1">3</a>
<a name="a2">5</a>
<a name="a3">2</a>
<a name="new">1</a>
file 2
<a name="a1">1</a>
<a name="a3">1</a>
<a name="a4">2</a>
required output
<a name="a1">4</a>
<a name="a2">5</a>
<a name="a3">3</a>
<a name="a4">2</a>
<a name="new">1</a>
xsl file:
version="1.0"><xsl utput method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="document('dp-f1.xml')/fa/a|
<xsl:sort select="@name"/><a name="{@name}">
<xsl:value-of select="sum(document('dp-f1.xml')/fa/a[@name=current()/@name]|

Spritle Software Blogs
I agree. Here's the link:
subject: Tranformning multiple XML docs to a single XML doc
jQuery in Action, 3rd edition