VSe
VSe

Reputation: 929

How to run Saxon XSLT for all the files in the folder

I have list of files in the folder/subfolders. How to run a single XSLT to run all the files in the folder/subfolder. Is it possible in saxon command line?

I have tried the below command but its not working:

 java -jar saxon9.jar -o:foldername -xsl:xslfilename.xsl

Your help much appreciated.

Upvotes: 1

Views: 3340

Answers (2)

PhillyNJ
PhillyNJ

Reputation: 3902

Since you are using Saxon, you can use xslt 2.0 and the collection function.

for example:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
    <xsl:for-each select="collection(concat('file:///c:/filesarehere', '?select=*.xml;recurse=yes'))">
        <!--process nodes-->
    </xsl:for-each>
</xsl:template>

Upvotes: 5

Michael Kay
Michael Kay

Reputation: 163498

If you want to create one output file for each input file, with corresponding names, then you can set -s:inputDir and -o:outputDir on the command line, and it will process all the files in the directory. But this is a bit inflexible, for example if there are some non-XML files in the directory that you want to ignore. Controlling the process from within the stylesheet, using the collection() function, as suggested by @PhilVallone is more flexible.

Upvotes: 3

Related Questions