two7s_clash
two7s_clash

Reputation: 5827

Generic way to apply an XSL to all files in a directory?

I have an XSL that transforms an XML file into a HTML file. Works great. But I would like to apply to a directory of files. Ideally a new HTML file for each XML file would be plunked down in the same directory.

I'm using Windows XP. I've got Cygwin, and am good enough with shell scripting. I've now got Saxon, but haven't been able to accomplish much with it so far. Right now I'm doing something like

java -jar settings.saxon_path -t -s:sourceFilepathNormal -xsl:normalizePath(myXSLT) -o:newXMLFilepathNormal

in a for loop on each file in the directory, but this seems hella clunky to me. Actually, doesn't seem that way, I know its clunky. What is the most elegant way you would accomplish this task with the tools at hand?

Upvotes: 2

Views: 684

Answers (3)

nobody
nobody

Reputation: 1

Try:

find . -name *.xml -exec java -jar settings.saxon_path -t -s:{} -xsl:normalizePath(myXSLT) -o:{}.html \;

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163498

You can do this using the collection() function as suggested; but there's also a facility on the Saxon command line to process a whole directory. Just give a directory name as the value of the -s argument and another directory as the value of the -o argument.

If you prefer a GUI approach, KernowForSaxon also has the capability to apply the same transformation to every file in a folder.

Upvotes: 1

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243539

You can do this easily in XSLT 2.0 using the standard XPath 2.0 function collection() and the XSLT 2.0 instruction <xsl:result-document>.

As the collection() function is only superficially defined in the W3C Spec, read the more Saxon-specific bits here:

And see for example my answer to this question.

Upvotes: 1

Related Questions