public abstract class AbstractXsltTransformer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
baseOutputUriWasSet |
protected XsltController |
controller |
protected Processor |
processor |
Modifier and Type | Method and Description |
---|---|
protected void |
applyTemplatesToSource(javax.xml.transform.Source source,
Receiver out) |
java.lang.String |
getBaseOutputURI()
Get the base output URI.
|
Receiver |
getDestinationReceiver(XsltController controller,
Destination destination)
Get a Receiver corresponding to the chosen Destination for the transformation
|
javax.xml.transform.ErrorListener |
getErrorListener()
Get the ErrorListener being used during this transformation
|
ErrorReporter |
getErrorReporter()
Get the callback that will be used when reporting a dynamic error or warning
|
QName |
getInitialMode()
Get the name of the initial mode for the transformation, if one has been set.
|
MessageListener2 |
getMessageListener2()
Get the MessageListener2 to be notified whenever the stylesheet evaluates an
xsl:message instruction. |
protected Receiver |
getReceivingTransformer(XsltController controller,
GlobalParameterSet parameters,
Destination finalDestination)
Return a Receiver which can be used to supply the principal source document for the transformation.
|
ResourceResolver |
getResourceResolver()
Get the resource resolver.
|
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.
|
XsltController |
getUnderlyingController()
Get the underlying Controller used to implement this XsltTransformer.
|
UnparsedTextURIResolver |
getUnparsedTextURIResolver()
Get the URI resolver used for
fn:unparsed-text() and related functions. |
javax.xml.transform.URIResolver |
getURIResolver()
Get the URI resolver.
|
boolean |
isAssertionsEnabled()
Ask whether assertions (xsl:assert instructions) have been enabled at run time.
|
protected boolean |
isStreamableSource(javax.xml.transform.Source source) |
void |
setAssertionsEnabled(boolean enabled)
Say whether assertions (xsl:assert instructions) should be enabled at run time.
|
void |
setBaseOutputURI(java.lang.String uri)
Set the base output URI.
|
void |
setErrorListener(javax.xml.transform.ErrorListener listener)
Set the ErrorListener to be used during this transformation
|
void |
setErrorReporter(ErrorReporter reporter)
Set a callback that will be used when reporting a dynamic error or warning.
|
void |
setInitialMode(QName modeName)
Set the initial mode for the transformation
|
void |
setMessageHandler(java.util.function.Consumer<Message> messageHandler)
Set a message handler to be notified of
xsl:message and xsl:assert output. |
void |
setMessageListener(MessageListener2 listener)
Set the MessageListener to be notified of
xsl:message and xsl:assert output. |
void |
setResourceResolver(ResourceResolver resolver)
Set the
ResourceResolver to be used during stylesheet execution. |
void |
setResultDocumentHandler(java.util.function.Function<java.net.URI,Destination> handler)
Set a callback function that will be used when
xsl:result-document is evaluated. |
void |
setSchemaValidationMode(ValidationMode mode)
Set the schema validation mode 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 |
setUnparsedTextResolver(UnparsedTextURIResolver resolver)
Set an object that will be used to resolve URIs used in
fn:unparsed-text() and related functions. |
void |
setURIResolver(javax.xml.transform.URIResolver resolver)
Deprecated.
since 11.1. Use
setResourceResolver(net.sf.saxon.lib.ResourceResolver) in preference. |
protected Processor processor
protected XsltController controller
protected boolean baseOutputUriWasSet
public void setBaseOutputURI(java.lang.String uri)
This defaults to the base URI of the Destination
for the principal output
of the transformation if a destination is supplied and its base URI is known.
If a base output URI is supplied using this method then it takes precedence
over any base URI defined in the supplied Destination
object, and
it may cause the base URI of the Destination
object to be modified in situ.
The base output URI is used for resolving relative URIs in the href
attribute
of the xsl:result-document
instruction; it is accessible to XSLT stylesheet
code using the XPath current-output-uri()
function
uri
- the base output URIpublic java.lang.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(javax.xml.transform.URIResolver resolver)
setResourceResolver(net.sf.saxon.lib.ResourceResolver)
in preference.resolver
- An object that implements the URIResolver interface, or
null.public void setResourceResolver(ResourceResolver resolver)
ResourceResolver
to be used during stylesheet execution.
The ResourceResolver
is used for dereferencing
an absolute URI (after URI resolution) to return a Source
representing the
required resource.
This ResourceResolver
is used to dereference the URIs appearing in the doc()
,
doc-available()
, and document()
functions: in these cases it may return any
supported Source
object.
It is also used to dereference the URI supplied to the xsl:source-document
instruction. In this case the resource request passed to the resolver indicates whether the
instruction has the attribute streamable="yes"
; if it does, the returned
Source
object must be a StreamSource
or SAXSource
.
The resolver is also used for a number of other cases where URIs are dereferenced during
stylesheet execution, for example in the fn:transform
function
resolver
- the ResourceResolver
to be used during stylesheet execution.public ResourceResolver getResourceResolver()
public javax.xml.transform.URIResolver getURIResolver()
public void setUnparsedTextResolver(UnparsedTextURIResolver resolver)
fn:unparsed-text()
and related functions.resolver
- An object that implements the UnparsedTextURIResolver interface, or
null.public UnparsedTextURIResolver getUnparsedTextURIResolver()
fn:unparsed-text()
and related functions.public void setErrorListener(javax.xml.transform.ErrorListener listener)
listener
- The error listener to be used. This is notified of all dynamic errors detected during the
transformation.public javax.xml.transform.ErrorListener getErrorListener()
ErrorListener
has been set the method will return
a system-supplied ErrorListener that delegates to the ErrorReporter
.
If an explicit ErrorListener
has been set using setErrorListener(ErrorListener)
,
then that ErrorListener will generally be returned, unless the internal ErrorListener has been changed
by some other mechanism.public void setErrorReporter(ErrorReporter reporter)
reporter
- the callbackpublic ErrorReporter getErrorReporter()
public void setResultDocumentHandler(java.util.function.Function<java.net.URI,Destination> handler)
xsl:result-document
is evaluated. The argument
is a function that takes a URI as input (specifically, the value of the href
argument
to xsl:result-document
, resolved against the base output URI of the transformation),
and returns a Destination
, which will be used as the destination for the result document.
If the href
argument of the xsl:result-document
instruction is absent or if
it is set to a zero length string, then the callback function is not normally called; instead
a Receiver
for the secondary output is obtained by making a second call on
Destination.getReceiver(PipelineConfiguration, SerializationProperties)
for the principal destination of the transformation. In that situation, this result document handler
is invoked only if the call on Destination.getReceiver(PipelineConfiguration, SerializationProperties)
returns null.
If the base output URI is absent (perhaps because the principal output destination for the
transformation was supplied as a OutputStream
or Writer
with no associated
URI or systemId), then the value of the href
attribute is used as is if it
is an absolute URI; if it is a relative URI (including the case where it is absent or zero-length)
then the callback function is not called; instead a dynamic error is raised (code
SaxonErrorCode.SXRD0002
).
If the callback function throws a SaxonApiUncheckedException
, this will result
in the xsl:result-document
instruction failing with a dynamic error, which can be caught
using xsl:try/xsl:catch
. The error code, by default, will be "err:SXRD0001".
The application can request to be notified when the Destination
is closed by setting
a Destination.onClose(Action)
callback on the Destination
object.
handler
- the callback function to be invoked whenever an xsl:result-document
instruction is evaluated.public void setMessageListener(MessageListener2 listener)
xsl:message
and xsl:assert
output.listener
- the MessageListener to be notifiedpublic void setMessageHandler(java.util.function.Consumer<Message> messageHandler)
xsl:message
and xsl:assert
output.messageHandler
- the message handler to be notifiedpublic MessageListener2 getMessageListener2()
xsl:message
instruction. If no MessageListener2 has been nominated,
return nullpublic 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 boolean isAssertionsEnabled()
public 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()
protected void applyTemplatesToSource(javax.xml.transform.Source source, Receiver out) throws XPathException
XPathException
protected boolean isStreamableSource(javax.xml.transform.Source source)
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 setInitialMode(QName modeName) throws SaxonApiException
modeName
- the name of the initial mode. 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 default mode (which defaults to the unnamed
mode, but can be set differently in an XSLT 3.0 stylesheet).SaxonApiException
- if the requested mode is not defined in the stylesheet, or if
it is defined with visibility="private".public QName getInitialMode()
public XsltController getUnderlyingController()
Controller
public Receiver getDestinationReceiver(XsltController controller, Destination destination) throws SaxonApiException
controller
- the Controller for the transformationdestination
- the destination for the results of this transformationSaxonApiException
- if anything goes wrongprotected Receiver getReceivingTransformer(XsltController controller, GlobalParameterSet parameters, Destination finalDestination) 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.
controller
- the Controller for the transformationparameters
- the global parametersfinalDestination
- the destination for the results of this transformationSaxonApiException
- if the Receiver cannot be createdjava.lang.IllegalStateException
- if no Destination has been suppliedCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.