The XSLT Packages

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

Java APIs for XML Kick Start
By Aoyon Chowdhury, Parag Choudhary

Table of Contents
Chapter 6.  XSLT and XPath


The XSLT packages are defined in the following sections:

  • javax.xml.transform

  • javax.xml.transform.dom

  • javax.xml.transform.sax

  • javax.xml.transform.stream

The javax.xml.transform Package

The javax.xml.transform package contains the necessary interfaces and classes to create a Transformer object, process transformation instructions, and then transform the XML documents. The interfaces and classes are described in the following sections.

The javax.xml.transform Package Classes

The classes of the javax.xml.transform package enable an application to create the Transformer object and handle exceptions that can be raised while transforming an XML document.

The classes of the javax.xml.transform package are described in the following list:

  • OutputKeys This class provides string constants that can be used to set output properties for a Transformer object. This class can also be used to retrieve output properties from a Transformer or Templates object. For example, the DOCTYPE_SYSTEM key is used to store the system ID of the DTD.

  • Transformer This is an abstract class, which actually transforms a source tree into the result tree. The instance of the Transformer class can process XML from a number of sources and write out the transformation to different types of output sources.

  • TransformerFactory This is an abstract class used to create the Transformer and Template objects. Similar to SAX, the factory implementation that is created depends on the value of the javax.xml.transform.TransformerFactory system property. The default implementation with JAXP is the XALAN XSLT processor.

  • TransformerConfigurationException This is an exception handling class thrown when there is a serious configuration error.

  • TransformerException This is an exception handling class thrown when an exception occurs during the transformation process.

  • TransformerFactoryConfigurationError This is an exception handling class thrown when there is a configuration error with the transformer factory, such as the inability to load the factory class specified in the javax.xml.transform.TransformerFactory system property.

The javax.xml.transform Package Interfaces

The interfaces of the javax.xml.transform package are described in the following list:

  • ErrorListener This interface can be implemented to do customized error handling. This is similar to the customized error handling implemented in the SAX and the DOM chapters.

  • Result An object that implements this interface contains the information needed to build a transformation result tree. For example, when transforming XML to display on the terminal window, the StreamResult class, which implements the Result interface, is used to act as the holder for the transformation result.

  • Source An object that implements this interface contains the information needed to act as input source. The input source could be either an XML source or transformation instructions. For example, the DOMSource class that implements the Source interface can use information in a DOMDocument object to act as a source input.

  • SourceLocator This interface provides the functionality to identify where an error occurred in the XML source or transformation instructions. This is analogous to the Locator object that you used in Chapter 4, "Advanced Use of SAX."

  • Templates An object that implements this interface is the runtime representation of processed transformation instructions.

  • URIResolver This interface declares a method that resolves a URI used in document(), xsl:import(), or xsl:include() functions into a Source object.

The javax.xml.transform.dom Package

The javax.xml.transform.dom package contains two classes that help in using a DOM tree as an input source and as an output of the transformation process. This package also contains an interface that helps in reporting errors while transforming a DOM source to a DOM result.

The classes of the javax.xml.transform.dom package are described in the following list:

  • DOMResult This class implements the Result interface defined in the javax.xml.transform package. This object holds the transformation result tree in the form of a DOM tree.

  • DOMSource This class implements the Source interface defined in the javax.xml.transform package. This object holds the source tree in the form of a DOM tree.

The javax.xml.transform.dom Package Interface

The single interface in the javax.xml.transform.dom package is DOMLocator, which extends the SourceLocator interface defined in the javax.xml.transform package. The methods declared in this interface help an application determine the location where an event occurs. These methods can be used to report errors when transforming an XML source.

The javax.xml.transform.sax Package

The javax.xml.transform.sax package contains three classes that help in using a SAX event generator as an input source, and deliver SAX events as output of the transformation process to a SAX event processor. This package also contains two interfaces that help in parsing transformation instructions into a Templates object, and transform the SAX parse events to a SAXResult object.

The javax.xml.transform.sax Package Classes

The classes in the javax.xml.transform.dom package are described in the following list:

  • SAXResult This class implements the Result interface defined in the javax.xml.transform package. This object holds the transformation result tree.

  • SAXSource This class implements the Source interface defined in the javax.xml.transform package. This object holds the source tree.

  • SAXTransformerFactory This class extends the TransformerFactory to provide SAX-specific factory methods.

The javax.xml.transform.sax Package Interfaces

The interfaces of the javax.xml.transform.sax package are described in the following list:

  • TemplatesHandler This interface extends the ContentHandler interface and provides the methods with which SAX parse events can be processed into a Templates object.

  • TransformerHandler This interface listens for SAX events and transforms them to a SAXResult object.

The javax.xml.transform.stream Package

The javax.xml.transform.stream package has two classes that provide the stream and URI-specific transformation APIs.

The javax.xml.transform.stream Package Classes

The classes of the javax.xml.transform.stream package are described in the following list:

  • StreamResult This class implements the Result interface, and acts as a holder for the transformation result. This is used when the transformation output needs to be delivered in a stream, such as when outputting the transformed document to the terminal window.

  • StreamSource This class implements the Source interface and acts as a holder of the transformation source. The transformation source will be in the form of a stream of XML markup.

Now you'll learn how to use the XSLT with DOM.


printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
Top

[0672324342/ch06lev1sec2]

 
 


JavaT APIs for XML Kick Start
JAX: Java APIs for XML Kick Start
ISBN: 0672324342
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net