xsltcachingxsl-fojaxp

XSL caching in java - dependent xsl files


I am using the following code to cache the xsl (same across all requests) so that the file is not read from the disk every single time.

My question is if the xsl refers to 100 other xsl files(<xsl:include href="file1"/>), will they be loaded into the cache as well? will they still be read from the disk?

if not, How do we make all dependent xsls to be read into memory and cached?

private static Templates cachedXslt = null;
// Transformer
        if(cachedXslt == null)
        {
            Source xsltSrc = new StreamSource(xslPath);

            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            cachedXslt = transformerFactory.newTemplates(xsltSrc);
        }

    Transformer transformer = cachedXslt.newTransformer();

Solution

  • Yes, the Templates object will contain some kind of internal/compiled in-memory representation of the entire stylesheet (that is, all modules of the stylesheet). Though exactly what happens depends of course on the implementation (JAXP is an interface and JAXP implementations can implement it in different ways.)