Robert Taylor wrote:
Greetings, I'm using Xalan2.6 for XML transformation. Some of my stylesheets need to import other style sheets. I would like to use a relative URI so that I don't have to change the value of the href attribute when I deploy to different machines.
I've read the technical definition of <xsl:import .../> href attribute here: http://www.w3.org/TR/xslt#import
and am confused on how it calculates the base URI.
For example: Let's say I have an application directory structure like so:
C:drive |---B-dir |---C-dir |---A.xsl |---B.xsl
I want A.xsl to import B.xsl, so my A.xsl looks something like:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="B.xsl"/>
</xsl:stylesheet>
I'm getting an exeption: Exception in startElement: Had IO Exception with stylesheet file: B.xsl
If I use the fully qualified URI to B.xsl,
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="file:///c:/b/c/B.xsl"/>
it works, but I would like to use a relative URI.
Any help would be greatly appreciated.
Take a look at the setURIResolver[1] method on the TransformerFactory
class.
These method is called by the XSLT processor when an xsl:import
function in your XSLT is found.
Then, if you write your own URIResolver [2], you can give the good location of your imported file to the XSLT Processor...
Create your own class, pass a base directory as argument, and then in
the resolve method, compute the good path...
TransformerFactory factory = TransformerFactory.newInstance(); factory.setURIResolver(new MyResolver(...));
class MyResolver implements URIResolver {
public Source resolve(String href,String base) {
// manage your cache and return a Source to the Processor
}
}[1]
http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/TransformerFactory.html#setURIResolver(javax.xml.transform.URIResolver)
[2] http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/URIResolver.html
HTH
Fr�d�ric Laurent
-- XPath free testing software : http://www.opikanoba.org/lantern/ Fr�d�ric Laurent http://www.opikanoba.org
