Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
liamquin opened this issue Aug 30, 2019 · 6 comments
Closed

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

liamquin opened this issue Aug 30, 2019 · 6 comments

Comments

@liamquin
Copy link

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
Copy link
Contributor

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
Copy link
Member

ChristianGruen commented Sep 17, 2019

Thanks both for your feedback!

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

  • caches Templates instead of Transformer objects (I assume this is cleaner anyway);
  • assigns the catalog URI resolver to both the Templates and the Transformer object (as it seems that each XSLT implementation seems to consider the resolver at a different stage).

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
Copy link
Member

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

@gimsieke
Copy link
Contributor

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
Copy link
Member

Great news, thanks Gerrit!

@liamquin
Copy link
Author

liamquin commented Sep 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants