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. Note however that a
when the input to a transformation is supplied in this way, it will always be built as a tree in
memory, rather than the transformation being streamed.
Modifier | Constructor and Description |
---|---|
protected |
XsltTransformer(Processor processor,
Controller controller,
GlobalParameterSet staticParameters)
Protected constructor
|
Modifier and Type | Method and Description |
---|---|
void |
clearParameters()
Clear the values of all parameters that have been set
|
void |
close()
Close this destination, allowing resources to be released.
|
String |
getBaseOutputURI()
Get the base output URI.
|
Destination |
getDestination()
Get the destination that was specified in a previous call of
setDestination(net.sf.saxon.s9api.Destination) |
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 name of 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.
|
Logger |
getTraceFunctionDestination()
Get the destination for output from the fn:trace() function.
|
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.
|
URIResolver |
getURIResolver()
Get the URI resolver.
|
void |
setBaseOutputURI(String uri)
Set the base output URI.
|
void |
setDestination(Destination destination)
Set the destination to be used for the result of 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 |
setTraceFunctionDestination(Logger stream)
Set the destination for output from the fn:trace() function.
|
void |
setTraceListener(TraceListener listener)
Set a TraceListener to be notified of all events occurring during the transformation.
|
void |
setURIResolver(URIResolver resolver)
Set an object that will be used to resolve URIs used in
fn:doc() and related functions.
|
void |
transform()
Perform the transformation.
|
protected XsltTransformer(Processor processor, Controller controller, GlobalParameterSet staticParameters)
processor
- the S9API processorcontroller
- the Saxon controller objectstaticParameters
- the static parameters supplied at stylesheet compile timepublic void setInitialTemplate(QName templateName) throws SaxonApiException
templateName
- the name of the initial template, or null to indicate
that there should be no initial named templateSaxonApiException
- if there is no named template with this namepublic QName getInitialTemplate()
public void setInitialMode(QName modeName) throws IllegalArgumentException
modeName
- the name of the initial mode, or null to indicate the default
(unnamed) modeIllegalArgumentException
- if the requested mode is not defined in the stylesheetpublic QName getInitialMode()
public void setSchemaValidationMode(ValidationMode mode)
doc()
, document()
,
or collection()
functions.mode
- the validation mode. Passing null causes no change to the existing value.
Passing ValidationMode.DEFAULT
resets to the initial value, which determines
the validation requirements from the Saxon Configuration.public ValidationMode getSchemaValidationMode()
doc()
, document()
,
or collection()
functions.public void setSource(Source source) throws SaxonApiException
If the source is an instance of NodeInfo
, the supplied node is used
directly as the initial context item of the transformation.
If the source is an instance of DOMSource
, the DOM node identified
by the DOMSource is wrapped as a Saxon node, and this is then used as the context item
In other cases a new Saxon tree will be built by the transformation engine when the transformation starts, unless it is a Saxon-EE streaming transformation, in which case the document is processed in streaming fashion as it is being parsed.
To run a transformation in streaming mode, the source should be supplied as an instance
of StreamSource
, SAXSource
,
or Transmitter
.
source
- the principal source document for the transformationSaxonApiException
- if for example the Source is an unrecognized type of sourcepublic void setInitialContextNode(XdmNode node)
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.
Calling this method has the side-effect of setting the initial source to null.
node
- the initial context node, or null if there is to be no initial context nodepublic XdmNode getInitialContextNode()
XdmNode
instance as was supplied, but it will be an XdmNode object that represents
the same underlying node.public void setParameter(QName name, XdmValue value)
name
- the name of the stylesheet parameter, as a QNamevalue
- the value of the stylesheet parameter, or null to clear a previously set valuepublic void clearParameters()
public XdmValue getParameter(QName name)
name
- the parameter whose name is requiredpublic void setDestination(Destination destination)
This method can be used to chain transformations into a pipeline, by using one
XsltTransformer
as the destination of another
If the destination is a Serializer
, then this call has two side-effects:
href
attribute of any xsl:result-document
instruction.Serializer
override any
serialization parameters defined using xsl:output
for the principal
output of the transformation. However, they have no effect on any output produced
using xsl:result-document
.destination
- the destination to be usedpublic Destination getDestination()
setDestination(net.sf.saxon.s9api.Destination)
public void setBaseOutputURI(String uri)
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.
If no base output URI is supplied, but the Destination
of the transformation
is a Serializer
that writes to a file, then the URI of this file is used as
the base output URI.
The base output URI is used for resolving relative URIs in the href
attribute
of the xsl:result-document
instruction.
uri
- the base output URIpublic String getBaseOutputURI()
This returns the value set using the setBaseOutputURI(java.lang.String)
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.
public void setURIResolver(URIResolver resolver)
resolver
- An object that implements the URIResolver interface, or
null.public URIResolver getURIResolver()
public void setErrorListener(ErrorListener listener)
listener
- The error listener to be used. This is notified of all dynamic errors detected during the
transformation.public ErrorListener getErrorListener()
public void setMessageListener(MessageListener listener)
xsl:message
instruction. If no MessageListener is nominated,
the output of xsl:message
instructions will be serialized and sent
to the standard error stream.listener
- the MessageListener to be usedpublic MessageListener getMessageListener()
xsl:message
instruction. If no MessageListener has been nominated,
return nullpublic void setTraceListener(TraceListener listener)
XsltCompiler.setCompileWithTracing(boolean)
)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.public TraceListener getTraceListener()
public void setTraceFunctionDestination(Logger stream)
stream
- the PrintStream to which trace output will be sent. If set to
null, trace output is suppressed entirely. It is the caller's responsibility
to close the stream after use.public Logger getTraceFunctionDestination()
public void transform() throws SaxonApiException
SaxonApiException
- if any dynamic error occurs during the transformationIllegalStateException
- if no destination has been suppliedpublic Receiver getReceiver(Configuration config) throws SaxonApiException
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 setDestination(net.sf.saxon.s9api.Destination)
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
using setInitialContextNode(XdmNode)
is ignored,
as is the source set using setSource(javax.xml.transform.Source)
.
getReceiver
in interface Destination
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.SaxonApiException
- if the Receiver cannot be createdIllegalStateException
- if no Destination has been suppliedpublic void close() throws SaxonApiException
close
in interface Destination
SaxonApiException
- if any failure occurspublic Controller getUnderlyingController()
Copyright (c) 2004-2014 Saxonica Limited. All rights reserved.