I've stuck on a problem with Saxon 9.5 HE and I haven't found a solution for days.
Maybe it is something obvious and easy, but I just can't see it.
What I'm trying to do is to XSL transform XML by specifying a custom URIResolver.
If I run this, I get my XSL files loaded and the transformation takes place producing a valid result.
try {
//tfactory.setURIResolver(new DOTUriResolver());
Transformer transformer = tfactory.newTransformer(xslSource);
if (transformer!=null)
transformer.transform(xmlSource, new StreamResult(System.out));
}
catch (Exception e) {
System.err.println(e.getMessage());
}
If I comment out
tfactory.setURIResolver(new DOTUriResolver());
And provide a very simple URIResolver that just prints out the values of base and href:
@Override
public Source resolve(String href, String base) throws XPathException {
System.out.println( " resolve: " + base + " | " + href);
return;
}
I get errors when creating the transformer object.
javax.xml.transform.TransformerConfigurationException: XML-22000: (Fatal Error) Error while parsing XSL file
Looking in what is printed by my URIResolver, I see that the base parameter is always the same and has the value of the root (first) XSL file. I would expect that base changes based on the current XSL file that contains the xsl:import or xsl:include tags (or document()), but that stays the same for all files.
This is the code that creates the xslSource and sets the systemId:
StreamSource source = new StreamSource(file);
String systemID = file.toURI().toURL().toString();
source.setSystemId(systemID);
Do you have any ideas why is this happening? This was used to be working in the past with previous versions of Saxon (9.1).
Any help would be much appreciated.
EDIT:
This is my URI resolver (full code):
package com.mekon.xproc;
import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import net.sf.saxon.trans.XPathException;
public class DOTUriResolver implements URIResolver{
@Override
public Source resolve(String href, String base) throws XPathException {
System.out.println( " resolve: " + base + " | " + href);
return null;
}
}
Now, if I use it I get the problem described above. Base will remain the same for every call, the same value as for the first source. If I don't call it, then the URIs are resolved with no problems.