我正在尝试获取一个我发现的使用 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
输入.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>
转换.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”或类似的东西。)我怀疑长期解决方案是更改 XSLT 以将空格编码为%20
喂食前$filename
to xsl:result-document
,但恐怕我的 XSLT-2.0-fu 还不够强大,无法告诉您如何操作。
Edit:我还没有对此进行测试,因为我手边没有 XSLT 2.0 处理器,但浏览了文档后,看起来您想要编码 uri功能。像下面这样的东西可能对你有用:
<xsl:result-document href="{fn:encode-for-uri($filename)}" format="html">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)