xsl-list
[Top] [All Lists]

Re: Merging multiple xmls into a single xml

2005-07-15 04:38:40
Hi,

Tempore 09:05:14, die 07/15/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Neelam Joshi <mneelam(_at_)gmail(_dot_)com>:

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)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--