Michael Kay wrote:
How good is the MSXSL transformer with extensions to combine multiple
XML files into one XML file by XSLT?
So long as each file is retrieved indivudually using document(), no problem,
but it doesn't have anything like the XSLT 2.0 collection() function. Though
you can simulate it by constructing a source document containing a list of
URLs and then applying document() to those URLs.
However, assuming you have the XML source file that contains the list of
file names (URLs) that Michael mentioned, then a single invocation of
document() can return all the root nodes from your XML files. (You don't
have to do it individually for each one, e.g., inside <xsl:for-each>.)
And you don't need any extension functions to do this.
Let's say you have a file named files.xml in the "config" directory that
contains this:
<files>
<file>input/foo.xml</file>
<file>input/bar.xml</file>
<file>input/bat.xml</file>
</files>
Given the above document, the following expression will return a
node-set containing three root nodes, corresponding to the three files
listed.
document(document('config/files.xml')/files/file)
The file names are resolved relative to the location of files.xml by
default, i.e. from the "config" directory in this case. The XSLT
processor will look for an "input" directory inside the "config"
directory. If you want to resolve them relative to your main source
document (rather than from the "config" directory), then you could use
the second (optional) argument to the document() function, like so:
document(document('config/files.xml')/files/file, /)
The / in the second argument tells the function to resolve the URLs
relative to the base URI of the source document instead of from the
config directory (where files.xml lives). The XSLT processor will look
for an "input" directory inside whatever directory your source document
came from.
Finally, if you want to resolve them relative to the stylesheet's base
URI, you would use this:
document(document('config/files.xml')/files/file, document(''))
The document('') in the second argument returns the root node of the
stylesheet itself, so the relative URLs in files.xml are resolved
relative to the base URI of the stylesheet. The XSLT processor will look
for an "input" directory insider whatever directory your stylesheet came
from.
One more note: all the above examples assume that the "config" directory
is in the same directory as the stylesheet. When you pass document() a
string as the first argument it assumes the base URI of the stylesheet.
When you pass it a node-set as the first argument (as we did with the
<file> elements), then the function uses the base URI of each node in
the node-set. In either case, you can override the base URI behavior by
using the second optional argument (which must be a node-set). So, for
example, if the "config" directory is in the same location as your
source document, then you'd want to substitute this to grab the root
node of files.xml in each of the above examples:
document('config/files.xml', /)
Hope this helps,
Evan
--~------------------------------------------------------------------
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>
--~--