1

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>
Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
Ryan Lewis
  • 365
  • 6
  • 15
  • This looks like its mostly copied from http://www.ibm.com/developerworks/library/x-tipmultxsl/ – a reference to that would have been appropriate. – Joachim Breitner Aug 22 '14 at 05:05

2 Answers2

1

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">
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
  • I moved it to C:\ and that did the trick, thanks! But, seems like the Saxon developers could do something to rectify this as well, since it replaced the spaces in the path to the transformation file just fine. – Ryan Lewis Jul 13 '09 at 21:21
  • I just tried your change, and I can't seem to get it to produce anything other than the same error. I also tried it in the declaration of $filename. Note that I had to remove the "fn:" namespace since it said it was undeclared. – Ryan Lewis Jul 13 '09 at 21:34
  • I'm not sure this will come across correctly in a comment, but I believe you need to declare the `fn` namespace as `http://www.w3.org/2005/xpath-functions`. More info: http://www.w3.org/TR/xquery-operators/#namespace-prefixes – Ben Blank Jul 13 '09 at 21:56
  • No, it turned it into a URL. Get the namespace from the second link. :-) – Ben Blank Jul 13 '09 at 21:57
1

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