Hi,
(haven't tried this, but...) You could probably do something like:
public Source resolve(String href, String base)
throws TransformerException {
Source source = super.resolve(href, base);
File file = new File(source.getSystemId());
if (file.exists()) {
return source;
} else {
URL url = this.getClass().getResource(file.getName());
return new StreamSource(url.openStream());
}
}
let me know if it or something like it works :) I don't know if the
Source will have a system id??
best,
-Rob
Barry Lay wrote:
Marcus,
I tend to use a URIResolver for this sort of thing. The
javax.xml.transform.Source interface does not define a mechanism for
determining the source file location (there may not even be one) so
the XSL transform has no way of knowing where the XSL file came from,
thus can't find things relative to it. Using a resolver allows you to
specify the relative location of imports at run time which is also
useful for testing. You could put the value in an environment
variable or system property.
The resolve(href, base) method returns a Source object which gives you
plenty of flexibility - the imported stylesheet doesn't even have to
be in a file.
Barry
Marcus Andersson wrote:
I'm trying to import a stylesheet from another stylesheet with Saxon
8 from a servlet running in Tomcat and I'm using dom4j for the
documents. I am using TransformerFactory.newTemplates(xslSource).
How do I need to set it up to make the resolver resolve relative urls
(<xsl:import href="common.xsl"/> where common.xsl resides in the same
dir as the importing xsl)? The same happens when I use include.
When I do according to the above I get the following in the log:
Error at xsl:import on line -1 of :
java.io.FileNotFoundException: C:\WINDOWS\system32\common.xsl (The
system cannot find the
file specified)
So, what should I do to make my setup work? I have obviously made an
error somewhere. Does it depend on how I create my
javax.xml.transform.Source for the XSL? Or do I really have to
implement a custom URIResolver for this, what I believe, pretty
common case?
/Marcus