How to break caching on exist-db of included XSLs in Transform

284 views Asked by At

I have a large set of XSLs that we recently went through and implemented a shared XSL template with common bits. We included an xsl:include in all the main XSLs now to pull these in. We had no issues at first until we started to make changes to the shared XSL.

For information, the whole system is web based, calling queries to dynamically format documents in the database given different XSLs through XSL FO and RenderX.

The main transform is:

let $fo := util:expand(transform:transform($articles, doc("/db/Customer/data/edit/xsl/Custbatch.xsl"), $parameters))

That XSL (Custbatch.xsl) has:

<xsl:include href="Custshared.v1.xsl"/>

If we make an edit to "Custshared.v1.xsl" is not reflected in the result because it is obvious that "Custshared.v1.xsl" is being cached and used. We know this because as you can see the name now includes "v1". If we make a change and change all the references say from v1 to v2, it all works. But this seems a bit ridiculous as that means we have to change the 18 XSLs that include this XSL or do something silly like restart the database.

So, what am I missing in the setup or controller.xql (which has the following on all not matched paths), to get things not to cache. I assume that is all internal so this setting likely does not matter. Is there some other setting in the config that does?

<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
    <cache-control cache="no"/>
</dispatch>

In reading the document here: http://exist-db.org/exist/apps/doc/xsl-transform.xml, it states:

"The stylesheet will be compiled into a template using the standard Java APIs (javax.xml.transform). The template is shared between all instances of the function and will only be reloaded if modified since its last invocation."

However, if I change an included XSL, it is not being used.

Update #1

I even went as far as creating a query that returns the XSL that is included, then I use:

<xsl:include href="http://localhost/get-include-xsl.xq"/>

This does work as formatting is not broken, but changing the underlying XSL yields the same result. So even that Xquery result is cached.

Update #2

And yes, through some simple test all is proven. If I make any change to the root template (like add a meaningless space) and run, it does include the changes made in the include. If I only change the included XSL, no changes happen.

So lacking anything else, we could always write a Xquery that basically touches all the main templates after a change is made to the include template. Seems so wrong as a workaround.

Update #3

So the workaround we are currently using is that we have an unused "variable" in the XSL (version) and when we update the shared template, we execute that query which basically updates the value in that variable. At least it's only one XQuery and maybe we should attach to a trigger.

1

There are 1 answers

0
pstadler On

There is a setting in $exist-db-root$/conf.xml for the XSL transformer where you can turn off caching: <transformer class="net.sf.saxon.TransformerFactoryImpl" caching="no"> (The default is 'yes')