Project

Profile

Help

Missing method PreparedStylesheet.loadCompiledStylesheet

Added by Yevgeniy Yanavichus over 3 years ago

I realized now that method PreparedStylesheet.loadCompiledStylesheet is no longer available in API: https://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/PreparedStylesheet.html

While it was available in v9: https://www.saxonica.com/documentation9.0/javadoc/net/sf/saxon/PreparedStylesheet.html

What's a recommended way to load precompiled stylesheets now?

Thanks, Yevgeniy


Replies (7)

Please register to reply

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Michael Kay over 3 years ago

9.0 was a very long time ago! (November 2007 to be precise)

In those days a "compiled stylesheet held in a file" meant a Java serialization of the PreparedStylesheet object. We dropped the use of Java object serialization many releases ago, partly because it didn't perform very well, partly because there were too many restrictions - some of the JDK classes that we depend on, notably collations, aren't serializable. I don't remember the exact timeline, but the equivalent functionality in recent Saxon releases is delivered by generating a SEF file. SEF files can be loaded simply by supplying a Source object that refers to a SEF file to any interface that accepts a source stylesheet.

I would recommend trying to stick to using s9api interfaces, which are very stable from one release to the next. The s9api interface was introduced in 9.1. Before then there wasn't always a very clear distinction between interfaces that were part of Saxon's stable public API, and interfaces that were primarily for internal use.

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Michael Kay over 3 years ago

In fact, the method you ask about was last present in Saxon 9.1, it was dropped in 9.2 which was released in June 2009.

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Yevgeniy Yanavichus over 3 years ago

Well, actually I'm trying to load SEF file. I got an exception saying "javax.xml.transform.TransformerConfigurationException: The input document is not a stylesheet (the XSL namespace is not declared in the root element". This is why I started looking for other methods. This is my code:

final Resource fileResource = resourceLoader.getResource("classpath:static/transform.sef");

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(new StreamSource(fileResource.getInputStream()));

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Yevgeniy Yanavichus over 3 years ago

I tried to move to s9api and got some more issues. When trying to load SEF file into XsltExecutable using methods compiler.loadExecutablePackage and compiler.compile (I understand that we shouldn't compile already compiled stylesheet, just tried this case as well) I'm getting error saying:

"nested exception is net.sf.saxon.s9api.SaxonApiException: Unknown simple type NE"

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Michael Kay over 3 years ago

As regards the error "The input document is not a stylesheet (the XSL namespace is not declared in the root element"., check that the TransformerFactory you have loaded is actually a Saxon TransformerFactory. (This doesn't seem like a Saxon error message, unless it's an old release).

As regards the s9api error, please (a) check which versions of Saxon were used to generate the SEF file and then to reload it, and (b) supply full details that we can reproduce. The full stack trace would be useful as well.

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Yevgeniy Yanavichus over 3 years ago

Thanks, after using same version (latest v9) both for generating SEF and code itself it became working. One more question, if you don't mind of course:

What's a recommended (fastest) way to return result XML in response body? So far I'm using RawDestination and it's method getXdmValue() and then toString(). Is it good enough or maybe toString() is not recommended and better use Serializer as a destination? I'm asking because right now I'm sharing XsltExecutable as a bean and if I have to use Serializer I'll have to share it as well since it's have to be constructed using Processor. I'm ok with sharing it (in your samples in method TransformC you wrote that it's ok and thread-safe), just want to have a fastest implementation

RE: Missing method PreparedStylesheet.loadCompiledStylesheet - Added by Michael Kay over 3 years ago

It's better to send the output to a Serializer. That way, any xsl:output statements in the stylesheet take effect, and it's also faster because the result tree doesn't have to be constructed in memory.

    (1-7/7)

    Please register to reply