Within an XSLT document, is it possible to loop over a set of files in the current directory?
I have a situation where I have a directory full of xml files that need some analysis done to generate a report. I have my stylesheet operating on a single document fine, but I'd like to extend that without going to another tool to merge the xml documents.
I was thinking along these lines:
<xsl:for-each select="{IO Selector Here}">
<xsl:variable select="document(@url)" name="contents" />
<!--More stuff here-->
</xsl:for-each>
In XSLT 2.0, and with Saxon, you can do this with the collection()
function:
<xsl:for-each select="file:///path/to/directory">
<!-- process the documents -->
</xsl:for-each>
See http://www.saxonica.com/documentation/sourcedocs/collections.html for more details.
In XSLT 1.0, you have to create an index that lists the documents you want to process with a separate tool. Your environment may provide such a tool; for example, Cocoon has a Directory Generator that creates such an index. But without knowing what your environment is, it's hard to know what to recommend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With