Re: [xsl] How to merge multiple XML files

Subject: Re: [xsl] How to merge multiple XML files
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 07 May 2007 11:22:17 +0200
Colin Paul Adams wrote:
"Abel" == Abel Braaksma <abel.online@xxxxxxxxx> writes:

Abel> Please read the reply that George Cristian Bina sent you: Abel> you can use the fn:collection() function to your purpose in Abel> XSLT 2.0

But note that you must read the documentation for your specific XSLT
processor first, as although the function is standard, the meaning of
any particular URI is not.

Indeed. I tried it once with AltovaXML for instance, and couldn't find a way to make it work (and there's no documentation at all). But both Gestalt and Saxon have a well-documented way of collecting a directory.


One more thing I can think of: in XSLT 2.0, the meaning of the fn:document() function was expanded to accept a sequence of more than one value as its first argument, each being a URI. Of course, this won't help you when you do not know the names of the files up front, unless you can somehow give them as a parameter on the commandline:

document( ('one.xml', 'two.xml') )

will give you a sequence of two document nodes, one for 'one.xml' and one for 'two.xml'.

Suppose you'd have a space separated list of files from your directory in a parameter (you can do so with some trickery on the commandline of course), this should work to 'concatenate' all files in one output document:

<xsl:copy-of select="document( tokenize($filelist, ' ') )" />

Cheers,
-- Abel Braaksma

Current Thread