Please don't go off-list, it's important that when people find the question in the archives, they also find the answer. Also, it allows other users to contribute to solving the problem, which is especially important in cases like this where the problem can't easily be reproduced.
The replacement of spaces by %20 is correct behaviour when converting a file name to a URI. This isn't the source of the problem.
I'm afraid I can't think of any other ideas. There's clearly something on your system that's different from mine.
Michael Kay

From: Shapovalenko Daniil []
Sent: 05 December 2006 13:02
To: Michael Kay
Subject: RE: [saxon] import from path with spaces

Hello Michael!


Thank you for your answer.


I’ve upgraded to Saxon 8.8 with jdk1.5.0_10 on Windows XP.


I’ve added test line of code

System.out.println((new File("c:\\111 222\\zzz.txt")).toURI().toString());

And the output is



I’ve replaced one line of code when StreamSource constructor calls with

template = aFactory.newTemplates(new StreamSource(templateFile.toURI().toString()));


Unfortunately, problem is not solved.


Have You any idea how can I make this program works.


Best Regards, Daniil.

From: Michael Kay []
Sent: Tuesday, December 05, 2006 7:23 AM
To: 'Mailing list for SAXON XSLT queries'
Cc: Shapovalenko Daniil
Subject: RE: [saxon] import from path with spaces


I can't reproduce the problem: your program works for me. I am using Saxon 8.8 with jdk1.5.0_09 on Windows XP.


The Saxon command line processor uses


File styleFile = ...;

... new StreamSource(styleFile.toURI().toString())


rather than


    new StreamSource(styleFile)


I believe this is because the File to URI conversion done by the JAXP StreamSource class was at one time not as good as that done by File.toURI().


I'm pretty sure this problem was fixed some time ago, but you may somehow be using an old version of the code. Try the file.toURI().toString() approach and see if it works.


Michael Kay


From: [] On Behalf Of Shapovalenko Daniil
Sent: 04 December 2006 12:30
Subject: [saxon] import from path with spaces



I’ve tried to transform simple file with simple template:


--- XML

<?xml version="1.0" encoding="iso-8859-1"?>

<?xml-stylesheet type="text/xsl" href="hello.xsl"?>

<greeting>24.08.2006 12:05:27</greeting>


--- XSL1

<?xml version="1.0" encoding="windows-1251"?>

<xsl:stylesheet xmlns:xsl="" version="1.0">

<xsl:import href="./one dir/import.xsl"/>



--- XSL2 ("./one dir/import.xsl")

<?xml version="1.0" encoding="windows-1251"?>

<xsl:stylesheet xmlns:xsl="" version="1.0">

<xsl:template match="/">

test root element




When I try to transform it from command line all is fine.

When I try to transform it in program the exception occurs.


--- Exception

Error at xsl:import on line 4 of file:///D:/workspace/test/hello.xsl:

  XTSE0165: D:\workspace\test\one%20dir\import.xsl


As you can see, it replace space symbol with ‘%20’.


How can I solve this problem.

Code is here:


public class XSLTTemplates {


    private TransformerFactory aFactory = null;


    public XSLTTemplates() {

        String XSLTtransf = "net.sf.saxon.TransformerFactoryImpl";

        System.setProperty("javax.xml.transform.TransformerFactory", XSLTtransf);


        try {

            aFactory = TransformerFactory.newInstance();

        } catch (TransformerFactoryConfigurationError e) {

            System.out.println("XslTemplatesFactory hasn't been initialized!");



        System.out.println("XslTemplatesFactory has been initialized - " + aFactory.getClass().getName());



    public String process() {

        String templateName = "hello.xsl";


        File templateFile = new File(templateName);

        Templates template = null;

        try {

            template = aFactory.newTemplates(new StreamSource(templateFile));

        } catch (TransformerConfigurationException e) {




        if (template != null) {

            StreamResult ReplyResult = new StreamResult(new StringWriter());

            Transformer transformer;

            try {

                transformer = template.newTransformer();

                transformer.transform(new StreamSource("hello.xml"), ReplyResult);

                return ReplyResult.getWriter().toString();

            } catch (TransformerException e) {




        return "";



    public static void main(String[] args) {

        XSLTTemplates test = new XSLTTemplates();


        String res = test.process();

        FileWriter fw = null;

        try {

            fw = new FileWriter(new File("out.txt"));


        } catch (IOException e) {


        } finally {

            if (fw != null) {

                try {


                } catch (IOException e) {








Best Regards, Daniil.