Using s9api for Transformations

You can perform a transformation using the s9api interface as follows:

  1. Create a Processor (net.sf.saxon.s9api.Processor) and set any global configuration options on the Processor.

  2. Call newXsltCompiler() to create an XSLT Compiler, and set any options that are local to a specific compilation (for example, the destination of error messages).

  3. Call the compile() method to compile a stylesheet. The result is an XsltExecutable, which can be used as often as you like in the same thread or in different threads.

  4. To run a transformation, call the load() method on the XsltExecutable. This creates an XsltTransformer. The XsltTransformer can be serially reused, but it must not be shared across multiple threads. Set any options required for the specific transformation (for example, the initial context node, the stylesheet parameters, and the destination for the results of the transformation), and then call the transform() method to run the transformation.

The output of the transformation is specified as a Destination object, which allows a wide range of possibilities: you can send the output to a serializer, or to a SAX ContentHandler. You can build a tree either in Saxon's native format (represented by the s9api class XdmNode) or as a DOM. You can send the output to be validated against a schema by nominating a SchemaValidator as the destination, or you can pipe it through another transformation, because XsltTransformer itself implements the Destination interface.

Examples of s9api transformations are included in the Saxon resources file, see module