public class XsltController extends Controller
ANONYMOUS_PRINCIPAL_OUTPUT_URI, errorListener, executable, globalContextItem, inUse, principalResult, principalResultURI, traceListener, validationMode
Constructor and Description |
---|
XsltController(Configuration config,
PreparedStylesheet pss) |
Modifier and Type | Method and Description |
---|---|
void |
addUnavailableOutputDestination(DocumentURI uri)
Add a URI to the set of output destinations that cannot be written to, either because
they have already been written to, or because they have been read
|
void |
applyStreamingTemplates(javax.xml.transform.Source source,
Receiver out)
Perform a transformation by applying templates in a streamable mode to a streamable
input document.
|
void |
applyTemplates(Sequence<?> source,
Receiver out)
Perform a transformation from a Source document to a Result document.
|
void |
callTemplate(StructuredQName initialTemplateName,
Receiver out)
Execute a transformation by evaluating a named template and delivering
the "raw result".
|
boolean |
checkUniqueOutputDestination(DocumentURI uri)
Check that an output destination has not been used before, optionally adding
this URI to the set of URIs that have been used.
|
protected void |
clearPerTransformationData()
Reset variables that need to be reset for each transformation if the controller
is serially reused
|
AccumulatorManager |
getAccumulatorManager()
Get the accumulator manager for this transformation.
|
java.util.Stack<AttributeSet> |
getAttributeSetEvaluationStack()
Get the stack of attribute sets being evaluated (for detection of cycles)
|
PrincipalOutputGatekeeper |
getGatekeeper()
Get the Gatekeeper object, which is used to ensure that we don't write a secondary
result document to the same destination as the principal result document
|
Mode |
getInitialMode()
Get the initial mode for the transformation
|
StructuredQName |
getInitialModeName()
Get the name of the initial mode for the transformation
|
java.util.Map<StructuredQName,Sequence<?>> |
getInitialTemplateParameters(boolean tunnel)
Get the parameters for the initial template
|
java.util.Map<StructuredQName,java.lang.Integer> |
getMessageCounters()
Get the message counters
|
Receiver |
getMessageEmitter()
Deprecated.
since 9.9.0.2; always returns null.
|
OutputURIResolver |
getOutputURIResolver()
Get the output URI resolver.
|
Destination |
getPrincipalDestination()
Get the principal destination that was supplied to the Controller
|
int |
getRecoveryPolicy()
Get the policy for handling recoverable errors
|
ResultDocumentResolver |
getResultDocumentResolver() |
Receiver |
getStreamingReceiver(Mode mode,
Receiver result)
Get a receiver to which the input to this transformation can be supplied
as a stream of events, causing the transformation to be executed in streaming mode.
|
void |
incrementMessageCounter(StructuredQName code)
Increment a counter in the message counters.
|
boolean |
isAssertionsEnabled()
Ask whether assertions (xsl:assert instructions) have been enabled at run time.
|
boolean |
isUnusedOutputDestination(DocumentURI uri)
Determine whether an output URI is available for use.
|
Receiver |
makeMessageReceiver()
Make a Receiver to be used for xsl:message output.
|
void |
preEvaluateGlobals(XPathContext context)
Pre-evaluate global variables (when debugging/tracing).
|
void |
recoverableError(XPathException err)
Report a recoverable error.
|
void |
releaseAttributeSetEvaluationStack() |
void |
removeUnavailableOutputDestination(DocumentURI uri)
Remove a URI from the set of output destinations that cannot be written to or read from.
|
void |
reset()
Reset this
Transformer to its original configuration. |
void |
setAssertionsEnabled(boolean enabled)
Ask whether assertions (xsl:assert instructions) have been enabled at run time.
|
void |
setInitialMode(StructuredQName expandedModeName)
Set the initial mode for the transformation.
|
void |
setInitialTemplateParameters(java.util.Map<StructuredQName,Sequence<?>> params,
boolean tunnel)
Set parameters for the initial template (whether this is a named template, or a template
rule invoked to process the initial input item)
|
void |
setMessageEmitter(Receiver receiver)
Set the Receiver to be used for xsl:message output.
|
void |
setMessageFactory(java.util.function.Supplier<Receiver> messageReceiverFactory)
Supply a factory function that is called every time xsl:message is executed; the factory function
is responsible for creating a
Receiver that receives the content of the message, and does
what it will with it. |
void |
setMessageReceiverClassName(java.lang.String name)
Set the message receiver class name.
|
void |
setOutputURIResolver(OutputURIResolver resolver)
Set the URI resolver for secondary output documents.
|
void |
setPrincipalDestination(Destination destination)
Supply the Controller with information about the principal destination of the transformation
|
void |
setRecoveryPolicy(int policy)
Set the policy for handling recoverable XSLT errors.
|
void |
setResultDocumentResolver(ResultDocumentResolver resultDocumentResolver) |
addTraceListener, allocateSequenceOutputter, allocateSequenceOutputter, checkReadiness, clearDocumentPool, clearGlobalContextItem, getBaseOutputURI, getBindery, getCollectionFinder, getCollectionURIResolver, getConfiguration, getConvertedParameter, getCurrentDateTime, getDefaultCollection, getDocumentPool, getErrorListener, getExecutable, getFocusTrackerFactory, getGlobalContextItem, getImplicitTimezone, getLocalIndexes, getModel, getParameter, getPathMapForDocumentProjection, getPrincipalResult, getRememberedNumber, getRuleManager, getSchemaValidationMode, getSpaceStrippingRule, getStandardURIResolver, getStylesheetCache, getTraceFunctionDestination, getTraceListener, getUnparsedTextURIResolver, getURIResolver, getUserData, handleXPathException, initializeController, isStripSourceTree, isStylesheetContainingStripSpace, isStylesheetStrippingTypeAnnotations, isTracing, makeBuilder, makePipelineConfiguration, makeSourceTree, makeStripper, newXPathContext, pauseTracing, prepareInputTree, registerDocument, registerGlobalVariableDependency, removeTraceListener, reportFatalError, setApplyFunctionConversionRulesToExternalVariables, setBaseOutputURI, setCollectionFinder, setCollectionURIResolver, setCurrentDateTime, setDefaultCollection, setErrorListener, setFocusTrackerFactory, setGlobalContextItem, setGlobalContextItem, setMemoizingFocusTrackerFactory, setModel, setMultithreadedFocusTrackerFactory, setRememberedNumber, setSchemaValidationMode, setStripSourceTrees, setTraceFunctionDestination, setTraceListener, setUnparsedTextURIResolver, setURIResolver, setUseDocumentProjection, setUserData, warning
public XsltController(Configuration config, PreparedStylesheet pss)
public void reset()
Reset this Transformer
to its original configuration.
Transformer
is reset to the same state as when it was created with
TransformerFactory.newTransformer()
,
TransformerFactory.newTransformer(javax.xml.transform.Source source)
or
Templates.newTransformer()
.
reset()
is designed to allow the reuse of existing Transformer
s
thus saving resources associated with the creation of new Transformer
s.
The above is from the JAXP specification. With Saxon, it's unlikely that reusing a Transformer will
give any performance benefits over creating a new one. The one case where it might be beneficial is
to reuse the document pool (the set of documents that have been loaded using the doc() or document()
functions). Therefore, this method does not clear the document pool. If you want to clear the document
pool, call the method Controller.clearDocumentPool()
as well.
The reset Transformer
is not guaranteed to have the same URIResolver
or ErrorListener
Object
s, e.g. Object.equals(Object obj)
.
It is guaranteed to have a functionally equal URIResolver
and ErrorListener
.
reset
in class Controller
protected void clearPerTransformationData()
clearPerTransformationData
in class Controller
public void setInitialMode(StructuredQName expandedModeName) throws XPathException
XSLT 2.0 allows a transformation to be started in a mode other than the default mode. The transformation then starts by looking for the template rule in this mode that best matches the initial context node.
This method may eventually be superseded by a standard JAXP method.
expandedModeName
- the name of the initial mode. The mode is
supplied as an expanded QName. Two special values are recognized, in the
reserved XSLT namespace:
xsl:unnamed to indicate the mode with no name, and xsl:default to indicate the
mode defined in the stylesheet header as the default mode.
The value null also indicates the unnamed mode.XPathException
- if the requested mode is not defined in the stylesheetpublic StructuredQName getInitialModeName()
public Mode getInitialMode()
public AccumulatorManager getAccumulatorManager()
public boolean checkUniqueOutputDestination(DocumentURI uri)
This method is intended for internal use only.
uri
- the URI to be used as the output destinationpublic void addUnavailableOutputDestination(DocumentURI uri)
uri
- A URI that is not available as an output destinationpublic void removeUnavailableOutputDestination(DocumentURI uri)
uri
- A URI that is being made available as an output destinationpublic boolean isUnusedOutputDestination(DocumentURI uri)
uri
- A uri that the application is proposing to use in the href attribute of
xsl:result-document: if this function returns false, then the xsl:result-document
call will fail saying the URI has already been used.public void setInitialTemplateParameters(java.util.Map<StructuredQName,Sequence<?>> params, boolean tunnel)
params
- Tunnel or non-tunnel parameters to be supplied to the initial template. The supplied
values will be converted to the required type using the function conversion rules.
Any surplus parameters are silently ignored. May be null.tunnel
- true if these are tunnel parameters; false if they are non-tunnel parameterspublic java.util.Map<StructuredQName,Sequence<?>> getInitialTemplateParameters(boolean tunnel)
tunnel
- true if the parameters to be returned are the tunnel parameters; false for the non-tunnel parameterssetInitialTemplateParameters(Map, boolean)
.
May be null.public void setMessageFactory(java.util.function.Supplier<Receiver> messageReceiverFactory)
Receiver
that receives the content of the message, and does
what it will with it.messageReceiverFactory
- a factory function whose job it is to create a Receiver
for
xsl:message output; the function should supply a new Receiver
each time it is called, because xsl:message calls may arise in different
threads and the Receiver is unlikely to be thread-safe.public void setMessageReceiverClassName(java.lang.String name)
name
- the full name of the class to be instantiated to provide a receiver for xsl:message output. The name must
be the name of a class that implements the Receiver
interfacepublic Receiver makeMessageReceiver() throws XPathException
This method is intended for internal use only. From 9.9.0.2 (bug 3979) this method is called to obtain a new Receiver each time an xsl:message instruction is evaluated.
XPathException
- if any dynamic error occurs; in
particular, if the registered MessageEmitter class is not an
Emitterpublic void setMessageEmitter(Receiver receiver)
Recent versions of the JAXP interface specify that by default the output of xsl:message is sent to the registered ErrorListener. Saxon does not implement this convention. Instead, the output is sent to a default message emitter, which is a slightly customised implementation of the standard Saxon Emitter interface.
This interface can be used to change the way in which Saxon outputs xsl:message output.
It is not necessary to use this interface in order to change the destination
to which messages are written: that can be achieved by obtaining the standard
message emitter and calling its Emitter.setWriter(java.io.Writer)
method.
Although any Receiver
can be supplied as the destination for messages,
applications may find it convenient to implement a subclass of SequenceWriter
,
in which only the abstract write()
method is implemented. This will have the effect that the
write()
method is called to output each message as it is generated, with the Item
that is passed to the write()
method being the document node at the root of an XML document
containing the contents of the message.
This method is intended for use by advanced applications. The Receiver interface itself is subject to change in new Saxon releases.
The supplied Receiver will have its open() method called once at the start of
the transformation, and its close() method will be called once at the end of the
transformation. Each individual call of an xsl:message instruction is wrapped by
calls of startDocument() and endDocument(). If terminate="yes" is specified on the
xsl:message call, the properties argument of the startDocument() call will be set
to the value ReceiverOptions.TERMINATE
.
receiver
- The receiver to receive xsl:message output.public Receiver getMessageEmitter()
setMessageEmitter(net.sf.saxon.event.Receiver)
method, or the
default message emitter otherwise.public void incrementMessageCounter(StructuredQName code)
code
- the error code whose counter is to be incrementedpublic java.util.Map<StructuredQName,java.lang.Integer> getMessageCounters()
public void setRecoveryPolicy(int policy)
Since 9.3 this call has no effect unless the error listener in use is a StandardErrorListener
or a subclass thereof. Calling this method then results in a call to the StandardErrorListener
to set the recovery policy, and the action that is taken on calls of the various methods
error(), fatalError(), and warning() is then the responsibility of the ErrorListener itself.
Since 9.2 the policy for handling the most common recoverable error, namely the ambiguous template
match that arises when a node matches more than one match pattern, is a compile-time rather than run-time
setting, and can be controlled using CompilerInfo.setRecoveryPolicy(int)
policy
- the recovery policy to be used. The options are Configuration.RECOVER_SILENTLY
,
Configuration.RECOVER_WITH_WARNINGS
, or Configuration.DO_NOT_RECOVER
.public int getRecoveryPolicy()
public void recoverableError(XPathException err) throws XPathException
This method is intended for internal use only.
recoverableError
in class Controller
err
- An exception holding information about the errorXPathException
- if the error listener decides not to
recover from the errorpublic void setOutputURIResolver(OutputURIResolver resolver)
XSLT 2.0 introduces the xsl:result-document
instruction,
allowing a transformation to have multiple result documents. JAXP does
not yet support this capability. This method allows an OutputURIResolver
to be specified that takes responsibility for deciding the destination
(and, if it wishes, the serialization properties) of secondary output files.
In Saxon 9.5, because xsl:result-document is now multi-threaded, the supplied resolver is cloned each time a new result document is created. The cloned resolved is therefore able to maintain information about the specific result document for use when its close() method is called, without worrying about thread safety.
resolver
- An object that implements the OutputURIResolver
interface, or null.setResultDocumentResolver(ResultDocumentResolver)
public ResultDocumentResolver getResultDocumentResolver()
public void setResultDocumentResolver(ResultDocumentResolver resultDocumentResolver)
public OutputURIResolver getOutputURIResolver()
getResultDocumentResolver()
setOutputURIResolver(net.sf.saxon.lib.OutputURIResolver)
public void setPrincipalDestination(Destination destination)
destination
- the principal destinationpublic Destination getPrincipalDestination()
public boolean isAssertionsEnabled()
public void setAssertionsEnabled(boolean enabled)
enabled
- true if assertions are to be enabled at run time; this has no effect
if assertions were disabled (for a particular package) at compile timepublic void preEvaluateGlobals(XPathContext context) throws XPathException
Controller
This method is intended for internal use.
preEvaluateGlobals
in class Controller
context
- the dynamic context for evaluating the global variablesXPathException
public void applyTemplates(Sequence<?> source, Receiver out) throws XPathException
source
- The input for the source tree. May be null if and only if an
initial template has been supplied.out
- The destination for the result sequence. The events that are written to this
Receiver
will form a regular event sequence
as defined in RegularSequenceChecker
. This event sequence represents
the raw results of the transformation; subsequent processing
such as sequence normalization (to construct a document node) is the
responsibility of the Receiver itself.XPathException
- if the transformation fails. As a
special case, the method throws a TerminationException (a subclass
of XPathException) if the transformation was terminated using
xsl:message terminate="yes".public PrincipalOutputGatekeeper getGatekeeper()
public void callTemplate(StructuredQName initialTemplateName, Receiver out) throws XPathException
If any child threads are started (as a result of calls to xsl:result-document) the method will wait for these to finish before returning to the caller.
initialTemplateName
- the entry point, the name of a named templateout
- The destination for the result sequence. The events that are written to this
Receiver
will form a regular event sequence
as defined in RegularSequenceChecker
. This event sequence represents
the raw results of the transformation; subsequent processing
such as sequence normalization (to construct a document node) is the
responsibility of the Receiver itself.XPathException
- if any dynamic error occurs (in this thread or in a child thread).
This includes the case where the named template does not exist.public void applyStreamingTemplates(javax.xml.transform.Source source, Receiver out) throws XPathException
source
- The input for the source tree. Must be (or resolve to) a StreamSource
or SAXSource.out
- The destination for the result sequence. The events that are written to this
Receiver
will form a regular event sequence
as defined in RegularSequenceChecker
. This event sequence represents
the raw results of the transformation; subsequent processing
such as sequence normalization (to construct a document node) is the
responsibility of the Receiver itself.XPathException
- if the transformation fails. As a
special case, the method throws a TerminationException (a subclass
of XPathException) if the transformation was terminated using
xsl:message terminate="yes".public Receiver getStreamingReceiver(Mode mode, Receiver result) throws XPathException
mode
- the initial mode, which must be a streaming moderesult
- The output destinationXPathException
- if any dynamic error occurspublic java.util.Stack<AttributeSet> getAttributeSetEvaluationStack()
public void releaseAttributeSetEvaluationStack()
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.