Re: [xsl] Merging multiple xmls into a single xml

Subject: Re: [xsl] Merging multiple xmls into a single xml
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Fri, 15 Jul 2005 13:38:40 +0200
Hi,

Tempore 09:05:14, die 07/15/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Neelam Joshi <mneelam@xxxxxxxxx>:

The number of input xmls is not fixed, it may vary. So is it possible
to accept more than one input file to an xsl script?

yes, take a look at this stylesheet:


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


<xsl:param name="sources">file1.xml|e:/temp/file2.xml|xml3</xsl:param>

<xsl:template match="/">
	<modulenames>
		<xsl:call-template name="loaddocuments"/>
	</modulenames>
</xsl:template>

<xsl:template name="loaddocuments">
<xsl:param name="string" select="concat($sources,'|')"/>
<xsl:if test="substring-before($string,'|') != ''">
<xsl:apply-templates select="document(substring-before($string,'|'))" mode="merge"/>
</xsl:if>
<xsl:if test="contains($string,'|')">
<xsl:call-template name="loaddocuments">
<xsl:with-param name="string" select="substring-after($string,'|')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


<xsl:template match="/" mode="merge">
	<xsl:copy-of select="//module"/>
</xsl:template>

</xsl:stylesheet>

This will load all files specified in the 'sources' parameter and copy their 'module' nodes.

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Spread the wiki (http://www.wikipedia.org)

Current Thread