Invoking XSLT from an application

Rather than running XSLT transformations from the command line, you may want to invoke transformations from your own application, perhaps one that runs within a web-based application server. If you use Saxon repeatedly to perform multiple transformations, this will always be much faster than running it each time from a command line, because of the overheads of starting up the Java Virtual Machine.

There are several APIs you can use to invoke Saxon's XSLT processor from an application.

The JAXP interface (Java)

On the Java platform, Saxon incorporates support for the standard JAXP transformation API (originally known as TrAX). This is compatible with the API for invoking other XSLT processors such as Xalan and Oracle.

Although the JAXP interface is convenient, it has several significant drawbacks:

  1. It was defined for XSLT 1.0, and does not directly expose the new features exposed by XSLT 2.0 and 3.0, such as the ability to use a named template as the entry point to a transformation.
  2. The interface is not integrated with other XML capabilities, for example schema processing, making it cumbersome to combine XSLT processing with other tasks.
  3. The mechanism for locating an XSLT processor is slow and unreliable; applications that were tested to work with one XSLT processor can find themselves executing with another, which can cause bugs if the code is not fully portable.
  4. It does not take advantage of facilities introduced to Java and the JDK over the last ten years.
  5. It is biased towards use of DOM as the tree model; while Saxon supports DOM, it is much slower (sometimes by a factor of 10) than other tree models.

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.

For more information on using this API to invoke the Saxon XSLT processor, see Using JAXP for Transformations.

The s9api interface (Java)

An alternative is to use Saxon's own s9api interface. This is designed to provide an integrated approach to XML processing across the different range of languages supported by Saxon; unlike JAXP, it includes support for XSLT 2.0 and 3.0 capabilities, and it also takes advantage of generics, thus giving a more strongly typed and therefore more robust interface.

For more information on using this API to invoke the Saxon XSLT processor, see Using s9api for Transformations.

The Saxon.Api interface (.NET)

There is also an API for Saxon on the .NET platform, designed to make Saxon available from .NET languages such as C#, VB.NET, and ASP.NET. For more information on using this API to invoke the Saxon XSLT processor, see Saxon API for .NET.