public class XsltCompiler extends Object
To construct an XsltCompiler, use the factory method Processor.newXsltCompiler()
on the Processor object.
An XsltCompiler may be used repeatedly to compile multiple queries. Any changes made to the XsltCompiler (that is, to the static context) do not affect queries that have already been compiled. An XsltCompiler may be used concurrently in multiple threads, but it should not then be modified once initialized.
Modifier | Constructor and Description |
---|---|
protected |
XsltCompiler(Processor processor)
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
XsltExecutable |
compile(Source source)
Compile a stylesheet.
|
void |
declareCollation(String uri,
Collator collation)
Bind a collation URI to a collation
|
void |
declareDefaultCollation(String uri)
Declare the default collation
|
ErrorListener |
getErrorListener()
Get the ErrorListener being used during this compilation episode
|
Processor |
getProcessor()
Get the Processor from which this XsltCompiler was constructed
|
CompilerInfo |
getUnderlyingCompilerInfo()
Get the underlying CompilerInfo object, which provides more detailed (but less stable) control
over some compilation options
|
URIResolver |
getURIResolver()
Get the URIResolver to be used during stylesheet compilation.
|
String |
getXsltLanguageVersion()
Get the XSLT (and XPath) language level supported by the processor.
|
boolean |
isCompileWithTracing()
Ask whether trace hooks are included in the compiled code.
|
boolean |
isSchemaAware()
Ask whether schema-awareness has been requested by means of a call on
setSchemaAware(boolean) |
void |
setCompileWithTracing(boolean option)
Set whether trace hooks are to be included in the compiled code.
|
void |
setErrorListener(ErrorListener listener)
Set the ErrorListener to be used during this compilation episode
|
void |
setParameter(QName name,
XdmValue value)
Set the non-static paramters as well as static ones.
|
void |
setSchemaAware(boolean schemaAware)
Say that the stylesheet must be compiled to be schema-aware, even if it contains no
xsl:import-schema declarations.
|
void |
setURIResolver(URIResolver resolver)
Set the URIResolver to be used during stylesheet compilation.
|
void |
setXsltLanguageVersion(String version)
Set the XSLT (and XPath) language level to be supported by the processor.
|
protected XsltCompiler(Processor processor)
Processor.newXsltCompiler()
.processor
- the Saxon processorpublic Processor getProcessor()
public void setURIResolver(URIResolver resolver)
Source
representing the
location where a stylesheet module can be found.
This URIResolver is used to dereference the URIs appearing in xsl:import
,
xsl:include
, and xsl:import-schema
declarations.
It is not used at run-time for resolving requests to the document()
or similar functions.
resolver
- the URIResolver to be used during stylesheet compilation.public void setParameter(QName name, XdmValue value)
name
- the StructuredQName of the parametervalue
- as a XdmValue of the parameterpublic URIResolver getURIResolver()
public void setErrorListener(ErrorListener listener)
listener
- The error listener to be used. This is notified of all errors detected during the
compilation.public ErrorListener getErrorListener()
public void setSchemaAware(boolean schemaAware)
schemaAware
- If true, the stylesheet will be compiled with schema-awareness
enabled even if it contains no xsl:import-schema declarations. If false, the stylesheet
is treated as schema-aware only if it contains one or more xsl:import-schema declarations.public boolean isSchemaAware()
setSchemaAware(boolean)
public void declareCollation(String uri, Collator collation)
uri
- the absolute collation URIcollation
- a Collator
object that implements the required collationIllegalArgumentException
- if an attempt is made to rebind the standard URI
for the Unicode codepoint collationpublic void declareDefaultCollation(String uri)
uri
- the absolute URI of the default collation. This URI must have been bound to a collation
using the method declareCollation(String, java.text.Collator)
IllegalStateException
- if the collation URI has not been registered, unless it is the standard
Unicode codepoint collation which is registered implicitlypublic void setXsltLanguageVersion(String version)
version
- the language level to be supported. The value 2.0 requests a processor conforming to the
XSLT 2.0 specification; 3.0 requests an XSLT 3.0 processor, while the value "0.0" (which is the
default setting in the absence of a call on this method) gets a processor according to the
value of the version attribute on the xsl:stylesheet element.
Although this interface can be used to run a 1.0 stylesheet, it is not possible to request a 1.0 processor; Saxon will handle it as a 2.0 processor in backwards-compatibility mode, which is not quite the same thing.
The value 2.1 is accepted temporarily as a synonym for 3.0
IllegalArgumentException
- if the value is not numerically equal to 0.0, 2.0, or 3.0public String getXsltLanguageVersion()
setXsltLanguageVersion(java.lang.String)
represents a processor
selected according to the value of the version attribute on the xsl:stylesheet element.public void setCompileWithTracing(boolean option)
option
- true if trace code is to be compiled in, false otherwisepublic boolean isCompileWithTracing()
public XsltExecutable compile(Source source) throws SaxonApiException
Note: the term "compile" here indicates that the stylesheet is converted into an executable form. There is no implication that this involves code generation.
The source argument identifies the XML document holding the principal stylesheet module. Other modules will be located relative to this module by resolving against the base URI that is defined as the systemId property of the supplied Source.
The following kinds of Source
are recognized:
StreamSource
, allowing the stylesheet to be supplied as a
URI, as a File
, as an InputStream
, or as a Reader
SAXSource
, allowing the stylesheet to be supplied as a stream
of SAX events from a SAX2-compliant XML parser (or any other source of SAX events)DOMSource
, allowing the stylesheet to be supplied as a
DOM tree. This option is available only if saxon9-dom.jar is on the classpath.XdmNode
representing the document node of the stylesheet modulesource
- Source object representing the principal stylesheet module to be compiledSaxonApiException
- if the stylesheet contains static errors or if it cannot be read. Note that
the exception that is thrown will not contain details of the actual errors found in the stylesheet. These
will instead be notified to the registered ErrorListener. The default ErrorListener displays error messages
on the standard error output.public CompilerInfo getUnderlyingCompilerInfo()
Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.