我有一个可将 XML 文件转换为 HTML 文件的 XSL。效果很好。但我想应用于文件目录。理想情况下,每个 XML 文件都有一个新的 HTML 文件放在同一目录中。
我使用的是Windows XP。我有 Cygwin,并且对 shell 脚本编写已经足够好了。我现在已经有了 Saxon,但到目前为止还没有能够用它完成很多事情。现在我正在
java -jar settings.saxon_path -t -s:sourceFilepathNormal -xsl:normalizePath(myXSLT) -o:newXMLFilepathNormal
对目录中的每个文件执行类似 for
循环的操作,但这对我来说似乎非常笨重。事实上,看起来并非如此,我知道它很笨重。使用手头的工具完成这项任务的最优雅的方式是什么?
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?
发布评论
评论(3)
您可以在 XSLT 2.0 中使用标准 XPath 2.0 函数轻松完成此操作
collection()
和 XSLT 2.0 指令。
由于
collection()
函数仅在 W3C 规范中进行了表面定义,因此请阅读 更多撒克逊特定位:例如,请参阅我对 这个问题。
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:
您可以按照建议使用 collection() 函数来执行此操作;但 Saxon 命令行上还有一个工具可以处理整个目录。只需将一个目录名称作为 -s 参数的值,将另一个目录作为 -o 参数的值即可。
如果您更喜欢 GUI 方法,KernowForSaxon 还能够对文件夹中的每个文件应用相同的转换。
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.