URIResolver with relative URLs

I have XML that I want to transform using XSLT.

The location of the XSLT is done using a URL http:// for file:/.

Then the XSLT refer to some other XSLT or XML using relative URL (e.g. <xsl:include href="../hello.xslt" /> or document('hello2.xml').

It's possible that A.xslt refers to B.xslt with is in another directory and B.xslt refers to C.xslt which is again in another XSLT.

The problem I have with the URIResolver that I'm writing is that I don't know from which document the URL to resolve is comming from.

How can I know in Source resolve(String href, String base) which document is trying to resolve this URL?

I just have href="../hello.xslt" and base="" but as I don't know which document is asking for it, I cannot resolve the location.

Please help,

Anthony

[835 byte] By [agoubarda] at [2007-10-2 23:34:59]
# 1

I just overcame a similar problem. What you have to do is make sure the Source object you use for the XSLT is created with a URI. For example if you use new StreamSource(InputStream stream) to pass the XSLT to the transformation change it to use StreamSource(InputStream stream, String uri) where uri points to the folder containing the XSLT or just use StreamSource(String uri) to locate the XSLT. If you don't use a Source with a URI attached then the XSLT resolves relative paths from the VM's working directory (where ever the VM was launched from). If you do use a Source with a URI then relative paths are resolved against the location of the referring stylesheet. In other words if "/foo/bar/path/A.xsl" referrs to "./B.xsl" then that would resolve to "/foo/bar/path/B.xsl". If the same "/foo/bar/path/A.xsl" referrs to "./lib/C.xsl" then it would resolve to "/foo/bar/path/lib/C.xsl".

Cliftona at 2007-7-14 16:17:01 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...