使用XSLT输出多个文件
我正在尝试获取一个我发现的使用 XSLT 2.0 输出多个文件的示例。
将 Saxon B 9.7.0.1 与 Java 1.6 一起使用,出现此错误:
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>
I'm trying to get an example that I found for using XSLT 2.0 to output multiple files working.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
URI 中的字符 20 是“文档和设置”中的第一个空格。 作为快速修复方法,请尝试将文件移动到不带空格的路径。 (比如“C:\test”或类似的东西。)我怀疑长期解决办法是在输入
$filename
之前更改 XSLT 将空格编码为%20
到xsl:result-document
,但恐怕我的 XSLT-2.0-fu 还不够强大,无法告诉您如何操作。编辑:我还没有对此进行测试,因为我手边没有 XSLT 2.0 处理器,但浏览了文档后,看起来您想要 encode-for-uri 函数。 像下面这样的东西可能对你有用:
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
toxsl:result-document
, but I'm afraid my XSLT-2.0-fu isn't strong enough to tell you how.Edit: 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:
我在 saxon -o: outputfile 用 %20 替换空格时遇到了同样的问题..
发现问题是 saxon 和 java 版本。
Linux JAVA 1.7.0_45:Saxon 创建 %20
Unix JAVA 1.5.0_61:SAXON 创建 %20
Unix JAVA 1.4.2_22:SAXON 不创建 %20 目录
I had the same issue with saxon -o: outputfile replacing the spaces with %20..
found out the issue is saxon and java versions.
Linux JAVA 1.7.0_45 : Saxon creates %20
Unix JAVA 1.5.0_61 : SAXON creates %20
Unix JAVA 1.4.2_22 : SAXON Does Not creates %20 directory