使用 XSLT 输出多个文件 [英] Using XSLT to output multiple files
问题描述
我正在尝试获取我发现的使用 XSLT 2.0 输出多个工作文件的示例.
I'm trying to get an example that I found for using XSLT 2.0 to output multiple files working.
在 Java 1.6 中使用 Saxon B 9.7.0.1,我收到此错误:
Using Saxon B 9.7.0.1 with Java 1.6, I get this error:
C:\Documents and Settings\Administrator\Desktop\saxon>java -jar saxon9.jar -s:input.xml -xsl:transform.xml
Error on line 15 of transform.xml:
java.net.URISyntaxException: Illegal character in path at index 20: file:///C:/Documents
and Settings/Administrator/Desktop/saxon/output1/test1.html
at xsl:for-each (file:/C:/Documents%20and%20Settings/Administrator/Desktop/saxon/transform.xml#10)
processing /tests/testrun[1]
Transformation failed: Run-time errors were reported
input.xml
<?xml version="1.0" encoding="UTF-8"?>
<tests>
<testrun run="test1">
<test name="foo" pass="true" />
<test name="bar" pass="true" />
<test name="baz" pass="true" />
</testrun>
<testrun run="test2">
<test name="foo" pass="true" />
<test name="bar" pass="false" />
<test name="baz" pass="false" />
</testrun>
<testrun run="test3">
<test name="foo" pass="false" />
<test name="bar" pass="true" />
<test name="baz" pass="false" />
</testrun>
</tests>
transform.xml
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:output method="html" indent="yes" name="html"/>
<xsl:template match="/">
<xsl:for-each select="//testrun">
<xsl:variable name="filename"
select="concat('output1/',@run,'.html')" />
<xsl:value-of select="$filename" /> <!-- Creating -->
<xsl:result-document href="{$filename}" format="html">
<html><body>
<xsl:value-of select="@run"/>
</body></html>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
推荐答案
URI 中的字符 20 是文档和设置"中的第一个空格.作为快速修复,尝试将文件移动到没有空格的路径.(比如,C:\test"或类似的.)我怀疑长期修复是在输入 $filename
之前改变你的 XSLT 将空格编码为 %20
xsl:result-document
,但恐怕我的 XSLT-2.0-fu 不够强大,无法告诉您如何操作.
Character 20 in your URI is the first space in "Documents and Settings". As a quick fix, try moving the files to a path without spaces. (Say, "C:\test" or some such.) I suspect the long-term fix is to change your XSLT to encode spaces to %20
before feeding $filename
to xsl:result-document
, but I'm afraid my XSLT-2.0-fu isn't strong enough to tell you how.
我没有测试过这个,因为我手边没有 XSLT 2.0 处理器,但是在浏览文档之后,看起来你想要 encode-for-uri 功能.类似以下内容可能对您有用:
I haven't tested this, as I don't have an XSLT 2.0 processor handy, but after glancing at the docs, it looks like you want the encode-for-uri function. Something like the following may work for you:
<xsl:result-document href="{fn:encode-for-uri($filename)}" format="html">
这篇关于使用 XSLT 输出多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!