Using JAXP for Transformations

This API is described in the documentation provided with JDK 1.5 and later. It is available online at http://download.oracle.com/javase/6/docs/api/ Look for the javax.xml.transform package.

More information and examples relating to the JAXP transformation API can be found in the TraxExamples.java example application found in the samples directory.

The class name for the JAXP TransformerFactory depends on which Saxon edition you are using:

Note that as an alternative to using TransformerFactory.newInstance() to find Saxon dynamically on the class path, it is possible (and much faster, and more robust) to instantiate the Saxon TransformerFactory directly, by a call such as TransformerFactory factory = new com.saxonica.config.ProfessionalTransformerFactory()

The types of object that can be supplied as stylesheet parameters are not defined in the JAXP specification: they are implementation-dependent. Saxon takes the Java object supplied, and converts it to an XPath value using the same rules as it applies for the return value from a Java extension function: for these rules, see Saxon Extensibility. If the resulting value is an atomic value, it is cast to the required type of the parameter as specified in the xsl:param declaration, using the XPath casting rules. If the value is non-atomic (for example, if it is a node, or a sequence of integers), then no conversion is attempted, instead, the value must match the required type as stated.

The JAXP TransformerFactory interface provides a configuration method setAttribute() for setting implementation-defined configuration parameters. The parameters supported by Saxon have names defined by constants in the class net.sf.saxon.FeatureKeys. The names of these properties and their meanings, are described in .

Where the required value of a property is a Boolean, the supplied value may be either a java.lang.Boolean, or a String holding the values "true" or "false" (also accepted are "on"|"off", "1"|"0", or "yes"|"no"). The returned value of the property, however, will be a Boolean.

Saxon's implementation of the JAXP Transformer interface is the class net.sf.saxon.Controller. This provides a number of options beyond those available in the standard JAXP interface, for example the ability to set an output URI resolver for secondary output documents, and a method to set the initial mode before the transformation starts. You can access these methods by casting the Transformer to a Controller. The methods are described in the JavaDoc documentation supplied with the product.

When using the JAXP interface, you can set serialization properties using a java.util.Properties object. The names of the core XSLT 1.0 properties, such as method, encoding, and indent, are defined in the JAXP class javax.xml.transform.OutputKeys. Additional properties, including Saxon extensions and XSLT 2.0 extensions, have names defined by constants in the class net.sf.saxon.lib.SaxonOutputKeys. The values of the properties are exactly as you would specify them in the xsl:output declaration, except that QNames are written in Clark notation ({uri}local).