使用XSLT输出多个文件

发布于 2024-07-27 17:42:58 字数 2111 浏览 9 评论 0原文

我正在尝试获取一个我发现的使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤还要旧人安 2024-08-03 17:42:58

URI 中的字符 20 是“文档和设置”中的第一个空格。 作为快速修复方法,请尝试将文件移动到不带空格的路径。 (比如“C:\test”或类似的东西。)我怀疑长期解决办法是在输入 $filename 之前更改 XSLT 将空格编码为 %20xsl:result-document,但恐怕我的 XSLT-2.0-fu 还不够强大,无法告诉您如何操作。

编辑:我还没有对此进行测试,因为我手边没有 XSLT 2.0 处理器,但浏览了文档后,看起来您想要 encode-for-uri 函数。 像下面这样的东西可能对你有用:

<xsl:result-document href="{fn:encode-for-uri($filename)}" format="html">

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.

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:

<xsl:result-document href="{fn:encode-for-uri($filename)}" format="html">
流绪微梦 2024-08-03 17:42:58

我在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文