BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
692 stars 265 forks source link

Support XML Catalog Files in xsl:import in fn:transform() #1719

Closed liamquin closed 5 years ago

liamquin commented 5 years ago

It turns out that the patch for issue #1405 hsa a rather obscure but very important problem - it doesn't work for xsl:import.

This turns out to be because Saxon (and possibly other XSLT implementations) only use the XML Catalog URI resolver for xsl:import when stylesheets are first compiled and then executed.

I hacked XsltTransform.java Transformer.transformer() to look like this, Transformer tr = null; TransformerFactory tf = TransformerFactory.newInstance(); if(cw != null) tf.setURIResolver(cw.getURIResolver()); Templates compiled = tf.newTemplates(ss); return compiled.newTransformer();

This works wonderfully EXCEPT that there's no longer a transformer cache. To keep a cache, we'd either need to make sure the XSLT stylesheet was the same each time or to save just the result of TransformerFactory.newInstance(); is that worth it?

I didn't append a patch because of that question. It would also be possible to add a "basex:compile-stylesheet" boolean option to xslt:transform() to control the behaviour - being as BaseX is a database server i'm concerned about performance, but the performane characteristics will probably depend on the size and complexity of the stylesheet, and how much of it is used.

What do you think?

gimsieke commented 5 years ago

Thanks for investigating, Liam! Our usage scenarios often involve applying the same XSLT stylesheet to thousands of documents. Of course performance is always an issue. Therefore we’d like to see an option by which we can control the caching of compiled stylesheets that are also able to use the catalog for imports. Or rather, we actually don’t want to control the caching, we’d like to have it by default.

Let’s wait for Christian’s thoughts; I think he’s currently on a well-deserved vacation.

ChristianGruen commented 5 years ago

Thanks both for your feedback!

Based on Liam’s suggestions, I have committed a new version that:

Could you please try the new snapshot for me? I’d particularly be interested if we lose speed by caching the Templates (which are used in the next step to create Transformer instances).

ChristianGruen commented 5 years ago

Hi Liam, hi Gerrit, I hope the updated version matches your requirements. I’ll close this issue; feel free to reopen it.

gimsieke commented 5 years ago

Hi Christian, I was just about to test it. I can confirm that it works, specifying for example declare option db:catfile "path/relative/to/cwd/catalog.xml";. Thank you both!

ChristianGruen commented 5 years ago

Great news, thanks Gerrit!

liamquin commented 5 years ago

On Mon, 2019-09-23 at 11:14 -0700, Gerrit Imsieke wrote:

Hi Christian, I was just about to test it. I can confirm that it works, specifying for example declare option db:catfile "path/relative/to/cwd/catalog.xml";. Thank you both!

That's great!

Thanks

-- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org