Re: [xsl] How to merge multiple XML files

Subject: Re: [xsl] How to merge multiple XML files
From: "Alexander Johannesen" <alexander.johannesen@xxxxxxxxx>
Date: Mon, 7 May 2007 15:40:39 +1000
Hiya,

On 5/7/07, J. S. Rawat <jrawat@xxxxxxxxxxxxxx> wrote:
Would anybody let me know that how to merge multiple xml files within a
directory into a single XML file. I have no idea about it.

Several ways of doing it;


 a) Scripting language : create array of input files, read them in,
locate all the <record> elements (and content), and dump them all out
in a file containing the surrounding <records> element.

b) XSLT :

	<xsl:template match="/">
		<xsl:variable name="a" select="document('a.xml')/records" />
		<xsl:variable name="b" select="document('b.xml')/records" />
		<xsl:variable name="c" select="document('c.xml')/records" />
		<records>
			<xsl:copy-of select="$a/text()|$a/*" />
			<xsl:copy-of select="$b/text()|$b/*" />
			<xsl:copy-of select="$c/text()|$c/*" />
		</records>
	</xsl:template>

       or a more dyunamic version with an XML input, or XSLT 2.0 with
embedded XML. If you need some special sort-order you need to tweakit
a bit.

c) with DTD's.

And I'm sure there's more.


Alex -- --------------------------------------------------------------------------- Project Wrangler, SOA, Information Alchymist, UX, RESTafarian, Topic Maps ------------------------------------------ http://shelter.nu/blog/ --------

Current Thread