Using an XSLT 2.0 processor and the collection()
function this is really easy.
Below is an example using Saxon:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pDirName" select="'D:/Temp/xmlFilesDelete'"/>
<xsl:template match="/">
<wrap>
<xsl:apply-templates select=
"collection(
concat('file:///',
$pDirName,
'?select=*.xml;recurse=yes;on-error=ignore'
)
)/*
"/>
</wrap>
</xsl:template>
<xsl:template match="*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on any XML document (not used), it processes all xml files in the file-system subtree starting at the directory, whose value is specified by the global parameter $pDirName
.
At the time this transformation was applied there were only two xml files there:
<apples>3</apples>
and
<oranges>3</oranges>
The correct result is produced:
<wrap>
<apples>3</apples>
<oranges>3</oranges>
</wrap>
This is the simplest example possible that can be constructed. To fully answer the question, the directory can be specified on the command line invoking Saxon. Read more about the ways to invoke Saxon from the command-line here.