Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple file inputs?

Tags:

io

xml

xslt

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>
like image 652
Josh Bush Avatar asked Sep 19 '08 14:09

Josh Bush


1 Answers

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.

like image 130
JeniT Avatar answered Oct 22 '22 19:10

JeniT