You know the URL resolver will only cache the XSL files that are included
through xsl:include / import. You are still not caching the main Transformer,
at least not in the code shown below. If you are caching the transformer
in the code below, I am not sure that is thread safe. You should be creating
Templates then asking the Templates to produce a Transformer. There does not
seem to be much overhead for a Template to produce a Transformer.
Also the comment is correct, setting the resolver on the transformer is only
for resolving runtime references such as document(). xsl:include / import
are resolved when the Transformer/Templates is created so the resolver needs to
be set in the factory prior to creating the Transformer/template.
John G
Christopher Ebert wrote:
>
> Try setting the URIResolver on your factory before you generate the
> Transformer.
>
> Chris
>
> -----Original Message-----
> *From:* Robert van Loenhout [mailto:r.vanloenhout@greenvalley.nl]
> *Sent:* Thursday, May 27, 2004 08:26
> *To:* xalan-j-users@xml.apache.org
> *Subject:* URIResolver
>
> Hi!
>
> I am using local xsl files to transform xml documents into html.
> I wanted to cache those xsl files, because they are
> used often in my application and usually stay the same.
> The xsl files also use xsl:import.
>
> I looked in the API documentation and found the setURIResolver
> method for
> TransformerFactory and Transformer classes. So I made my own
> URIResolver and
> used them in the setURIResolver.
>
> URI xsl = new File(xslFile).toURI();
> Transformer transformer = tFactory.newTransformer(new
> StreamSource(xsl.toString()));
> CachingURIResolver resolver = new CachingURIResolver();
> tFactory.setURIResolver(resolver);
> transformer.setURIResolver(resolver);
> ...
> transformer.transform(...
>
> Unfortunately the resolve method of my CachingURIResolver is never
> called!
> The transformation is done normally.
>
> I am using Xerces-j_2_6_2 and Xalan-j_2_6_0.
>
> How can I get this to work correctly? Or is there an easier way to
> accomplish my goals?
>
> Thanks for any help.
> Robert.
>
>
|