Class XsltTransformer
- java.lang.Object
-
- net.sf.saxon.s9api.XsltTransformer
-
- All Implemented Interfaces:
Destination
public class XsltTransformer extends java.lang.Object implements Destination
AnXsltTransformer
represents a compiled and loaded stylesheet ready for execution. TheXsltTransformer
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 theLoad
method of anXsltExecutable
.An
XsltTransformer
is itself aDestination
. This means it is possible to use oneXsltTransformer
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.- Since:
- 9.0
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
baseOutputUriWasSet
-
Constructor Summary
Constructors Modifier Constructor Description protected
XsltTransformer(Processor processor, Controller controller)
Protected constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this destination, allowing resources to be released.java.lang.String
getBaseOutputURI()
Get the base output URI.Destination
getDestination()
Get the destination that was specified in a previous call ofsetDestination(net.sf.saxon.s9api.Destination)
javax.xml.transform.ErrorListener
getErrorListener()
Get the ErrorListener being used during this compilation episodeXdmNode
getInitialContextNode()
Get the initial context node for the transformation, if one has been setQName
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 setMessageListener
getMessageListener()
Get the MessageListener to be notified whenever the stylesheet evaluates anxsl:message
instruction.XdmValue
getParameter(QName name)
Get the value that has been set for a stylesheet parameterReceiver
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.javax.xml.transform.URIResolver
getURIResolver()
Get the URI resolver.void
setBaseOutputURI(java.lang.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(javax.xml.transform.ErrorListener listener)
Set the ErrorListener to be used during this transformationvoid
setInitialContextNode(XdmNode node)
Set the initial context node for the transformation.void
setInitialMode(QName modeName)
Set the initial mode for the transformationvoid
setInitialTemplate(QName templateName)
Set the initial named template for the transformationvoid
setMessageListener(MessageListener listener)
Set the MessageListener to be notified whenever the stylesheet evaluates anxsl:message
instruction.void
setParameter(QName name, XdmValue value)
Set the value of a stylesheet parametervoid
setSchemaValidationMode(ValidationMode mode)
Set the schema validation mode for the transformation.void
setSource(javax.xml.transform.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
setURIResolver(javax.xml.transform.URIResolver resolver)
Set an object that will be used to resolve URIs used in fn:doc() and related functions.void
transform()
Perform the transformation.
-
-
-
Constructor Detail
-
XsltTransformer
protected XsltTransformer(Processor processor, Controller controller)
Protected constructor- Parameters:
processor
- the S9API processorcontroller
- the Saxon controller object
-
-
Method Detail
-
setInitialTemplate
public void setInitialTemplate(QName templateName) throws SaxonApiException
Set the initial named template for the transformation- 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
-
getInitialTemplate
public QName getInitialTemplate()
Get the initial named template for the transformation, if one has been set- Returns:
- the name of the initial template, or null if none has been set
-
setInitialMode
public void setInitialMode(QName modeName)
Set the initial mode for the transformation- Parameters:
modeName
- the name of the initial mode, or null to indicate the default (unnamed) mode
-
getInitialMode
public QName getInitialMode()
Get the name of the initial mode for the transformation, if one has been set.- 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
-
setSchemaValidationMode
public void setSchemaValidationMode(ValidationMode mode)
Set the schema validation mode for the transformation. This indicates how source documents loaded specifically for this transformation will be handled. This applies to the principal source document if supplied as a SAXSource or StreamSource, and to all documents loaded during the transformation using thedoc()
,document()
, orcollection()
functions.- Parameters:
mode
- the validation mode. Passing null causes no change to the existing value. PassingValidationMode.DEFAULT
resets to the initial value, which determines the validation requirements from the Saxon Configuration.
-
getSchemaValidationMode
public ValidationMode getSchemaValidationMode()
Get the schema validation mode for the transformation. This indicates how source documents loaded specifically for this transformation will be handled. This applies to the principal source document if supplied as a SAXSource or StreamSource, and to all documents loaded during the transformation using thedoc()
,document()
, orcollection()
functions.- Returns:
- the validation mode.
-
setSource
public void setSource(javax.xml.transform.Source source) throws SaxonApiException
Set the source document for the transformation.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
DOMSource
, the DOM node identified by the DOMSource is wrapped as a Saxon node, and this is then used as the context itemIn all 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
, orTransmitter
.- Parameters:
source
- the principal source document for the transformation- Throws:
SaxonApiException
-
setInitialContextNode
public void setInitialContextNode(XdmNode node)
Set the initial context node for the transformation.This is ignored in the case where the
XsltTransformer
is used as theDestination
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.
- Parameters:
node
- the initial context node, or null if there is to be no initial context node
-
getInitialContextNode
public XdmNode getInitialContextNode()
Get the initial context node for the transformation, if one has been set- 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.
-
setParameter
public void setParameter(QName name, XdmValue value)
Set the value of a stylesheet parameter- Parameters:
name
- the name of the stylesheet parameter, as a QNamevalue
- the value of the stylesheet parameter, or null to clear a previously set value
-
getParameter
public XdmValue getParameter(QName name)
Get the value that has been set for a stylesheet parameter- 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
-
setDestination
public void setDestination(Destination destination)
Set the destination to be used for the result of the transformation.This method can be used to chain transformations into a pipeline, by using one
XsltTransformer
as the destination of anotherIf the destination is a
Serializer
, then a side-effect of this method is to set the base output URI for the transformation. This acts as the base URI for resolving thehref
attribute of anyxsl:result-document
instruction. The serialiation parameters defined in theSerializer
override any serialization parameters defined usingxsl:output
for the principal output of the transformation. However, they have no effect on any output produced usingxsl:result-document
.- Parameters:
destination
- the destination to be used
-
getDestination
public Destination getDestination()
Get the destination that was specified in a previous call ofsetDestination(net.sf.saxon.s9api.Destination)
- Returns:
- the destination, or null if none has been supplied
-
setBaseOutputURI
public void setBaseOutputURI(java.lang.String uri)
Set the base output 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 aSerializer
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 thexsl:result-document
instruction.- Parameters:
uri
- the base output URI- Since:
- 9.2
-
getBaseOutputURI
public java.lang.String getBaseOutputURI()
Get the base output URI.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 thexsl:result-document
instruction.- Returns:
- the base output URI
- Since:
- 9.2
-
setURIResolver
public void setURIResolver(javax.xml.transform.URIResolver resolver)
Set an object that will be used to resolve URIs used in fn:doc() and related functions.- Parameters:
resolver
- An object that implements the URIResolver interface, or null.- Since:
- 9.3
-
getURIResolver
public javax.xml.transform.URIResolver getURIResolver()
Get the URI resolver.- Returns:
- the user-supplied URI resolver if there is one, or null otherwise
- Since:
- 9.3
-
setErrorListener
public void setErrorListener(javax.xml.transform.ErrorListener listener)
Set the ErrorListener to be used during this transformation- Parameters:
listener
- The error listener to be used. This is notified of all dynamic errors detected during the transformation.- Since:
- 9.2
-
getErrorListener
public javax.xml.transform.ErrorListener getErrorListener()
Get the ErrorListener being used during this compilation episode- 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
-
setMessageListener
public void setMessageListener(MessageListener listener)
Set the MessageListener to be notified whenever the stylesheet evaluates anxsl:message
instruction. If no MessageListener is nominated, the output ofxsl:message
instructions will be serialized and sent to the standard error stream.- Parameters:
listener
- the MessageListener to be used- Since:
- 9.1
-
getMessageListener
public MessageListener getMessageListener()
Get the MessageListener to be notified whenever the stylesheet evaluates anxsl:message
instruction. If no MessageListener has been nominated, return null- Returns:
- the user-supplied MessageListener, or null if none has been supplied
- Since:
- 9.1
-
setTraceListener
public void setTraceListener(TraceListener listener)
Set a TraceListener to be notified of all events occurring during the transformation. This will only be effective if the stylesheet was compiled with trace code enabled (seeXsltCompiler.setCompileWithTracing(boolean)
)- 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
-
getTraceListener
public TraceListener getTraceListener()
Get the TraceListener to be notified of all events occurring during the transformation. If no TraceListener has been nominated, return null- Returns:
- the user-supplied TraceListener, or null if none has been supplied
- Since:
- 9.2
-
transform
public void transform() throws SaxonApiException
Perform the transformation. If this method is used, a destination must have been supplied previously- Throws:
SaxonApiException
- if any dynamic error occurs during the transformationjava.lang.IllegalStateException
- if no destination has been supplied
-
getReceiver
public Receiver getReceiver(Configuration config) throws SaxonApiException
Return a Receiver which can be used to supply the principal source document for the transformation. This method is intended primarily for internal use, though it can also be called by a user application that wishes to feed events into the transformation engine.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
implementsDestination
, 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 aDestination
, the initial context node set on thatXsltTransformer
usingsetInitialContextNode(XdmNode)
is ignored, as is the source set usingsetSource(javax.xml.transform.Source)
.- Specified by:
getReceiver
in interfaceDestination
- 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 createdjava.lang.IllegalStateException
- if no Destination has been supplied
-
close
public void close() throws SaxonApiException
Close this destination, allowing resources to be released. Used when this XsltTransformer is acting as the destination of another transformation. Saxon calls this method when it has finished writing to the destination.- Specified by:
close
in interfaceDestination
- Throws:
SaxonApiException
- if any failure occurs
-
getUnderlyingController
public Controller getUnderlyingController()
Get the underlying Controller used to implement this XsltTransformer. This provides access to lower-level methods not otherwise available in the s9api interface. Note that classes and methods obtained by this route cannot be guaranteed stable from release to release.- Since:
- 9.0.0.4
-
-