Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
These constants are useful when you call methods such as
getOutputProperty()
and
setOutputProperty()
on the
Transformer
object.
javax.xml.transform.Result
Result
is an interface; it exists as an abstraction of the three classes
SAXResult
,
DOMResult
, and
StreamResult
, which are different ways of representing an XML output destination. This allows any of these different kinds of destination to be supplied as the second argument to the
Transformer.transform()
method. Implementations can also define other kinds of
Result
objects if they wish.
This class defines the two static constants
PI_DISABLE_OUTPUT_ESCAPING
and
PI_ENABLE OUTPUT_ESCAPING
which are the names of the processing instructions generated as a result of setting
disable-output-escaping=“yes”
on the
xsl:value-of
instruction in the stylesheet.
The interface defines two methods, allowing any of the different types of
Result
to have a system identifier (or base URI):
Method | Description |
String getSystemId() | Gets the system identifier |
void setSystemId() | Sets the system identifier |
javax.xml.transform.sax.SAXResult
Specifying a
SAXResult
as the output of the transformation causes the result tree produced by the transformation to be fed to a user-supplied SAX2
ContentHandler
as a sequence of SAX events, just as if the events came from an XML parser. The
SAXResult
object holds a reference to this
ContentHandler
, and also to a
String
containing a system identifier. (This system identifier might be made available to the
ContentHandler
code as part of the
Locator
object, though the specification doesn't make it clear that this is what should happen.)
Many XSLT processors will support SAX output, but it is not mandatory. If the processor does support it, then calling
getFeature(SAXResult.FEATURE)
on the
TransformerFactory
will return
true
.
There are several potential difficulties with supplying XSLT output to a
ContentHandler
:
The class has two constructors:
SAXResult()
SAXResult(org.xml.sax.ContentHandler)
and the following methods:
Method | Description |
org.xml.sax.ContentHandler getHandler() | Gets the ContentHandler |
org.xml.sax.ext.LexicalHandler getLexicalHandler() | Gets the LexicalHandler |
String getSystemId() | Gets the system identifier (base URI) |
void setHandler (org.xml.sax.ContentHandler) | Sets the ContentHandler that is to receive events representing the result tree |
void setHandler (org.xml.sax.ext.LexicalHandler) | Sets the LexicalHandler that is to receive lexical events (notably, comments) representing the result tree |
void setSystemId() | Sets the system identifier (base URI) |
javax.xml.transform.sax.SAXSource
A
SAXSource
is a
Source
, so it is one of the possible inputs you can supply to the
Transformer.transform()
method (when it represents a source XML document) or to the
TransformerFactory.newTemplates()
method (when it represents a stylesheet).
Essentially, a
SAXSource
is the combination of a SAX parser (
XMLReader
) and a SAX
InputSource
, which can be a URI, a binary input stream, or a character input stream. A
SAXSource
delivers the source document in the form of a stream of SAX events. Usually it will achieve this by parsing XML held in a file or somewhere in memory, but by defining your own implementations of
XMLReader
and/or
InputSource
, you can supply the SAX events from anywhere; for example, you can generate them as the result of an SQL query or an LDAP directory search, or you could use an
XMLFilter
that modifies the events coming through from a real XML parser before passing them on to the transformation.
If no
XMLReader
is supplied, the system will use a default one. It may do this using the rules for the
javax.xml.parsers.SAXParserFactory
class described earlier in this appendix, but this is not guaranteed.
Not every XSLT processor will support SAX input. If the processor does so, then calling
getFeature(SAXSource.FEATURE)
on the
TransformerFactory
will return
true
.
There are three constructors:
SAXSource()
SAXSource(InputSource)
SAXSource(XMLReader, InputSource)
plus the following methods:
Method | Description |
InputSource getInputSource() | Gets the SAX InputSource . |
String getSystemId() | Gets the System Identifier used for resolving relative URIs. |
XMLReader getXMLReader() | Gets the XMLReader (the parser) if one has been set. |
void setInputSource( org.xml.sax.InputSource) | Sets the SAX InputSource . |
void setSystemId(String) | Sets a System Identifier that can be used to resolve relative URIs. |
void setXMLReader(XMLReader) | Sets the XMLReader (the parser) to be used. |
static org.xml.sax.InputSource sourceToInputSource(Source source) | This static method attempts to construct a SAX InputSource from any kind of Source object. It will return null if this isn't possible. |
javax.xml.transform.sax.SAXTransformerFactory
This class is a subclass of
TransformerFactory
that provides three additional facilities:
These facilities were made optional because it was assumed that not every JAXP processor will support them; in practice, all mainstream implementations do.
If a
SAXTransformerFactory
is available at all, then it will always be produced as a result of calling
TransformerFactory.newInstance()
.
The class has the following methods, in addition to those of
TransformerFactory
:
Method | Description |
TemplatesHandler newTemplatesHandler() | Creates and returns a TemplatesHandler . The TemplatesHandler can be supplied with a stream of SAX events representing the contents of a stylesheet. |
TransformerHandler newTransformerHandler() | Creates and returns a TransformerHandler . The TransformerHandler will perform an identity transformation on the XML source document that is supplied to it in the form of a stream of SAX events. |
TransformerHandler newTransformerHandler(Source) | Creates and returns a TransformerHandler . The Source identifies a document containing a stylesheet. The TransformerHandler will perform the transformation defined by this stylesheet, on the XML source document that is supplied to it in the form of a stream of SAX events. |
TransformerHandler newTransformerHandler(Templates) | Creates and returns a TransformerHandler . The Templates argument identifies a compiled stylesheet. The TransformerHandler will perform the transformation defined by this stylesheet, on the XML source document that is supplied to it in the form of a stream of SAX events. |
org.sax.xml.XMLFilter newXMLFilter(Source) | Creates and returns an XMLFilter . The Source identifies a document containing a stylesheet. The resulting XMLFilter will perform the transformation defined by this stylesheet. |
org.sax.xml.XMLFilter newXMLFilter(Templates) | Creates and returns an XMLFilter . The Templates argument identifies a compiled stylesheet. The resulting XMLFilter will perform the transformation defined by this stylesheet. |