Still no luck.
-1. A note...
getServletContext() (in Tomcat at least) is the JSP's directory, not the
WEB-INF directory. I am able to getResourceAsStream using the JSP's
directory as the root.
0. The directory structure is webapps\project containing...
myJsp.jsp
xsl\<xsl pages>
web-inf\
1. I have a JSP page with the ServletContextResolver (see the previous
message) as an inner class (I know it's not the cleanest way to do it, just
want to see if it works).
2. The JSP gets an input stream for the XSL file
java.io.InputStream xsl =
getServletContext().getResourceAsStream("xsl/myXsl.xsl");
3. The JSP creates the transformer from the input stream
javax.xml.transform.TransformerFactory tFactory =
javax.xml.transform.TransformerFactory.newInstance();
javax.xml.transform.Transformer transformer =
tFactory.newTransformer(new
javax.xml.transform.stream.StreamSource(xsl));
4. The JSP sets the URI resolver
transformer.setURIResolver(new ServletContextResolver(getServletContext()));
5. The XSL file contains the following xsl:import
<xsl:import href="importedXsl.xsl"/>
<xsl:import href="xsl/importedXsl.xsl"/>
Result...
javax.xml.transform.TransformerException: Had IO Exception with stylesheet
file: importedXsl.xsl
I have tried placing the xsl files in the same directory as the JSP, in the
xsl directory, in the WEB-INF directory, in WEB-INF/xsl. Nothing works. I've
tried xsl:include. I've tried xsl:import.
Somebody must've got Xalan, Tomcat, and xsl:include or xsl:import to work.
Help. Please.
Thanks
Andy
-----Original Message-----
From: Sten Karlson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 04 June, 2002 10:22
To: [EMAIL PROTECTED]
Subject: Re: using xsl:include or xsl:import?
Well in the servlet context the root dir / is one below the /WEB-INF dir.
In that sense you can use the absoult path to find the file. First
however you must
implement the URIResolver that you pass to the transformer. The
URIResolver then uses
the ServletContext to resolve the actual location of the files on your
app. server.
example:
public class ServletContextResolver implements URIResolver {
private transient ServletContext context = null;
public ServletContextResolver(ServletContext context) {
this.context = context;
}
/**
* Reslove location of file
*
* @param href The file where / is the root dir in the servlet
context (eg. /WEB-INF)
* @param base
*/
public Source resolve(String href, String base) throws
TransformerException {
StreamSource source = new
StreamSource(context.getResourceAsStream(href));
return source;
}
}
Sten
Shane Curcuru wrote:
>Acually, I'm pretty sure that's not correct. I'm not a JSP expert, but
>Xalan can happily take either relative or absolute URLs to a stylesheet
>(and can take file: or http: ones), both to start with and for
>include/import (and document()).
>
>Note however that if you use a relative URL, then it has to be relative
>to where the original stylesheet was loaded from - and Xalan has to
>know where that is! MAke sure when you create a transformer from the
>XSL Source object that you call setSystemId() (or that you're using the
>String or File constructor version) and that when you say xsl:import
>the href is relative to where the original stylesheet lives.
>
>The other question is, where does your JSP environment deploy this code
>to. I'm presuming that you can find where it's putting your
>stylesheets and java code, so you can just put the included/imported
>stylesheets in the same place or in a subdirectory thereof.
>
>(This is a common question with server-hosted environments: the whole
>deployment to the live server environment can change pathing, and you
>need to understand how that works).
>
>Note that I would definitely not suggest using absolute URLs when you
>deploy to a live production server unless you're positive they'll
>always work! 8-)
>
>=====
>- Shane
>
><eof aka="mailto:[EMAIL PROTECTED]"
> .sig="Du sublime au ridicule il n'y a qu'un pas." />
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! - Official partner of 2002 FIFA World Cup
>http://fifaworldcup.yahoo.com
>
>