Package net.sf.saxon
Class PreparedStylesheet
- java.lang.Object
-
- net.sf.saxon.expr.instruct.Executable
-
- net.sf.saxon.PreparedStylesheet
-
- All Implemented Interfaces:
java.io.Serializable
,javax.xml.transform.Templates
public class PreparedStylesheet extends Executable implements javax.xml.transform.Templates, java.io.Serializable
This PreparedStylesheet class represents a Stylesheet that has been prepared for execution (or "compiled"). Note that the PreparedStylesheet object does not contain a reference to the source stylesheet tree (rooted at an XSLStyleSheet object). This allows the source tree to be garbage-collected when it is no longer required.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PreparedStylesheet(Configuration config, CompilerInfo info)
Constructor - deliberately protected
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PreparedStylesheet
compile(javax.xml.transform.Source source, Configuration config, CompilerInfo info)
Factory method to make a PreparedStylesheetvoid
explain(ExpressionPresenter presenter)
Produce an XML representation of the compiled and optimized stylesheetvoid
explainNamedTemplates(ExpressionPresenter presenter)
Explain the expression tree for named templates in a stylesheetstatic javax.xml.transform.Source
getAssociatedStylesheet(Configuration config, javax.xml.transform.Source source, java.lang.String media, java.lang.String title, java.lang.String charset)
Get the stylesheet specification(s) associated via the xml-stylesheet processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with the document document specified in the source parameter, and that match the given criteria.PreparedStylesheet
getCachedStylesheet(java.lang.String href, java.lang.String baseURI)
Get a "next in chain" stylesheet.CompilerInfo
getCompilerInfo()
Get the CompilerInfo containing details of XSLT compilation optionsDecimalFormatManager
getDecimalFormatManager()
Get the DecimalFormatManager which handles decimal-format definitionsint
getErrorCount()
Get the number of errors reported so farTemplate
getNamedTemplate(StructuredQName qName)
Get the named template with a given name.java.util.Properties
getOutputProperties()
Get the properties for xsl:output.RuleManager
getRuleManager()
Get the RuleManager which handles template rulesStyleNodeFactory
getStyleNodeFactory()
Get the StyleNodeFactory in use.boolean
isCompileWithTracing()
Determine whether trace hooks are included in the compiled code.java.util.Iterator<Template>
iterateNamedTemplates()
Iterate over all the named templates defined in this ExecutableDocumentImpl
loadStylesheetModule(javax.xml.transform.Source styleSource)
Build the tree representation of a stylesheet modulejavax.xml.transform.Transformer
newTransformer()
Make a Transformer from this Templates object.protected void
prepare(javax.xml.transform.Source styleSource)
Prepare a stylesheet from a Source documentvoid
putCachedStylesheet(java.lang.String href, java.lang.String baseURI, PreparedStylesheet pss)
Save a "next in chain" stylesheet in compiled form, so that it can be reused repeatedly.void
putNamedTemplate(StructuredQName templateName, Template template)
Register the named template with a given namevoid
reportError(javax.xml.transform.TransformerException err)
Report a compile time error.void
reportWarning(javax.xml.transform.TransformerException err)
Report a compile time warning.void
setConfiguration(Configuration config)
Set the configuration in which this stylesheet is compiled.void
setDecimalFormatManager(DecimalFormatManager dfm)
Set the DecimalFormatManager which handles decimal-format definitionsvoid
setRuleManager(RuleManager rm)
Set the RuleManager that handles template rulesprotected void
setStylesheetDocument(DocumentImpl doc)
Create a PreparedStylesheet from a supplied DocumentInfo Note: the document must have been built using the StyleNodeFactoryvoid
setUsesTunnelParameters()
Say that the stylesheet uses tunnel parameters.boolean
usesTunnelParameters()
Ask whether the stylesheet uses tunnel parameters.-
Methods inherited from class net.sf.saxon.expr.instruct.Executable
addQueryLibraryModule, addQueryLocationHintProcessed, addRequiredParam, checkAllRequiredParamsArePresent, createsSecondaryResult, explainGlobalVariables, fixupQueryModules, getCharacterMapIndex, getCollationTable, getCompiledGlobalVariables, getConfiguration, getDefaultOutputProperties, getFunctionLibrary, getGlobalVariable, getGlobalVariableMap, getHostLanguage, getInitialContextItemVariableName, getKeyManager, getLargestPatternStackFrame, getLocationMap, getNamedCollation, getOutputProperties, getQueryLibraryModules, getQueryLibraryModules, getQueryModuleWithSystemId, getStripperRules, initializeBindery, isAllowXPath30, isQueryLocationHintProcessed, isSchemaAware, registerGlobalVariable, setCharacterMapIndex, setCollationMap, setCreatesSecondaryResult, setDefaultOutputProperties, setFunctionLibrary, setHostLanguage, setInitialContextItemVariableName, setKeyManager, setLocationMap, setOutputProperties, setPatternSlotSpace, setSchemaAware, setStripperRules, setStripsInputTypeAnnotations, setStripsWhitespace, stripsInputTypeAnnotations, stripsWhitespace
-
-
-
-
Constructor Detail
-
PreparedStylesheet
protected PreparedStylesheet(Configuration config, CompilerInfo info)
Constructor - deliberately protected- Parameters:
config
- The Configuration set up by the TransformerFactoryinfo
- Compilation options
-
-
Method Detail
-
compile
public static PreparedStylesheet compile(javax.xml.transform.Source source, Configuration config, CompilerInfo info) throws javax.xml.transform.TransformerConfigurationException
Factory method to make a PreparedStylesheet- Parameters:
source
- the source of this principal stylesheet moduleconfig
- the Saxon configurationinfo
- compile-time options for this stylesheet compilation- Returns:
- the prepared stylesheet
- Throws:
javax.xml.transform.TransformerConfigurationException
- if there is a static error in the stylesheet
-
newTransformer
public javax.xml.transform.Transformer newTransformer()
Make a Transformer from this Templates object.- Specified by:
newTransformer
in interfacejavax.xml.transform.Templates
- Returns:
- the new Transformer (always a Controller)
- See Also:
Controller
-
setConfiguration
public void setConfiguration(Configuration config)
Set the configuration in which this stylesheet is compiled. Intended for internal use.- Overrides:
setConfiguration
in classExecutable
- Parameters:
config
- the configuration to be used.
-
getStyleNodeFactory
public StyleNodeFactory getStyleNodeFactory()
Get the StyleNodeFactory in use. The StyleNodeFactory determines which subclass of StyleElement to use for each element node in the stylesheet tree.- Returns:
- the StyleNodeFactory
-
setDecimalFormatManager
public void setDecimalFormatManager(DecimalFormatManager dfm)
Set the DecimalFormatManager which handles decimal-format definitions- Parameters:
dfm
- the DecimalFormatManager containing the named xsl:decimal-format definitions
-
getDecimalFormatManager
public DecimalFormatManager getDecimalFormatManager()
Get the DecimalFormatManager which handles decimal-format definitions- Returns:
- the DecimalFormatManager containing the named xsl:decimal-format definitions
-
setUsesTunnelParameters
public void setUsesTunnelParameters()
Say that the stylesheet uses tunnel parameters. (This information is used by the bytecode generator, which avoids generating code to pass tunnel parameters on every apply-templates call if there are no tunnel parameters anywhere in the stylesheet).
-
usesTunnelParameters
public boolean usesTunnelParameters()
Ask whether the stylesheet uses tunnel parameters. (Called by the bytecode generator).- Returns:
- true if the stylesheet uses tunnel parameters.
-
prepare
protected void prepare(javax.xml.transform.Source styleSource) throws javax.xml.transform.TransformerConfigurationException
Prepare a stylesheet from a Source document- Parameters:
styleSource
- the source document containing the stylesheet- Throws:
javax.xml.transform.TransformerConfigurationException
- if compilation of the stylesheet fails for any reason
-
loadStylesheetModule
public DocumentImpl loadStylesheetModule(javax.xml.transform.Source styleSource) throws XPathException
Build the tree representation of a stylesheet module- Parameters:
styleSource
- the source of the module- Returns:
- the root Document node of the tree containing the stylesheet module
- Throws:
XPathException
- if XML parsing or tree construction fails
-
setStylesheetDocument
protected void setStylesheetDocument(DocumentImpl doc) throws XPathException
Create a PreparedStylesheet from a supplied DocumentInfo Note: the document must have been built using the StyleNodeFactory- Parameters:
doc
- the document containing the stylesheet module- Throws:
XPathException
- if the document supplied is not a stylesheet
-
setRuleManager
public void setRuleManager(RuleManager rm)
Set the RuleManager that handles template rules- Parameters:
rm
- the RuleManager containing details of all the template rules
-
getRuleManager
public RuleManager getRuleManager()
Get the RuleManager which handles template rules- Returns:
- the RuleManager registered with setRuleManager
-
getNamedTemplate
public Template getNamedTemplate(StructuredQName qName)
Get the named template with a given name.- Parameters:
qName
- The template name- Returns:
- The template (of highest import precedence) with this name if there is one; null if none is found.
-
putNamedTemplate
public void putNamedTemplate(StructuredQName templateName, Template template)
Register the named template with a given name- Parameters:
templateName
- the name of a named XSLT templatetemplate
- the template
-
iterateNamedTemplates
public java.util.Iterator<Template> iterateNamedTemplates()
Iterate over all the named templates defined in this Executable- Returns:
- an iterator, the items returned being of class
Template
-
explainNamedTemplates
public void explainNamedTemplates(ExpressionPresenter presenter)
Explain the expression tree for named templates in a stylesheet- Parameters:
presenter
- destination for the explanatory output
-
isCompileWithTracing
public boolean isCompileWithTracing()
Determine whether trace hooks are included in the compiled code.- Returns:
- true if trace hooks are included, false if not.
- Since:
- 8.9
-
getOutputProperties
public java.util.Properties getOutputProperties()
Get the properties for xsl:output. JAXP method. The object returned will be a clone of the internal values, and thus it can be mutated without mutating the Templates object, and then handed in to the process method.In Saxon, the properties object is a new, empty, Properties object that is backed by the live properties to supply default values for missing properties. This means that the property values must be read using the getProperty() method. Calling the get() method on the underlying Hashtable will return null.
In Saxon 8.x, this method gets the output properties for the unnamed output format in the stylesheet.
- Specified by:
getOutputProperties
in interfacejavax.xml.transform.Templates
- Returns:
- A Properties object reflecting the output properties defined for the default (unnamed) output format in the stylesheet. It may be mutated and supplied to the setOutputProperties() method of the Transformer, without affecting other transformations that use the same stylesheet.
- See Also:
Transformer.setOutputProperties(java.util.Properties)
-
reportError
public void reportError(javax.xml.transform.TransformerException err) throws javax.xml.transform.TransformerException
Report a compile time error. This calls the errorListener to output details of the error, and increments an error count.- Parameters:
err
- the exception containing details of the error- Throws:
javax.xml.transform.TransformerException
- if the ErrorListener decides that the error should be reported
-
getErrorCount
public int getErrorCount()
Get the number of errors reported so far- Returns:
- the number of errors reported
-
reportWarning
public void reportWarning(javax.xml.transform.TransformerException err)
Report a compile time warning. This calls the errorListener to output details of the warning.- Parameters:
err
- an exception holding details of the warning condition to be reported
-
getCachedStylesheet
public PreparedStylesheet getCachedStylesheet(java.lang.String href, java.lang.String baseURI)
Get a "next in chain" stylesheet. This method is intended for internal use.- Parameters:
href
- the relative URI of the next-in-chain stylesheetbaseURI
- the baseURI against which this relativeURI is to be resolved- Returns:
- the cached stylesheet if present in the cache, or null if not
-
putCachedStylesheet
public void putCachedStylesheet(java.lang.String href, java.lang.String baseURI, PreparedStylesheet pss)
Save a "next in chain" stylesheet in compiled form, so that it can be reused repeatedly. This method is intended for internal use.- Parameters:
href
- the relative URI of the stylesheetbaseURI
- the base URI against which the relative URI is resolvedpss
- the prepared stylesheet object to be cached
-
getCompilerInfo
public CompilerInfo getCompilerInfo()
Get the CompilerInfo containing details of XSLT compilation options- Returns:
- the CompilerInfo containing compilation options
- Since:
- 9.2
-
explain
public void explain(ExpressionPresenter presenter)
Produce an XML representation of the compiled and optimized stylesheet- Parameters:
presenter
- defines the destination and format of the output
-
getAssociatedStylesheet
public static javax.xml.transform.Source getAssociatedStylesheet(Configuration config, javax.xml.transform.Source source, java.lang.String media, java.lang.String title, java.lang.String charset) throws javax.xml.transform.TransformerConfigurationException
Get the stylesheet specification(s) associated via the xml-stylesheet processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with the document document specified in the source parameter, and that match the given criteria. Note that it is possible to return several stylesheets, in which case they are applied as if they were a list of imports or cascades.- Parameters:
config
- The Saxon Configurationsource
- The XML source document.media
- The media attribute to be matched. May be null, in which case the prefered templates will be used (i.e. alternate = no).title
- The value of the title attribute to match. May be null.charset
- The value of the charset attribute to match. May be null.- Returns:
- A Source object suitable for passing to the TransformerFactory.
- Throws:
javax.xml.transform.TransformerConfigurationException
- if any problems occur
-
-