I’m using the XSLT processor in JDK 1.6 (Xalan) and I make extensive use of the document() function to retrieve data items from documents downloaded from the web. This processing is done as part of the work to render a web page, and it’s currently called each time a page is served. I’m aware of a number of ways to optimize multiple evaluations of the same document() from the same XSLT script, but my concern is rather about reducing the hit on the web; that is, I’d like to cache the external documents to retrieve (also because often I get a timeout when trying to retrieve some of them).
I suppose (hope) Xalan has got a pluggable class for retrieving external document, that I could intercept to inject my caching policy, but I can’t find it in the docs or browsing sources. Can somebody point me whether it exists and how it can be configured? Thanks.
Well, after some tweaking with the debugger and source crawling, I’ve found a pointer in the javadocs, which I didn’t find with Google. The class that does the trick is URIResolver, which can be installed to a Transformer by means of:
There should be some finer processing of href and base, I think in case of relative URLs, but it’s not needed in my case.