Package net.sf.saxon.style
Class PrincipalStylesheetModule
java.lang.Object
net.sf.saxon.style.StylesheetModule
net.sf.saxon.style.PrincipalStylesheetModule
- All Implemented Interfaces:
GlobalVariableManager
- Direct Known Subclasses:
PrincipalStylesheetModuleEE
Represents both the stylesheet module at the root of the import tree, that is, the module
that includes or imports all the others, and also the XSLT package that has this stylesheet
module as its root.
This version of the StylesheetPackage class represents a trivial package that is constructed by the system to wrap an ordinary (non-package) stylesheet, as available in XSLT 2.0. A subclass is used for "real" packages, currently available only in Saxon-EE.
-
Field Summary
Fields inherited from class net.sf.saxon.style.StylesheetModule
topLevel
-
Constructor Summary
ConstructorsConstructorDescriptionPrincipalStylesheetModule
(XSLPackage sourceElement) Create a PrincipalStylesheetModule -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFixupAction
(Action action) Register a callback action to be performed during the fixup phasevoid
addGlobalVariable
(GlobalVariable variable) Add a global variable to the collectionvoid
addGlobalVariable
(GlobalVariable variable, Visibility visibility) protected void
addImportedSchema
(NamespaceUri targetNamespace) protected void
void
Adjust visibility of components by applying xsl:expose rulesboolean
checkAcceptableModeForPackage
(XSLTemplate template, Mode mode) Check that it is legitimate to add a given template rule to a given modeprotected void
Check the streamability of an attribute set declared within this stylesheet module.void
combineAttributeSets
(Compilation compilation) Combine all like-named xsl:attribute-set declarations in this package into a single Component, whose body is an AttributeSet object.protected void
compile
(Compilation compilation) Compile the source XSLT stylesheet packageprotected void
compileError
(String message, String errorCode) Compile time error, specifying an error codeprotected void
compileError
(XPathException error) Report an error with diagnostic informationprotected void
complete()
void
declareXQueryFunction
(XQueryFunction function) Declare an imported XQuery functionprotected void
fixup()
gatherOutputProperties
(StructuredQName formatQName) Create an output properties object representing the xsl:output elements in the stylesheet.Get the class that manages accumulator functionsReturn all the attribute set declarations in the package having a particular QNameprotected void
getAttributeSets
(StructuredQName name, List<ComponentDeclaration> list) Get the list of attribute-set declarations associated with a given QName.Get a character map, identified by the fingerprint of its name.Get an index of character maps declared using xsl:character-map entries in this packagegetComponent
(SymbolicName name) Search the package for a component with a given nameGet the decimal format manager used to manage xsl:decimal-format declarations in this packagegetEquivalentVariable
(Expression select) Get an existing global variable whose initializer is a given expression, if there is one.Get the global variable or parameter with a given name (taking precedence rules into account).protected Set
<NamespaceUri> Get the key manager used to manage xsl:key declarations in this packageGet the named template with a given nameprotected NamespaceBinding
Get the declared namespace alias for a given namespace URI code if there is one.Get the outermost stylesheet module in a packageGet the rule manager used to manage modes declared explicitly or implicitly in this packageGet a module from the cache of stylesheet modulesGet the stylesheet packageGet the type alias manager (type aliases are a Saxon extension)protected boolean
protected void
Process import-schema declarationsprotected void
Add an attribute set to the indexprotected void
Add a stylesheet function to the indexvoid
Handle an explicitly-declared modeprotected void
Add a named template to the indexprotected void
Index a global xsl:variable or xsl:param elementprotected boolean
Determine if a namespace is included in the result-prefix of a namespace-aliasboolean
Ask whether it is required that modes be explicitly declaredprotected boolean
isImportedSchema
(NamespaceUri targetNamespace) Get an imported schema with a given namespacevoid
void
preprocess
(Compilation compilation) Preprocess does all the processing possible before the source document is available.void
Process the attributes of every node in the stylesheetvoid
putStylesheetDocument
(DocumentKey key, XSLStylesheet module) Add a module to the cache of stylesheet modulesvoid
setAccumulatorManager
(AccumulatorRegistry accumulatorManager) Set the class that manages accumulator functionsvoid
setNeedsDynamicOutputProperties
(boolean b) Say that this stylesheet package needs dynamic output propertiesprotected void
spliceUsePackages
(XSLPackage xslpackage, Compilation compilation) Incorporate declarations from used packagesMethods inherited from class net.sf.saxon.style.StylesheetModule
getAssociatedStylesheet, getConfiguration, getImporter, getInputTypeAnnotations, getMinImportPrecedence, getPrecedence, getRootElement, getStylesheetElement, loadStylesheet, loadStylesheetModule, setImporter, setInputTypeAnnotations, setMinImportPrecedence, setWasIncluded, spliceIncludes
-
Constructor Details
-
PrincipalStylesheetModule
Create a PrincipalStylesheetModule- Parameters:
sourceElement
- the xsl:package element at the root of the package manifest- Throws:
XPathException
- if things go wrong
-
-
Method Details
-
getComponent
Search the package for a component with a given name- Parameters:
name
- the symbolic name of the required component- Returns:
- the requested component if found, or null otherwise
-
getPrincipalStylesheetModule
Get the outermost stylesheet module in a package- Overrides:
getPrincipalStylesheetModule
in classStylesheetModule
- Returns:
- this module (this class represents both the package and its outermost module)
-
getStylesheetPackage
Get the stylesheet package- Returns:
- the associated stylesheet package
-
getKeyManager
Get the key manager used to manage xsl:key declarations in this package- Returns:
- the key manager
-
getDecimalFormatManager
Get the decimal format manager used to manage xsl:decimal-format declarations in this package- Returns:
- the decimal format manager
-
getRuleManager
Get the rule manager used to manage modes declared explicitly or implicitly in this package- Returns:
- the rule manager
-
isDeclaredModes
public boolean isDeclaredModes()Ask whether it is required that modes be explicitly declared- Returns:
- true if modes referenced within this package must be explicitly declared
-
addFixupAction
Register a callback action to be performed during the fixup phase- Parameters:
action
- the callback action
-
setNeedsDynamicOutputProperties
public void setNeedsDynamicOutputProperties(boolean b) Say that this stylesheet package needs dynamic output properties- Parameters:
b
- true if this stylesheet needs dynamic output properties
-
getCharacterMapIndex
Get an index of character maps declared using xsl:character-map entries in this package- Returns:
- the character map index
-
getTypeAliasManager
Get the type alias manager (type aliases are a Saxon extension)- Returns:
- the type alias manager
-
declareXQueryFunction
Declare an imported XQuery function- Parameters:
function
- the imported function- Throws:
XPathException
- if an error occurs
-
putStylesheetDocument
Add a module to the cache of stylesheet modules- Parameters:
key
- the key to be used (based on the absolute URI)module
- the stylesheet document tree corresponding to this absolute URI
-
getStylesheetDocument
Get a module from the cache of stylesheet modules- Parameters:
key
- the key to be used (based on the absolute URI)- Returns:
- the stylesheet document tree corresponding to this absolute URI
-
preprocess
Preprocess does all the processing possible before the source document is available. It is done once per stylesheet, so the stylesheet can be reused for multiple source documents. The method is called only on the XSLStylesheet element representing the principal stylesheet module- Parameters:
compilation
- the XSLT compilation in progress- Throws:
XPathException
- if errors are found in the stylesheet
-
spliceUsePackages
protected void spliceUsePackages(XSLPackage xslpackage, Compilation compilation) throws XPathException Incorporate declarations from used packages- Parameters:
xslpackage
- the used packagecompilation
- this compilation- Throws:
XPathException
- if any error is detected in the used package
-
importSchemata
Process import-schema declarations- Throws:
XPathException
- if errors are detected
-
processAllAttributes
public void processAllAttributes()Process the attributes of every node in the stylesheet -
indexFunction
Add a stylesheet function to the index- Parameters:
decl
- The declaration wrapping an XSLFunction object
-
indexVariableDeclaration
Index a global xsl:variable or xsl:param element- Parameters:
decl
- The Declaration referencing the XSLVariable or XSLParam element- Throws:
XPathException
- if an error occurs
-
getGlobalVariableBinding
Get the global variable or parameter with a given name (taking precedence rules into account). This will only return global variables declared in the same package where they are used.- Parameters:
qName
- name of the global variable or parameter- Returns:
- the variable declaration, or null if it does not exist
-
indexNamedTemplate
Add a named template to the index- Parameters:
decl
- the declaration of the Template object
-
getNamedTemplate
Get the named template with a given name- Parameters:
name
- the name of the required template- Returns:
- the template with the given name, if there is one, or null otherwise. If there are several templates with the same name, the one with highest import precedence is returned. Note that this template may subsequently be overridden in another package, but only by another template with a compatible signature.
-
indexAttributeSet
Add an attribute set to the index- Parameters:
decl
- the declaration of the attribute set object- Throws:
XPathException
- if an error occurs
-
getAttributeSetDeclarations
Return all the attribute set declarations in the package having a particular QName- Parameters:
name
- the name of the required declarations- Returns:
- the set of declarations having this name, or null if there are none
-
combineAttributeSets
Combine all like-named xsl:attribute-set declarations in this package into a single Component, whose body is an AttributeSet object. The resulting attribute set Components are saved in the StylesheetPackage object.- Parameters:
compilation
- the XSLT compilation in progress- Throws:
XPathException
- if a failure occurs
-
checkStreamability
Check the streamability of an attribute set declared within this stylesheet module. (Null implementation for Saxon-HE).- Parameters:
aSet
- the attribute set to be checked- Throws:
XPathException
- if the streamability rules are not satisifed
-
getAttributeSets
Get the list of attribute-set declarations associated with a given QName. This is used for xsl:element, xsl:copy, xsl:attribute-set, and on literal result elements- Parameters:
name
- the name of the required attribute setlist
- a list to hold the list of XSLAttributeSet elements in the stylesheet tree.
-
indexMode
Handle an explicitly-declared mode- Parameters:
decl
- the declaration of the Mode object
-
checkAcceptableModeForPackage
Check that it is legitimate to add a given template rule to a given mode- Parameters:
template
- the template rulemode
- the mode- Returns:
- true if all is well, false if the mode cannot be extended (in which case an error will have been reported)
-
getAccumulatorManager
Get the class that manages accumulator functions- Returns:
- the class that manages accumulators. Always null in Saxon-HE
-
setAccumulatorManager
Set the class that manages accumulator functions- Parameters:
accumulatorManager
- the manager of accumulator functions
-
addNamespaceAlias
-
getNamespaceAlias
Get the declared namespace alias for a given namespace URI code if there is one. If there is more than one, we get the last.- Parameters:
uri
- The uri used in the stylesheet.- Returns:
- The namespace binding to be used (prefix and uri): return null if no alias is defined
-
isAliasResultNamespace
Determine if a namespace is included in the result-prefix of a namespace-alias- Parameters:
uri
- the namespace URI- Returns:
- true if an xsl:namespace-alias has been defined for this namespace URI
-
hasNamespaceAliases
protected boolean hasNamespaceAliases() -
gatherOutputProperties
Create an output properties object representing the xsl:output elements in the stylesheet.- Parameters:
formatQName
- The name of the output format required. If set to null, gathers information for the unnamed output format- Returns:
- the Properties object containing the details of the specified output format
- Throws:
XPathException
- if a named output format does not exist in the stylesheet
-
compile
Compile the source XSLT stylesheet package- Parameters:
compilation
- the compilation episode- Throws:
XPathException
- if compilation fails for any reason
-
optimizeTopLevel
- Throws:
XPathException
-
isImportedSchema
Get an imported schema with a given namespace- Parameters:
targetNamespace
- The target namespace of the required schema. Supply an empty string for the default namespace- Returns:
- the required Schema, or null if no such schema has been imported
-
addImportedSchema
-
getImportedSchemaTable
-
getCharacterMap
Get a character map, identified by the fingerprint of its name. Search backwards through the stylesheet.- Parameters:
name
- The character map name being sought- Returns:
- the identified character map, or null if not found
-
adjustExposedVisibility
Adjust visibility of components by applying xsl:expose rules- Throws:
XPathException
- if this detects an error or inconsistency
-
compileError
Compile time error, specifying an error code- Parameters:
message
- the error messageerrorCode
- the error code. May be null if not known or not defined- Throws:
XPathException
- unconditionally
-
compileError
Report an error with diagnostic information- Parameters:
error
- contains information about the error
-
fixup
- Throws:
XPathException
-
complete
- Throws:
XPathException
-
getSlotManager
-
getEquivalentVariable
Description copied from interface:GlobalVariableManager
Get an existing global variable whose initializer is a given expression, if there is one. Note that this depends on the logic for detecting equivalence of expressions, which is necessarily approximate. Expressions with dependencies on the static context should never be considered equivalent. If no equivalent global variable is found, return null. An implementation can always return null if it wants to avoid a lengthy search.- Specified by:
getEquivalentVariable
in interfaceGlobalVariableManager
- Parameters:
select
- the expression to which the variable is bound- Returns:
- an existing global variable with the same select expression, if one can be found; otherwise null.
-
addGlobalVariable
Description copied from interface:GlobalVariableManager
Add a global variable to the collection- Specified by:
addGlobalVariable
in interfaceGlobalVariableManager
- Parameters:
variable
- the variable to be added
-
addGlobalVariable
-