• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tranformning multiple XML docs to a single XML doc

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
TIA
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
<fa>
<a name="a1">3</a>
<a name="a2">5</a>
<a name="a3">2</a>
<a name="new">1</a>
</fa>
file 2
<fb>
<a name="a1">1</a>
<a name="a3">1</a>
<a name="a4">2</a>
</fb>
required output
<res>
<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>
</res>
xsl file:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl utput method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="document('dp-f1.xml')/fa/a|
document('dp-f2.xml')/fb/a[not(@name=document('dp-f1.xml')/fa/a/@name)]">
<xsl:sort select="@name"/><a name="{@name}">
<xsl:value-of select="sum(document('dp-f1.xml')/fa/a[@name=current()/@name]|
document('dp-f2.xml')/fb/a[@name=current()/@name])"/>
</a>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic