net.sf.saxon.s9api
public class XsltTransformer extends Object implements Destination
XsltTransformer
represents a compiled and loaded stylesheet ready for execution.
The XsltTransformer
holds details of the dynamic evaluation context for the stylesheet.
An XsltTransformer
must not be used concurrently in multiple threads.
It is safe, however, to reuse the object within a single thread to run the same
stylesheet several times. Running the stylesheet does not change the context
that has been established.
An XsltTransformer
is always constructed by running the Load
method of an XsltExecutable.
An XsltTransformer
is itself a Destination
. This means it is possible to use
one XsltTransformer
as the destination to receive the results of another transformation,
this providing a simple way for transformations to be chained into a pipeline.
Since: 9.0
Constructor Summary | |
---|---|
protected | XsltTransformer(Processor processor, Controller controller)
Protected constructor |
Method Summary | |
---|---|
String | getBaseOutputURI()
Get the base output URI.
|
Destination | getDestination()
Get the destination that was specified in a previous call of |
ErrorListener | getErrorListener()
Get the ErrorListener being used during this compilation episode |
XdmNode | getInitialContextNode()
Get the initial context node for the transformation, if one has been set |
QName | getInitialMode()
Get the initial mode for the transformation, if one has been set. |
QName | getInitialTemplate()
Get the initial named template for the transformation, if one has been set |
MessageListener | getMessageListener()
Get the MessageListener to be notified whenever the stylesheet evaluates an
xsl:message instruction. |
XdmValue | getParameter(QName name)
Get the value that has been set for a stylesheet parameter |
Receiver | getReceiver(Configuration config)
Return a Receiver which can be used to supply the principal source document for the transformation.
|
ValidationMode | getSchemaValidationMode()
Get the schema validation mode for the transformation. |
TraceListener | getTraceListener()
Get the TraceListener to be notified of all events occurring during the transformation.
|
Controller | getUnderlyingController()
Get the underlying Controller used to implement this XsltTransformer. |
void | setBaseOutputURI(String uri)
Set the base output URI.
|
void | setDestination(Destination destination)
Set the destination to be used for the transformation.
|
void | setErrorListener(ErrorListener listener)
Set the ErrorListener to be used during this transformation |
void | setInitialContextNode(XdmNode node)
Set the initial context node for the transformation.
|
void | setInitialMode(QName modeName)
Set the initial mode for the transformation |
void | setInitialTemplate(QName templateName)
Set the initial named template for the transformation |
void | setMessageListener(MessageListener listener)
Set the MessageListener to be notified whenever the stylesheet evaluates an
xsl:message instruction. |
void | setParameter(QName name, XdmValue value)
Set the value of a stylesheet parameter |
void | setSchemaValidationMode(ValidationMode mode)
Set the schema validation mode for the transformation. |
void | setSource(Source source)
Set the source document for the transformation.
|
void | setTraceListener(TraceListener listener)
Set a TraceListener to be notified of all events occurring during the transformation.
|
void | transform()
Perform the transformation. |
Parameters: processor the S9API processor controller the Saxon controller object
This returns the value set using the XsltTransformer method. If no value has been set explicitly, then the method returns null if called before the transformation, or the computed default base output URI if called after the transformation.
The base output URI is used for resolving relative URIs in the href
attribute
of the xsl:result-document
instruction.
Returns: the base output URI
Since: 9.2
Returns: the destination, or null if none has been supplied
Returns: listener The error listener in use. This is notified of all dynamic errors detected during the transformation. If no user-supplied ErrorListener has been set the method will return a system-supplied ErrorListener.
Since: 9.2
Returns: the initial context node, or null if none has been set. This will not necessarily be the same XdmNode instance as was supplied, but it will be an XdmNode object that represents the same underlying node.
Returns: the initial mode for the transformation. Returns null if no mode has been set, or if the mode was set to null to represent the default (unnamed) mode
Returns: the name of the initial template, or null if none has been set
xsl:message
instruction. If no MessageListener has been nominated,
return nullReturns: the user-supplied MessageListener, or null if none has been supplied
Since: 9.1
Parameters: name the parameter whose name is required
Returns: the value that has been set for the parameter, or null if no value has been set
Saxon calls this method to obtain a Receiver, to which it then sends
a sequence of events representing the content of an XML document. This method is provided so that
XsltTransformer
implements Destination
, allowing one transformation
to receive the results of another in a pipeline.
Before calling this method, the XsltTransformer method must be called to supply a destination for the transformation.
Note that when an XsltTransformer
is used as a Destination
, the initial
context node set on that XsltTransformer
is ignored.
Parameters: config The Saxon configuration. This is supplied so that the destination can use information from the configuration (for example, a reference to the name pool) to construct or configure the returned Receiver.
Returns: the Receiver to which events are to be sent.
Throws: SaxonApiException if the Receiver cannot be created IllegalStateException if no Destination has been supplied
doc()
, document()
,
or collection()
functions.Returns: the validation mode.
Returns: the user-supplied TraceListener, or null if none has been supplied
Since: 9.2
Since: 9.0.0.4
This defaults to the system ID of the Destination for the principal output of the transformation if this is known; if it is not known, it defaults to the current directory.
The base output URI is used for resolving relative URIs in the href
attribute
of the xsl:result-document
instruction.
Parameters: uri the base output URI
Since: 9.2
This method can be used to chain transformations into a pipeline, by using one XsltTransformer as the destination of another
Parameters: destination the destination to be used
Parameters: listener The error listener to be used. This is notified of all dynamic errors detected during the transformation.
Since: 9.2
This is ignored in the case where the XsltTransformer is used as the Destination of another process. In that case the initial context node will always be the document node of the document that is being streamed to this destination.
Parameters: node the initial context node, or null if there is to be no initial context node
Parameters: modeName the name of the initial mode, or null to indicate the default (unnamed) mode
Parameters: templateName the name of the initial template, or null to indicate that there should be no initial named template
Throws: SaxonApiException if there is no named template with this name
xsl:message
instruction. If no MessageListener is nominated,
the output of xsl:message
instructions will be serialized and sent
to the standard error stream.Parameters: listener the MessageListener to be used
Since: 9.1
Parameters: name the name of the stylesheet parameter, as a QName value the value of the stylesheet parameter, or null to clear a previously set value
doc()
, document()
,
or collection()
functions.Parameters: mode the validation mode. Passing null causes no change to the existing value.
Passing Validation.DEFAULT
resets to the initial value, which determines
the validation requirements from the Saxon Configuration.
If the source is an instance of NodeInfo, the supplied node is used directly as the context node of the query.
If the source is an instance of javax.xml.transform.dom.DOMSource, the DOM node identified by the DOMSource is wrapped as a Saxon node, and this is then used as the context item
In all other cases a new Saxon tree is built, by calling build, and the document node of this tree is then used as the context item for the query.
Parameters: source the principal source document for the transformation
Parameters: listener the TraceListener to be used. Note that the TraceListener has access to interal Saxon interfaces which may vary from one release to the next. It is also possible that the TraceListener interface itself may be changed in future releases.
Since: 9.2
Throws: SaxonApiException if any dynamic error occurs during the transformation IllegalStateException if no destination has been supplied