Project

Profile

Help

document() function and caching

Added by Anonymous over 19 years ago

Legacy ID: #2975619 Legacy Poster: Konstantyn Smirnov (injecteer)

hi I'm using the following xsl code: ....... <xsl:variable name="actions"> <xsl:copy-of select="document('../xml/default/actions.xml')/actions/button"/> </xsl:variable> ....... then I store pre-compiled stylesheets in a static Hashtable: private static Hashtable ahtTemplates = new Hashtable(); protected static Templates getXSLTemplate( String pstrXSLPath ) { Templates templates = (Templates)ahtTemplates.get( pstrXSLPath ); if( null == templates ){ templates = atFactory.newTemplates( new StreamSource( pstrXSLPath ) ); ahtTemplates.put( pstrXSLPath, templates ); } return templates; } considering that, the question is: Is the $actions xsl:variable being rebuilt every time, when I call this template, or is it compiled once with "inline-included" xml document?


Replies (2)

RE: document() function and caching - Added by Anonymous over 19 years ago

Legacy ID: #2975631 Legacy Poster: Michael Kay (mhkay)

It's rebuilt every time. You could save yourself the cost of copying the document by writing the variable as: <xsl:variable name="actions" select="document('../xml/default/actions.xml')/actions/button"/> but it would still fetch and parse the document each time. This is by design: the URL might be an http: request to a service that provides changing information. You're better off building the document in your calling code and passing it to the stylesheet as a parameter. Michael Kay

RE: document() function and caching - Added by Anonymous over 19 years ago

Legacy ID: #2975750 Legacy Poster: Konstantyn Smirnov (injecteer)

ok, thanks! >> You're better off building the document in your calling code and passing it to the stylesheet as a parameter. You mean something like: transformer.setParameter( Name, external_document.toString() ); ? some extra questons are the xsl:include-d stylesheets processed only once while pre-compiling? how can I achive "inline-inclusion" of some external xml code into the xsl-template, which is then pre-comiled?

    (1-2/2)

    Please register to reply