Maybe a bug in fn:base-uri
Added by Anonymous over 19 years ago
Legacy ID: #3336874 Legacy Poster: Martin Szugat (hampti)
I'm using Saxon for the BioWeka (http://www.bioweka.org) project and in particular for a stylesheet which contains the following code: <xsl:variable name="href" select="fn:resolve-uri($filename, base-uri($root))"/> <xsl:result-document method="text" href="{$href}"> ... The source document is set using a StreamSource object: xmlSource = new StreamSource(file); It works in most cases fine, however if I pass a file with a path like "C:\Dokumente und Einstellungen..." I get an error: FORG0002: Base URI {file:/C:/Dokumente und Einstel...} is invalid: Illegal character in path at index 18: file:/C:/Dokumente und Einstellungen/Martin/Eigene Dateien/Projekte/Hiwi/BioWeka/data.tmp/xml/E-MANP-2.xml So the problem is the white space within the URL. I solved this problem by using the following code: xmlSource = new StreamSource(file.toURL().toString().replaceAll(" ", "\%20")); However, I think this should be done by Saxon/fn:base-uri.
Replies (1)
RE: Maybe a bug in fn:base-uri - Added by Anonymous over 19 years ago
Legacy ID: #3337202 Legacy Poster: Michael Kay (mhkay)
This area is very tricky because there have been changes in the StreamSource class between JDK 1.4 and JDK 1.5 and it's quite hard to write code that works correctly in all cases with both. Which are you using? When you say you are using xmlSource = new StreamSource(file); do you mean that file is a java.io.File, or is it a String? In the past the class has done a very poor job at converting a File to a URI, so I normally recommend doing it yourself: using file.toURI().toString(), not file.toURL.toString(). The URI class does a much better job of the conversion. The spec says that when you supply a string to new StreamSource() then it must be a URI, which implies that it can't have spaces in it: so you are doing the right thing by replacing the spaces with %20. I would certainly recommend doing this. However, the XSLT/XPath/XQuery specs have recently introduced a more liberal definition, where most contexts that require a "URI" now in fact permit what I call a "wannabe-URI" - a string that can be turned into a valid URI by escaping it. The problem, unfortunately, is that you can't escape a URI that has already been escaped, and you can't tell whether an incoming URI has been escaped or not! That's compounded by the fact that there are different versions of StreamSource around, some of which do the escaping and some of which don't. If you do the escaping before your URI enters the system you're on safe ground. Michael Kay
Please register to reply