Java API For XML Processing - XSLT Interface

XSLT Interface

The XML Stylesheet Language for Transformations, or XSLT, allows for conversion of an XML document into other forms of data. JAXP provides interfaces in package javax.xml.transform allowing applications to invoke an XSLT transformation. This interface was originally called TrAX (Transformation API for XML), and was developed by an informal collaboration between the developers of a number of Java XSLT processors.

Main features of the interface are

  • a factory class allowing the application to select dynamically which XSLT processor it wishes to use (TransformerFactory, TransformerFactory.newInstance, TransformerFactory.newInstance(java.lang.String, java.lang.ClassLoader))
  • methods on the factory class to create a Templates object, representing the compiled form of a stylesheet. This is a thread-safe object that can be used repeatedly, in series or in parallel, to apply the same stylesheet to multiple source documents (or to the same source document with different parameters) (TransformerFactory.newTemplates(javax.xml.transform.Source), also TransformerFactory.newTransformer(javax.xml.transform.Source), TransformerFactory.newTransformer)
  • a method on the Templates object to create a Transformer, representing the executable form of a stylesheet (Templates.newTransformer). This cannot be shared across threads, though it is serially reusable. The Transformer provides methods to set stylesheet parameters and serialization options (for example, whether output should be indented), and a method to actually run the transformation. (Transformer.transform(javax.xml.transform.Source, javax.xml.transform.Result))

Two abstract interfaces Source and Result are defined to represent the input and output of the transformation. This is a somewhat unconventional use of Java interfaces, since there is no expectation that a processor will accept any class that implements the interface - each processor can choose which kinds of Source or Result it is prepared to handle. In practice all JAXP processors support the three standard kinds of Source (DOMSource, SAXSource, StreamSource) and the three standard kinds of Result (DOMResult, SAXResult, StreamResult) and possibly other implementations of their own.

Read more about this topic:  Java API For XML Processing