net.sf.saxon.style

Class XSLStylesheet

public class XSLStylesheet extends StyleElement

An xsl:stylesheet or xsl:transform element in the stylesheet.
Note this element represents a stylesheet module, not necessarily the whole stylesheet. However, much of the functionality (and the fields) are relevant only to the top-level module.
Field Summary
static intANNOTATION_PRESERVE
static intANNOTATION_STRIP
Executableexec
Method Summary
protected voidaddImportedSchema(String targetNamespace)
protected voidaddNamespaceAlias(XSLNamespaceAlias node)
intallocateGlobalSlot(StructuredQName qName)
Allocate a slot number for a global variable or parameter
voidallocatePatternSlots(int n)
Ensure there is enough space for local variables or parameters when evaluating the match pattern of template rules
intallocateUniqueParameterNumber(StructuredQName qName)
Allocate a unique number to a local parameter name.
Expressioncompile(Executable exec)
Dummy compile() method to satisfy the interface
voidcompileStylesheet()
Compile the stylesheet to create an executable.
voiddeclareXQueryFunction(XQueryFunction function)
Declare an imported XQuery function
protected StringCollatorfindCollation(String name)
Find a named collation.
PropertiesgatherOutputProperties(StructuredQName formatQName)
Create an output properties object representing the xsl:output elements in the stylesheet.
XSLCharacterMapgetCharacterMap(StructuredQName name)
Get a character map, identified by the fingerprint of its name.
CollationMapgetCollationMap()
Get the collation map
intgetDefaultValidation()
Get the value of the default validation attribute
ExecutablegetExecutable()
Get the run-time Executable object
FunctionLibrarygetFunctionLibrary()
Get the function library.
XSLVariableDeclarationgetGlobalVariable(StructuredQName qName)
Get the global variable or parameter with a given name (taking precedence rules into account)
protected HashSet<String>getImportedSchemaTable()
XSLStylesheetgetImporter()
Get the StyleSheet that included or imported this one.
intgetInputTypeAnnotations()
Get the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules.
intgetInputTypeAnnotationsAttribute()
Get the value of the input-type-annotations attribute, for this module alone.
KeyManagergetKeyManager()
Get the KeyManager which handles key definitions
LocationMapgetLocationMap()
Get the locationMap object
intgetMinImportPrecedence()
Get the minimum import precedence of this stylesheet, that is, the lowest precedence of any stylesheet imported by this one
protected intgetNamespaceAlias(short uriCode)
Get the declared namespace alias for a given namespace URI code if there is one.
intgetPrecedence()
Get the import precedence of this stylesheet
PreparedStylesheetgetPreparedStylesheet()
Get the owning PreparedStylesheet object
RuleManagergetRuleManager()
Get the RuleManager which handles template rules
protected ModegetStripperRules()
Get the rules determining which nodes are to be stripped from the tree
ListgetTopLevel()
Get the top level elements in this stylesheet, after applying include/import
protected booleanhasNamespaceAliases()
protected voidindexNamedTemplate(XSLTemplate template)
Add a named template to the index
protected voidindexVariableDeclaration(XSLVariableDeclaration var)
Index a global xsl:variable or xsl:param element
protected booleanisAliasResultNamespace(short uriCode)
Determine if a namespace is included in the result-prefix of a namespace-alias
protected booleanisImportedSchema(String targetNamespace)
Get an imported schema with a given namespace
protected booleanmayContainParam(String attName)
voidprepareAttributes()
Prepare the attributes on the stylesheet element
voidpreprocess()
Preprocess does all the processing possible before the source document is available.
voidprocessAllAttributes()
Process the attributes of every node in the stylesheet
voidsetCollation(String name, StringCollator collation)
Register a named collation (actually a StringCollator)
voidsetImporter(XSLStylesheet importer)
Set the StyleSheet that included or imported this one.
voidsetInputTypeAnnotations(int annotations)
Set the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules.
voidsetMinImportPrecedence(int precedence)
Set the minimum import precedence of this stylesheet, that is, the lowest precedence of any stylesheet imported by this one
voidsetNeedsDynamicOutputProperties(boolean b)
Set that this stylesheet needs dynamic output properties
voidsetPrecedence(int prec)
Set the import precedence of this stylesheet
voidsetPreparedStylesheet(PreparedStylesheet sheet)
Create link to the owning PreparedStylesheet object
voidsetWasIncluded()
Indicate that this stylesheet was included (by its "importer") using an xsl:include statement as distinct from xsl:import
voidspliceIncludes()
Process xsl:include and xsl:import elements.
booleanstripsWhitespace()
Determine whether this stylesheet does any whitespace stripping
voidvalidate()
Validate this element

Field Detail

ANNOTATION_PRESERVE

public static final int ANNOTATION_PRESERVE

ANNOTATION_STRIP

public static final int ANNOTATION_STRIP

exec

Executable exec

Method Detail

addImportedSchema

protected void addImportedSchema(String targetNamespace)

addNamespaceAlias

protected void addNamespaceAlias(XSLNamespaceAlias node)

allocateGlobalSlot

public int allocateGlobalSlot(StructuredQName qName)
Allocate a slot number for a global variable or parameter

Parameters: qName the name of the variable or parameter

Returns: int the allocated slot number

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

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

compile

public Expression compile(Executable exec)
Dummy compile() method to satisfy the interface

compileStylesheet

public void compileStylesheet()
Compile the stylesheet to create an executable.

declareXQueryFunction

public void declareXQueryFunction(XQueryFunction function)
Declare an imported XQuery function

Parameters: function the imported function

findCollation

protected StringCollator findCollation(String name)
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 required

Returns: null if the collation is not found

gatherOutputProperties

