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>
1

2 Answers 2

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">
Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
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: w3.org/TR/xquery-operators/#namespace-prefixes
No, it turned it into a URL. Get the namespace from the second link. :-)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.