Question

I have a compiled stylesheet that was created with this Saxon command:

java net.sf.saxon.Compile [options] stylesheet output [ params…]

I would now like to apply this stylesheet to an XML tree within my Java code. Is it possible to do this using the JAXP API and if so, how exactly? Many thanks in advance for any help on this.

Was it helpful?

Solution

First, please note that this facility doesn't always do what people want. There are many restrictions - things you can do in your stylesheet that prevent it being compilable. And many people have performance expectations that aren't met when they use this feature. In Saxon 9.4, therefore, we withdrew it entirely.

When running a compiled stylesheet, the biggest limitation is that it can't share a Configuration with anything else - it has to run standalone. That's a consequence of the way the NamePool works. So if you try to do this from the Java API, it's your responsibility to get it right.

The key to loading a compiled stylesheet is the static method

PreparedStylesheet.loadCompiledStylesheet()

This can't be done using JAXP interfaces. It returns a PreparedStylesheet object, however, which is Saxon's implementation of the JAXP Templates object, and once you've got this, you can use JAXP interfaces to create a Transformer and run a transformation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top