Package net.sf.saxon.style
Class PrincipalStylesheetModule
- java.lang.Object
-
- net.sf.saxon.style.StylesheetModule
-
- net.sf.saxon.style.PrincipalStylesheetModule
-
public class PrincipalStylesheetModule extends StylesheetModule
Represents the stylesheet module at the root of the import tree, that is, the module that includes or imports all the others. Note that this object is present at compile time only, unlike the Executable, which also exists at run-time.
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.style.StylesheetModule
topLevel, wasIncluded
-
-
Constructor Summary
Constructors Constructor Description PrincipalStylesheetModule(XSLStylesheet sourceElement, int precedence)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addImportedSchema(java.lang.String targetNamespace)
protected void
addNamespaceAlias(Declaration node)
void
allocatePatternSlots(int n)
Ensure there is enough space for local variables or parameters when evaluating the match pattern of template rulesint
allocateUniqueParameterNumber(StructuredQName qName)
Allocate a unique number to a local parameter name.protected void
compileError(java.lang.String message, java.lang.String errorCode)
Compile time error, specifying an error codeprotected void
compileError(XPathException error)
Report an error with diagnostic informationvoid
compileStylesheet()
Compile the stylesheet to create an executable.FunctionLibraryList
createFunctionLibrary(CompilerInfo info)
Create the function libraryvoid
declareXQueryFunction(XQueryFunction function)
Declare an imported XQuery functionStringCollator
findCollation(java.lang.String name, java.lang.String baseURI)
Find a named collation.java.util.Properties
gatherOutputProperties(StructuredQName formatQName)
Create an output properties object representing the xsl:output elements in the stylesheet.protected boolean
getAttributeSets(StructuredQName name, java.util.List<Declaration> list)
Get the list of attribute-set declarations associated with a given QName.Declaration
getCharacterMap(StructuredQName name)
Get a character map, identified by the fingerprint of its name.CollationMap
getCollationMap()
Get the collation mapprotected XSLFunction
getFunction(StructuredQName name, int arity)
Get the function with a given name and arityprotected Declaration
getFunctionDeclaration(StructuredQName name, int arity)
FunctionLibrary
getFunctionLibrary()
Get the function library.XSLVariableDeclaration
getGlobalVariable(StructuredQName qName)
Get the global variable or parameter with a given name (taking precedence rules into account)protected java.util.HashSet<java.lang.String>
getImportedSchemaTable()
XSLTemplate
getNamedTemplate(StructuredQName name)
Get the named template with a given nameprotected NamespaceBinding
getNamespaceAlias(java.lang.String uri)
Get the declared namespace alias for a given namespace URI code if there is one.PreparedStylesheet
getPreparedStylesheet()
PrincipalStylesheetModule
getPrincipalStylesheetModule()
XSLStylesheet
getStylesheetDocument(DocumentURI key)
Get a module from the cachejava.lang.String
getVersion()
Get the value of the version attribute on the xsl:stylesheet element of the principal stylesheet moduleprotected boolean
hasNamespaceAliases()
protected void
indexFunction(Declaration decl)
Add a stylesheet function to the indexprotected void
indexNamedTemplate(Declaration decl)
Add a named template to the indexprotected void
indexVariableDeclaration(Declaration decl)
Index a global xsl:variable or xsl:param elementprotected boolean
isAliasResultNamespace(java.lang.String uri)
Determine if a namespace is included in the result-prefix of a namespace-aliasprotected boolean
isImportedSchema(java.lang.String targetNamespace)
Get an imported schema with a given namespacevoid
preprocess()
Preprocess does all the processing possible before the source document is available.void
processAllAttributes()
Process the attributes of every node in the stylesheetprotected void
putFunction(Declaration decl)
void
putStylesheetDocument(DocumentURI key, XSLStylesheet module)
Add a module to the cachevoid
setCollation(java.lang.String name, StringCollator collation)
Register a named collation (actually a StringCollator)void
setNeedsDynamicOutputProperties(boolean b)
Say that this stylesheet needs dynamic output propertiesvoid
setPreparedStylesheet(PreparedStylesheet preparedStylesheet)
void
setVersion(java.lang.String version)
Set the value of the version attribute on the xsl:stylesheet element of the principal stylesheet moduleboolean
stripsWhitespace()
Determine whether this stylesheet does any whitespace stripping-
Methods inherited from class net.sf.saxon.style.StylesheetModule
getImporter, getInputTypeAnnotations, getMinImportPrecedence, getPrecedence, getSourceElement, setImporter, setInputTypeAnnotations, setMinImportPrecedence, setWasIncluded, spliceIncludes
-
-
-
-
Constructor Detail
-
PrincipalStylesheetModule
public PrincipalStylesheetModule(XSLStylesheet sourceElement, int precedence)
-
-
Method Detail
-
setPreparedStylesheet
public void setPreparedStylesheet(PreparedStylesheet preparedStylesheet)
-
getPreparedStylesheet
public PreparedStylesheet getPreparedStylesheet()
-
getPrincipalStylesheetModule
public PrincipalStylesheetModule getPrincipalStylesheetModule()
- Overrides:
getPrincipalStylesheetModule
in classStylesheetModule
-
createFunctionLibrary
public FunctionLibraryList createFunctionLibrary(CompilerInfo info)
Create the function library- Returns:
- the resulting function library
-
getFunctionLibrary
public FunctionLibrary getFunctionLibrary()
Get the function library. Available only on the principal stylesheet module- Returns:
- the function library
-
declareXQueryFunction
public void declareXQueryFunction(XQueryFunction function) throws XPathException
Declare an imported XQuery function- Parameters:
function
- the imported function- Throws:
XPathException
- if an error occurs
-
putStylesheetDocument
public void putStylesheetDocument(DocumentURI key, XSLStylesheet module)
Add a module to the cache- Parameters:
key
- the key to be used (based on the absolute URI)module
- the stylesheet document tree corresponding to this absolute URI
-
getStylesheetDocument
public XSLStylesheet getStylesheetDocument(DocumentURI key)
Get a module from the cache- Parameters:
key
- the key to be used (based on the absolute URI)- Returns:
- the stylesheet document tree corresponding to this absolute URI
-
preprocess
public void preprocess() throws XPathException
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- Throws:
XPathException
- if errors are found in the stylesheet
-
processAllAttributes
public void processAllAttributes() throws XPathException
Process the attributes of every node in the stylesheet- Throws:
XPathException
- if static errors are found in the stylesheet
-
indexFunction
protected void indexFunction(Declaration decl) throws XPathException
Add a stylesheet function to the index- Parameters:
decl
- The declaration wrapping an XSLFunction object- Throws:
XPathException
- if errors are found
-
getFunctionDeclaration
protected Declaration getFunctionDeclaration(StructuredQName name, int arity)
-
getFunction
protected XSLFunction getFunction(StructuredQName name, int arity)
Get the function with a given name and arity- Parameters:
name
- the name of the functionarity
- the arity of the function, or -1 if any arity will do- Returns:
- the requested function, or null if none can be found
-
putFunction
protected void putFunction(Declaration decl)
-
indexVariableDeclaration
protected void indexVariableDeclaration(Declaration decl) throws XPathException
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
-
getGlobalVariable
public XSLVariableDeclaration getGlobalVariable(StructuredQName qName)
Get the global variable or parameter with a given name (taking precedence rules into account)- Parameters:
qName
- name of the global variable or parameter- Returns:
- the variable declaration, or null if it does not exist
-
allocateUniqueParameterNumber
public int allocateUniqueParameterNumber(StructuredQName qName)
Allocate a unique number to a local parameter name. This should only be called on the principal stylesheet module.- Parameters:
qName
- the local parameter name- Returns:
- an integer that uniquely identifies this parameter name within the stylesheet
-
indexNamedTemplate
protected void indexNamedTemplate(Declaration decl) throws XPathException
Add a named template to the index- Parameters:
decl
- the declaration of the Template object- Throws:
XPathException
- if an error occurs
-
getNamedTemplate
public XSLTemplate getNamedTemplate(StructuredQName name)
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.
-
addNamespaceAlias
protected void addNamespaceAlias(Declaration node)
-
getNamespaceAlias
protected NamespaceBinding getNamespaceAlias(java.lang.String uri)
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
protected boolean isAliasResultNamespace(java.lang.String uri)
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()
-
getCollationMap
public CollationMap getCollationMap()
Get the collation map- Returns:
- the CollationMap
-
setCollation
public void setCollation(java.lang.String name, StringCollator collation)
Register a named collation (actually a StringCollator)- Parameters:
name
- the name of the collationcollation
- the StringCollator that implements this collation
-
findCollation
public StringCollator findCollation(java.lang.String name, java.lang.String baseURI)
Find a named collation. Note this method should only be used at compile-time, before declarations have been pre-processed. After that time, use getCollation().- Parameters:
name
- identifies the name of the collation requiredbaseURI
- the base URI to be used for resolving the collation name if it is relative- Returns:
- null if the collation is not found
-
gatherOutputProperties
public java.util.Properties gatherOutputProperties(StructuredQName formatQName) throws XPathException
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
-
compileStylesheet
public void compileStylesheet() throws XPathException
Compile the stylesheet to create an executable.- Throws:
XPathException
- if compilation fails for any reason
-
isImportedSchema
protected boolean isImportedSchema(java.lang.String targetNamespace)
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
protected void addImportedSchema(java.lang.String targetNamespace)
-
getImportedSchemaTable
protected java.util.HashSet<java.lang.String> getImportedSchemaTable()
-
getAttributeSets
protected boolean getAttributeSets(StructuredQName name, java.util.List<Declaration> list) throws XPathException
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.- Returns:
- true if any declarations were found and added to the list; false if none were found
- Throws:
XPathException
- if an error occurs
-
stripsWhitespace
public boolean stripsWhitespace()
Determine whether this stylesheet does any whitespace stripping- Returns:
- true if this stylesheet strips whitespace from source documents
-
setVersion
public void setVersion(java.lang.String version)
Set the value of the version attribute on the xsl:stylesheet element of the principal stylesheet module- Parameters:
version
- the value of the version attribute
-
getVersion
public java.lang.String getVersion()
Get the value of the version attribute on the xsl:stylesheet element of the principal stylesheet module- Returns:
- the value of the version attribute
-
setNeedsDynamicOutputProperties
public void setNeedsDynamicOutputProperties(boolean b)
Say that this stylesheet needs dynamic output properties- Parameters:
b
- true if this stylesheet needs dynamic output properties
-
getCharacterMap
public Declaration getCharacterMap(StructuredQName name)
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
-
allocatePatternSlots
public void allocatePatternSlots(int n)
Ensure there is enough space for local variables or parameters when evaluating the match pattern of template rules- Parameters:
n
- the number of slots to be allocated
-
compileError
protected void compileError(java.lang.String message, java.lang.String errorCode) throws XPathException
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
protected void compileError(XPathException error) throws XPathException
Report an error with diagnostic information- Parameters:
error
- contains information about the error- Throws:
XPathException
- unconditionally, after reporting the error to the ErrorListener
-
-