public Properties gatherOutputProperties(StructuredQName formatQName)
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

getCharacterMap

public XSLCharacterMap 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

getCollationMap

public CollationMap getCollationMap()
Get the collation map

Returns: the CollationMap

getDefaultValidation

public int getDefaultValidation()
Get the value of the default validation attribute

Returns: the value of the default-validation attribute, as a constant such as STRIP

getExecutable

public Executable getExecutable()
Get the run-time Executable object

getFunctionLibrary

public FunctionLibrary getFunctionLibrary()
Get the function library. Available only on the principal stylesheet module

Returns: the function library

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

getImportedSchemaTable

protected HashSet<String> getImportedSchemaTable()

getImporter

public XSLStylesheet getImporter()
Get the StyleSheet that included or imported this one.

Returns: null if this is the principal stylesheet

getInputTypeAnnotations

public int getInputTypeAnnotations()
Get the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules. The value is an or-ed combination of the two bits ANNOTATION_STRIP and ANNOTATION_PRESERVE

Returns: the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules

getInputTypeAnnotationsAttribute

public int getInputTypeAnnotationsAttribute()
Get the value of the input-type-annotations attribute, for this module alone. The value is an or-ed combination of the two bits ANNOTATION_STRIP and ANNOTATION_PRESERVE

Returns: the value if the input-type-annotations attribute in this stylesheet module

getKeyManager

public KeyManager getKeyManager()
Get the KeyManager which handles key definitions

Returns: the key manager

getLocationMap

public LocationMap getLocationMap()
Get the locationMap object

Returns: the LocationMap

getMinImportPrecedence

public int getMinImportPrecedence()
Get the minimum import precedence of this stylesheet, that is, the lowest precedence of any stylesheet imported by this one

Returns: the minimum precedence of imported stylesheet modules

getNamespaceAlias

protected int getNamespaceAlias(short uriCode)
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: uriCode The code of the uri used in the stylesheet.

Returns: The namespace code to be used (prefix in top half, uri in bottom half): return -1 if no alias is defined

getPrecedence

public int getPrecedence()
Get the import precedence of this stylesheet

getPreparedStylesheet

public PreparedStylesheet getPreparedStylesheet()
Get the owning PreparedStylesheet object

getRuleManager

public RuleManager getRuleManager()
Get the RuleManager which handles template rules

Returns: the template rule manager

getStripperRules

protected Mode getStripperRules()
Get the rules determining which nodes are to be stripped from the tree

Returns: the Mode object holding the whitespace stripping rules. The stripping rules defined in xsl:strip-space are managed in the same way as template rules, hence the use of a special Mode object

getTopLevel

public List getTopLevel()
Get the top level elements in this stylesheet, after applying include/import

Returns: a list of top-level elements in this stylesheet module or in those modules that it includes or imports

hasNamespaceAliases

protected boolean hasNamespaceAliases()

indexNamedTemplate

protected void indexNamedTemplate(XSLTemplate template)
Add a named template to the index

Parameters: template The Template object

Throws: XPathException

indexVariableDeclaration

protected void indexVariableDeclaration(XSLVariableDeclaration var)
Index a global xsl:variable or xsl:param element

Parameters: var The XSLVariable or XSLParam element

Throws: XPathException

isAliasResultNamespace

protected boolean isAliasResultNamespace(short uriCode)
Determine if a namespace is included in the result-prefix of a namespace-alias

Parameters: uriCode the namepool code of the URI

Returns: true if an xsl:namespace-alias has been defined for this namespace URI

isImportedSchema

protected boolean isImportedSchema(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

mayContainParam

protected boolean mayContainParam(String attName)

prepareAttributes

public void prepareAttributes()
Prepare the attributes on the stylesheet element

preprocess

public void 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

processAllAttributes

public void processAllAttributes()
Process the attributes of every node in the stylesheet

setCollation

public void setCollation(String name, StringCollator collation)
Register a named collation (actually a StringCollator)

Parameters: name the name of the collation collation the StringCollator that implements this collation

setImporter

public void setImporter(XSLStylesheet importer)
Set the StyleSheet that included or imported this one.

Parameters: importer the stylesheet module that included or imported this module

setInputTypeAnnotations

public void setInputTypeAnnotations(int annotations)
Set the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules. The value is an or-ed combination of the two bits ANNOTATION_STRIP and ANNOTATION_PRESERVE

Parameters: annotations the value of the input-type-annotations attribute, for this module combined with that of all included/imported modules.

setMinImportPrecedence

public void setMinImportPrecedence(int precedence)
Set the minimum import precedence of this stylesheet, that is, the lowest precedence of any stylesheet imported by this one

Parameters: precedence the precedence of the first stylesheet module that this one imports

setNeedsDynamicOutputProperties

public void setNeedsDynamicOutputProperties(boolean b)
Set that this stylesheet needs dynamic output properties

Parameters: b true if this stylesheet needs dynamic output properties

setPrecedence

public void setPrecedence(int prec)
Set the import precedence of this stylesheet

Parameters: prec the import precedence. Higher numbers indicate higher precedence, but the actual number has no significance

setPreparedStylesheet

public void setPreparedStylesheet(PreparedStylesheet sheet)
Create link to the owning PreparedStylesheet object

Parameters: sheet the PreparedStylesheet

setWasIncluded

public void setWasIncluded()
Indicate that this stylesheet was included (by its "importer") using an xsl:include statement as distinct from xsl:import

spliceIncludes

public void spliceIncludes()
Process xsl:include and xsl:import elements.

stripsWhitespace

public boolean stripsWhitespace()
Determine whether this stylesheet does any whitespace stripping

Returns: true if this stylesheet strips whitespace from source documents

validate

public void validate()
Validate this element