<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="using-xsl" page="embedding" subpage="s9api-transformation"/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Using s9api for Transformations</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: Using s9api for Transformations"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>Using s9api for Transformations</h1> <p>You can perform a transformation using the s9api interface as follows:</p> <ol> <li content="para"> <p>Create a Processor (<code>net.sf.saxon.s9api.Processor</code>) and set any global configuration options on the Processor.</p> </li> <li content="para"> <p>Call <code>newXsltCompiler()</code> to create an XSLT Compiler, and set any options that are local to a specific compilation (for example, the destination of error messages).</p> </li> <li content="para"> <p>Call the <code>compile()</code> method to compile a stylesheet. The result is an <code>XsltExecutable</code>, which can be used as often as you like in the same thread or in different threads.</p> </li> <li content="para"> <p>To run a transformation, call the <code>load()</code> method on the <code>XsltExecutable</code>. This creates an <code>XsltTransformer</code>. The <code>XsltTransformer</code> 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 <code>transform()</code> method to run the transformation.</p> </li> </ol> <p>The output of the transformation is specified as a <code>Destination</code> 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 <code>XdmNode</code>) or as a DOM. You can send the output to be validated against a schema by nominating a <code>SchemaValidator</code> as the destination, or you can pipe it through another transformation, because <code>XsltTransformer</code> itself implements the <code>Destination</code> interface.</p> <p>Examples of s9api transformations are included in the Saxon resources file, see module <b>S9APIExamples.java</b>.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="jaxp-transformation.xml">Next</a></p> </td> </tr> </table> </body> </html>