Chapter 3. Processing XML 57
3.2 Xalan
Xalan is an XSLT processor for transforming XML documents into HTML, text, or
other XML document types. It implements the W3C Recommendations for XSL
Transformations (XSLT) and the XML Path Language (XPath). It provides a
standard API for performing XML Transformations. It builds on SAX2, DOM
Level2, and the XML parser API in Java API for XML Parsing 1.0 (JAXP). It may
be configured to work with any XML parser, such as Xerces, that implements
JAXP. It can process Stream, SAX or DOM input, and output to a Stream, SAX or
DOM.
The diagram in Figure 3-1 shows a high level model of operation. A
transformation expressed in XSLT describes the rules for transforming a source
tree into a result tree. A term tree represents the structure of an XML document,
whether it is a DOM tree, or a series of parse events coming from a SAX2
ContentHandler. The transformation is achieved by associating patterns with
templates. A pattern is matched against elements in the source tree. A template
is instantiated to create part of the result tree. The result tree is separate from the
source tree. The structure of the result tree can be completely different from the
structure of the source tree. In constructing the result tree, elements from the
source tree can be filtered and reordered.
Figure 3-1 Xalan model of operation
The primary interface for Xalan for external usage is javax.xml.transform. These
interfaces define a standard and powerful interface to perform tree-based
transformations. These interfaces have no dependencies on SAX or the DOM
standard as shown in Figure 3-2. It achieves this by defining source and result
interfaces, which a user can use to define instances of whatever input and output
desired, whether SAX, DOM, or stream.
Source
XML Result
XML
XSL
Style
Sheet
XSLT
Engine