开发者

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

开发者 https://www.devze.com 2023-04-12 18:11 出处:网络
I ha开发者_如何学运维ve 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

I ha开发者_如何学运维ve 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?


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.


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.


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号