net.sf.saxon.style

Class StyleElement

public abstract class StyleElement extends ElementImpl implements Locator, Container, InstructionInfo

Abstract superclass for all element nodes in the stylesheet.
Note: this class implements Locator. The element retains information about its own location in the stylesheet, which is useful when an XSL error is found.
Field Summary
protected StringdefaultCollationName
protected StringdefaultXPathNamespace
protected short[]extensionNamespaces
protected intreportingCircumstances
static intREPORT_ALWAYS
static intREPORT_IF_INSTANTIATED
static intREPORT_UNLESS_FALLBACK_AVAILABLE
static intREPORT_UNLESS_FORWARDS_COMPATIBLE
protected StaticContextstaticContext
protected XPathExceptionvalidationError
protected BigDecimalversion
Constructor Summary
StyleElement()
Constructor
Method Summary
protected intallocateLocationId(String systemId, int lineNumber)
Allocate a location identifier
voidallocatePatternSlots(int slots)
Allocate space for range variables within predicates in the match pattern.
voidallocateSlots(Expression exp)
Allocate slots in the local stack frame to range variables used in an XPath expression
booleanbackwardsCompatibleModeIsEnabled()
Determine whether backwards-compatible mode is enabled for this element
XSLVariableDeclarationbindVariable(StructuredQName qName)
Bind a variable used in this element to the compiled form of the XSLVariable element in which it is declared
voidcheckEmpty()
Convenience method to check that the stylesheet element is empty
protected voidcheckSortComesFirst(boolean sortRequired)
Check that among the children of this element, any xsl:sort elements precede any other elements
voidcheckTopLevel(String errorCode)
Convenience method to check that the stylesheet element is at the top level
protected voidcheckUnknownAttribute(int nc)
Check whether an unknown attribute is permitted.
voidcheckWithinTemplate()
Check that the stylesheet element is within a sequence constructor
abstract Expressioncompile(Executable exec)
Compile the instruction on the stylesheet tree into an executable instruction for use at run-time.
protected voidcompileError(XPathException error)
Report an error with diagnostic information
protected voidcompileError(String message)
Report a static error in the stylesheet
protected voidcompileError(String message, StructuredQName errorCode)
Compile time error, specifying an error code
protected voidcompileError(String message, String errorCode)
Compile time error, specifying an error code
ExpressioncompileSequenceConstructor(Executable exec, SequenceIterator iter, boolean includeParams)
Compile the children of this instruction on the stylesheet tree, adding the subordinate instructions to the parent instruction on the execution tree.
protected voidcompileWarning(String message, StructuredQName errorCode)
protected voidcompileWarning(String message, String errorCode)
protected booleandefinesExcludedNamespace(short uriCode)
Check whether this node excludes a particular namespace from the result.
protected booleandefinesExtensionElement(short uriCode)
Check whether a particular extension element namespace is defined on this node.
protected ExpressionfallbackProcessing(Executable exec, StyleElement instruction)
Perform fallback processing.
voidfixupReferences()
Fix up references from XPath expressions.
booleanforwardsCompatibleModeIsEnabled()
Determine whether forwards-compatible mode is enabled for this element
ListgetAllStylesheetFunctions()
Get a list of all stylesheet functions, excluding any that are masked by one of higher precedence
protected AttributeSet[]getAttributeSets(String use, List list)
Get the list of attribute-sets associated with this element.
StringgetAttributeValue(String clarkName)
Get an attribute value given the Clark name of the attribute (that is, the name in {uri}local format).
intgetColumnNumber(long locationId)
protected ItemTypegetCommonChildItemType()
Get the most general type of item returned by the children of this instruction
intgetConstructType()
Get the type of construct.
intgetContainerGranularity()
Get the granularity of the container.
SlotManagergetContainingSlotManager()
Get the SlotManager for the containing Procedure definition
XSLStylesheetgetContainingStylesheet()
Get the containing XSLStylesheet element
protected StringgetDefaultCollationName()
Get the default collation for this stylesheet element.
protected StringgetDefaultXPathNamespace()
Get the default XPath namespace for elements and types
ExecutablegetExecutable()
intgetHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
protected StyleElementgetLastChildInstruction()
Find the last child instruction of this instruction.
intgetLineNumber(long locationId)
LocationProvidergetLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.
NamespaceResolvergetNamespaceResolver()
Get the namespace context of the instruction.
StructuredQNamegetObjectName()
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.
intgetPrecedence()
Get the import precedence of this stylesheet element.
PreparedStylesheetgetPreparedStylesheet()
Get the PreparedStylesheet object.
XSLStylesheetgetPrincipalStylesheet()
Get the principal XSLStylesheet node.
IteratorgetProperties()
Get an iterator over all the properties available.
ObjectgetProperty(String name)
Get the value of a particular property of the instruction.
protected ItemTypegetReturnedItemType()
Determine the type of item returned by this instruction (only relevant if it is an instruction).
SchemaTypegetSchemaType(String typeAtt)
Get the Schema type definition for a type named in the stylesheet (in a "type" attribute).
StaticContextgetStaticContext()
Get the static context for expressions on this element
XSLFunctiongetStylesheetFunction(StructuredQName qName, int arity)
Get a FunctionCall declared using an xsl:function element in the stylesheet
StringgetSystemId(long locationId)
intgetTypeAnnotation(SchemaType schemaType)
Get the type annotation to use for a given schema type
BigDecimalgetVersion()
Get the numeric value of the version number on this element, or inherited from its ancestors
protected WithParam[]getWithParamInstructions(Executable exec, boolean tunnel, Instruction caller)
Get the list of xsl:with-param elements for a calling element (apply-templates, call-template, apply-imports, next-match).
protected voidindex(XSLStylesheet top)
Method supplied by declaration elements to add themselves to a stylesheet-level index
booleanisExcludedNamespace(short uriCode)
Check whether a namespace uri defines an namespace excluded from the result.
protected booleanisExplaining()
Determine whether saxon:explain has been set to "yes"
booleanisExtensionNamespace(short uriCode)
Check whether a namespace uri defines an extension element.
booleanisInstruction()
Determine whether this node is an instruction.
protected booleanisPermittedChild(StyleElement child)
Check whether a given child is permitted for this element.
protected voidissueWarning(TransformerException error)
Report a warning to the error listener
protected voidissueWarning(String message, SourceLocator locator)
Report a warning to the error listener
booleanisTopLevel()
Test whether this is a top-level element
protected ExpressionmakeAttributeValueTemplate(String expression)
Make an attribute value template in the context of this stylesheet element
ExpressionmakeExpression(String expression)
Compile an XPath expression in the context of this stylesheet element
ExpressionVisitormakeExpressionVisitor()
Make an expression visitor
SavedNamespaceContextmakeNamespaceContext()
Make a NamespaceContext object representing the list of in-scope namespaces.
PatternmakePattern(String pattern)
Make a pattern in the context of this stylesheet element
StructuredQNamemakeQName(String lexicalQName)
Make a structured QName, using this Element as the context for namespace resolution, and registering the code in the namepool.
SequenceTypemakeSequenceType(String sequenceType)
Process an attribute whose value is a SequenceType
protected SortKeyDefinition[]makeSortKeys()
Construct sort keys for a SortedIterator
protected static TraceWrappermakeTraceInstruction(StyleElement source, Expression child)
Create a trace instruction to wrap a real instruction
protected booleanmarkTailCalls()
Mark tail-recursive calls on templates and functions.
protected booleanmayContainFallback()
Determine whether this type of element is allowed to contain an xsl:fallback instruction.
protected booleanmayContainParam(String attName)
Determine whether this type of element is allowed to contain an xsl:param element
protected booleanmayContainSequenceConstructor()
Determine whether this type of element is allowed to contain a sequence constructor
voidpostValidate()
Hook to allow additional validation of a parent element immediately after its children have been validated.
protected abstract voidprepareAttributes()
Set the attribute list for the element.
protected voidprocessAllAttributes()
Process the attributes of this element and all its children
protected voidprocessAttributes()
Process the attribute list for the element.
protected voidprocessDefaultCollationAttribute(String ns)
Process the [xsl:]default-xpath-namespace attribute if there is one
protected voidprocessDefaultXPathNamespaceAttribute(String ns)
Process the [xsl:]xpath-default-namespace attribute if there is one
protected voidprocessExcludedNamespaces(String ns)
Process the [xsl:]exclude-result-prefixes attribute if there is one
protected voidprocessExtensionElementAttribute(String ns)
Process the [xsl:]extension-element-prefixes attribute if there is one
voidprocessStandardAttributes(String namespace)
Process the standard attributes such as [xsl:]default-collation
protected voidprocessVersionAttribute(String ns)
Process the [xsl:]version attribute if there is one
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
voidreportAbsence(String attribute)
Convenience method to report the absence of a mandatory attribute
protected booleanseesAvuncularVariables()
Ask whether variables declared in an "uncle" element are visible.
voidsetObjectName(StructuredQName qName)
Set the object name, for example the name of a function, variable, or template declared on this element
voidsetValidationError(TransformerException reason, int circumstances)
Set a validation error.
voidsubstituteFor(StyleElement temp)
Make this node a substitute for a temporary one previously added to the tree.
ExpressiontypeCheck(String name, Expression exp)
Type-check an expression.
PatterntypeCheck(String name, Pattern pattern)
Type-check a pattern.
protected voidundeclaredNamespaceError(String prefix, String errorCode)
voidvalidate()
Check that the stylesheet element is valid.
protected voidvalidateChildren()
Validate the children of this node, recursively.
voidvalidateSubtree()
Recursive walk through the stylesheet to validate all nodes

Field Detail

defaultCollationName

protected String defaultCollationName

defaultXPathNamespace

protected String defaultXPathNamespace

extensionNamespaces

protected short[] extensionNamespaces

reportingCircumstances

protected int reportingCircumstances

REPORT_ALWAYS

public static final int REPORT_ALWAYS

REPORT_IF_INSTANTIATED

public static final int REPORT_IF_INSTANTIATED

REPORT_UNLESS_FALLBACK_AVAILABLE

public static final int REPORT_UNLESS_FALLBACK_AVAILABLE

REPORT_UNLESS_FORWARDS_COMPATIBLE

public static final int REPORT_UNLESS_FORWARDS_COMPATIBLE

staticContext

protected StaticContext staticContext

validationError

protected XPathException validationError

version

protected BigDecimal version

Constructor Detail

StyleElement

public StyleElement()
Constructor

Method Detail

allocateLocationId

protected int allocateLocationId(String systemId, int lineNumber)
Allocate a location identifier

Parameters: systemId identifies the module containing the instruction lineNumber the line number of the instruction

Returns: an integer location ID which can be used to report the location of the instruction, by reference to a LocationProvider

allocatePatternSlots

public void allocatePatternSlots(int slots)
Allocate space for range variables within predicates in the match pattern. The xsl:template element has no XPath expressions among its attributes, so if this method is called on this object it can only be because there are variables used in the match pattern. We work out how many slots are needed for the match pattern in each template rule, and then apply-templates can allocate a stack frame that is large enough for the most demanding match pattern in the entire stylesheet.

Parameters: slots the number of slots required

allocateSlots

public void allocateSlots(Expression exp)
Allocate slots in the local stack frame to range variables used in an XPath expression

Parameters: exp the XPath expression for which slots are to be allocated

backwardsCompatibleModeIsEnabled

public boolean backwardsCompatibleModeIsEnabled()
Determine whether backwards-compatible mode is enabled for this element

Returns: true if backwards compatable mode is enabled, that is, if this or an enclosing element specifies [xsl:]version="1.0"

bindVariable

public XSLVariableDeclaration bindVariable(StructuredQName qName)
Bind a variable used in this element to the compiled form of the XSLVariable element in which it is declared

Parameters: qName The name of the variable

Returns: the XSLVariableDeclaration (that is, an xsl:variable or xsl:param instruction) for the variable, or null if no declaration of the variable can be found

checkEmpty

public void checkEmpty()
Convenience method to check that the stylesheet element is empty

Throws: XPathException if it is not empty

checkSortComesFirst

protected void checkSortComesFirst(boolean sortRequired)
Check that among the children of this element, any xsl:sort elements precede any other elements

Parameters: sortRequired true if there must be at least one xsl:sort element

Throws: XPathException if invalid

checkTopLevel

public void checkTopLevel(String errorCode)
Convenience method to check that the stylesheet element is at the top level

Parameters: errorCode the error to throw if it is not at the top level; defaults to XTSE0010 if the value is null

Throws: XPathException if not at top level

checkUnknownAttribute

protected void checkUnknownAttribute(int nc)
Check whether an unknown attribute is permitted.

Parameters: nc The name code of the attribute name

Throws: XPathException (and reports the error) if this is an attribute that is not permitted on the containing element

checkWithinTemplate

public void checkWithinTemplate()
Check that the stylesheet element is within a sequence constructor

Throws: XPathException if not within a sequence constructor

compile

public abstract Expression compile(Executable exec)
Compile the instruction on the stylesheet tree into an executable instruction for use at run-time.

Parameters: exec the Executable

Returns: either a ComputedExpression, or null. The value null is returned when compiling an instruction that returns a no-op, or when compiling a top-level object such as an xsl:template that compiles into something other than an instruction.

compileError

protected void compileError(XPathException error)
Report an error with diagnostic information

Parameters: error contains information about the error

Throws: XPathException always, after reporting the error to the ErrorListener

compileError

protected void compileError(String message)
Report a static error in the stylesheet

Parameters: message the error message

Throws: XPathException always, after reporting the error to the ErrorListener

compileError

protected void compileError(String message, StructuredQName errorCode)
Compile time error, specifying an error code

Parameters: message the error message errorCode the error code. May be null if not known or not defined

Throws: XPathException

compileError

protected void compileError(String message, String errorCode)
Compile time error, specifying an error code

Parameters: message the error message errorCode the error code. May be null if not known or not defined

Throws: XPathException

compileSequenceConstructor

public Expression compileSequenceConstructor(Executable exec, SequenceIterator iter, boolean includeParams)
Compile the children of this instruction on the stylesheet tree, adding the subordinate instructions to the parent instruction on the execution tree.

Parameters: exec the Executable iter Iterator over the children. This is used in the case where there are children that are not part of the sequence constructor, for example the xsl:sort children of xsl:for-each; the iterator can be positioned past such elements. includeParams true if xsl:param elements are to be treated as child instructions (true for templates but not for functions)

Returns: an Expression tree representing the children of this instruction

compileWarning

protected void compileWarning(String message, StructuredQName errorCode)

compileWarning

protected void compileWarning(String message, String errorCode)

definesExcludedNamespace

protected boolean definesExcludedNamespace(short uriCode)
Check whether this node excludes a particular namespace from the result. This method checks this node only, not the ancestor nodes.

Parameters: uriCode the code of the namespace URI being tested

Returns: true if the namespace is excluded by virtue of an [xsl:]exclude-result-prefixes attribute

definesExtensionElement

protected boolean definesExtensionElement(short uriCode)
Check whether a particular extension element namespace is defined on this node. This checks this node only, not the ancestor nodes. The implementation checks whether the prefix is included in the [xsl:]extension-element-prefixes attribute.

Parameters: uriCode the namespace URI code being tested

Returns: true if this namespace is defined on this element as an extension element namespace

fallbackProcessing

protected Expression fallbackProcessing(Executable exec, StyleElement instruction)
Perform fallback processing. Generate fallback code for an extension instruction that is not recognized by the implementation.

Parameters: exec the Executable instruction The unknown extension instruction

Returns: the expression tree representing the fallback code

fixupReferences

public void fixupReferences()
Fix up references from XPath expressions. Overridden for function declarations and variable declarations

forwardsCompatibleModeIsEnabled

public boolean forwardsCompatibleModeIsEnabled()
Determine whether forwards-compatible mode is enabled for this element

Returns: true if forwards-compatible mode is enabled

getAllStylesheetFunctions

public List getAllStylesheetFunctions()
Get a list of all stylesheet functions, excluding any that are masked by one of higher precedence

Returns: a list of all stylesheet functions. The members of the list are instances of class XSLFunction

getAttributeSets

protected AttributeSet[] getAttributeSets(String use, List list)
Get the list of attribute-sets associated with this element. This is used for xsl:element, xsl:copy, xsl:attribute-set, and on literal result elements

Parameters: use the original value of the [xsl:]use-attribute-sets attribute list an empty list to hold the list of XSLAttributeSet elements in the stylesheet tree. Or null, if these are not required.

Returns: an array of AttributeList instructions representing the compiled attribute sets

getAttributeValue

public String getAttributeValue(String clarkName)
Get an attribute value given the Clark name of the attribute (that is, the name in {uri}local format).

Parameters: clarkName the name of the attribute in {uri}local format

Returns: the value of the attribute if it exists, or null otherwise

getColumnNumber

public int getColumnNumber(long locationId)

getCommonChildItemType

protected ItemType getCommonChildItemType()
Get the most general type of item returned by the children of this instruction

Returns: the lowest common supertype of the item types returned by the children

getConstructType

public int getConstructType()
Get the type of construct. This will be a constant in class Location. This method is part of the InstructionInfo interface

getContainerGranularity

public int getContainerGranularity()
Get the granularity of the container.

Returns: 0 for a temporary container created during parsing; 1 for a container that operates at the level of an XPath expression; 2 for a container at the level of a global function or template

getContainingSlotManager

public SlotManager getContainingSlotManager()
Get the SlotManager for the containing Procedure definition

Returns: the SlotManager associated with the containing Function, Template, etc, or null if there is no such containing Function, Template etc.

getContainingStylesheet

public XSLStylesheet getContainingStylesheet()
Get the containing XSLStylesheet element

Returns: the XSLStylesheet element representing the outermost element of the containing stylesheet module. Exceptionally, return null if there is no containing XSLStylesheet element

getDefaultCollationName

protected String getDefaultCollationName()
Get the default collation for this stylesheet element. If no default collation is specified in the stylesheet, return the Unicode codepoint collation name.

Returns: the name of the default collation

getDefaultXPathNamespace

protected String getDefaultXPathNamespace()
Get the default XPath namespace for elements and types

Returns: the default namespace for elements and types. Return NULL for the non-namespace

getExecutable

public Executable getExecutable()

getHostLanguage

public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container

Returns: typically XSLT or XQUERY

getLastChildInstruction

protected StyleElement getLastChildInstruction()
Find the last child instruction of this instruction. Returns null if there are no child instructions, or if the last child is a text node.

Returns: the last child instruction, or null if there are no child instructions

getLineNumber

public int getLineNumber(long locationId)

getLocationProvider

public LocationProvider getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.

getNamespaceResolver

public NamespaceResolver getNamespaceResolver()
Get the namespace context of the instruction.

Returns: the namespace context. This method does not make a copy of the namespace context, so a reference to the returned NamespaceResolver will lock the stylesheet tree in memory.

getObjectName

public StructuredQName getObjectName()
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. This is used only where the name is known statically. If there is no name, the value will be null.

Returns: the name of the object declared in this element, if any

getPrecedence

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

Returns: the import precedence. The actual numeric value is arbitrary, but a higher number indicates a higher precedence.

getPreparedStylesheet

public PreparedStylesheet getPreparedStylesheet()
Get the PreparedStylesheet object.

Returns: the PreparedStylesheet to which this stylesheet element belongs. Exceptionally (with early errors in a simplified stylesheet module) return null.

getPrincipalStylesheet

public XSLStylesheet getPrincipalStylesheet()
Get the principal XSLStylesheet node. This gets the principal style sheet, i.e. the one originally loaded, that forms the root of the import/include tree

Returns: the xsl:stylesheet element at the root of the principal stylesheet module. Exceptionally (with early errors in a simplified stylesheet module) return null.

getProperties

public Iterator getProperties()
Get an iterator over all the properties available. The values returned by the iterator will be of type String, and each string can be supplied as input to the getProperty() method to retrieve the value of the property.

getProperty

public Object getProperty(String name)
Get the value of a particular property of the instruction. This is part of the InstructionInfo interface for run-time tracing and debugging. The properties available include all the attributes of the source instruction (named by the attribute name): these are all provided as string values.

Parameters: name The name of the required property

Returns: The value of the requested property, or null if the property is not available

getReturnedItemType

protected ItemType getReturnedItemType()
Determine the type of item returned by this instruction (only relevant if it is an instruction). Default implementation returns Type.ITEM, indicating that we don't know, it might be anything. Returns null in the case of an element such as xsl:sort or xsl:variable that can appear in a sequence constructor but contributes nothing to the result sequence.

Returns: the item type returned

getSchemaType

public SchemaType getSchemaType(String typeAtt)
Get the Schema type definition for a type named in the stylesheet (in a "type" attribute).

Parameters: typeAtt the value of the type attribute

Returns: the corresponding schema type

Throws: XPathException if the type is not declared in an imported schema, or is not a built-in type

getStaticContext

public StaticContext getStaticContext()
Get the static context for expressions on this element

Returns: the static context

getStylesheetFunction

public XSLFunction getStylesheetFunction(StructuredQName qName, int arity)
Get a FunctionCall declared using an xsl:function element in the stylesheet

Parameters: qName the name of the function arity the number of arguments in the function call. The value -1 indicates that any arity will do (this is used to support the function-available() function).

Returns: the XSLFunction object representing the function declaration in the stylesheet, or null if no such function is defined.

getSystemId

public String getSystemId(long locationId)

getTypeAnnotation

public int getTypeAnnotation(SchemaType schemaType)
Get the type annotation to use for a given schema type

Parameters: schemaType the schema type

Returns: the corresponding numeric type annotation

getVersion

public BigDecimal getVersion()
Get the numeric value of the version number on this element, or inherited from its ancestors

Returns: the version number as a decimal

getWithParamInstructions

protected WithParam[] getWithParamInstructions(Executable exec, boolean tunnel, Instruction caller)
Get the list of xsl:with-param elements for a calling element (apply-templates, call-template, apply-imports, next-match). This method can be used to get either the tunnel parameters, or the non-tunnel parameters.

Parameters: exec the Executable tunnel true if the tunnel="yes" parameters are wanted, false to get caller the calling instruction (for example xsl:apply-templates

Returns: an array of WithParam objects for either the ordinary parameters or the tunnel parameters

index

protected void index(XSLStylesheet top)
Method supplied by declaration elements to add themselves to a stylesheet-level index

Parameters: top the outermost XSLStylesheet element

isExcludedNamespace

public boolean isExcludedNamespace(short uriCode)
Check whether a namespace uri defines an namespace excluded from the result. This checks whether the namespace is defined as an excluded namespace on this or any ancestor node.

Parameters: uriCode the code of the namespace URI being tested

Returns: true if this namespace URI is a namespace excluded by virtue of exclude-result-prefixes on this element or on an ancestor element

isExplaining

protected boolean isExplaining()
Determine whether saxon:explain has been set to "yes"

Returns: true if saxon:explain has been set to "yes" on this element

isExtensionNamespace

public boolean isExtensionNamespace(short uriCode)
Check whether a namespace uri defines an extension element. This checks whether the namespace is defined as an extension namespace on this or any ancestor node.

Parameters: uriCode the namespace URI code being tested

Returns: true if the URI is an extension element namespace URI

isInstruction

public boolean isInstruction()
Determine whether this node is an instruction. The default implementation says it isn't.

Returns: true if this element is an instruction

isPermittedChild

protected boolean isPermittedChild(StyleElement child)
Check whether a given child is permitted for this element. This method is used when a non-instruction child element such as xsl:sort is encountered in a context where instructions would normally be expected.

Parameters: child the child that may or may not be permitted

Returns: true if the child is permitted.

issueWarning

protected void issueWarning(TransformerException error)
Report a warning to the error listener

Parameters: error an exception containing the warning text

issueWarning

protected void issueWarning(String message, SourceLocator locator)
Report a warning to the error listener

Parameters: message the warning message text locator the location of the problem in the source stylesheet

isTopLevel

public boolean isTopLevel()
Test whether this is a top-level element

Returns: true if the element is a child of the xsl:stylesheet element

makeAttributeValueTemplate

protected Expression makeAttributeValueTemplate(String expression)
Make an attribute value template in the context of this stylesheet element

Parameters: expression the source text of the attribute value template

Returns: a compiled XPath expression that computes the value of the attribute (including concatenating the results of embedded expressions with any surrounding fixed text)

makeExpression

public Expression makeExpression(String expression)
Compile an XPath expression in the context of this stylesheet element

Parameters: expression the source text of the XPath expression

Returns: the compiled expression tree for the XPath expression

makeExpressionVisitor

public ExpressionVisitor makeExpressionVisitor()
Make an expression visitor

Returns: the expression visitor

makeNamespaceContext

public SavedNamespaceContext makeNamespaceContext()
Make a NamespaceContext object representing the list of in-scope namespaces. This will be a copy of the namespace context with no references to objects in the stylesheet tree, so that it can be kept until run-time without locking the tree down in memory.

Returns: a copy of the namespace context

makePattern

public Pattern makePattern(String pattern)
Make a pattern in the context of this stylesheet element

Parameters: pattern the source text of the pattern

Returns: the compiled pattern

makeQName

public final StructuredQName makeQName(String lexicalQName)
Make a structured QName, using this Element as the context for namespace resolution, and registering the code in the namepool. If the name is unprefixed, the default namespace is not used.

Parameters: lexicalQName The lexical QName as written, in the form "[prefix:]localname". The name must have already been validated as a syntactically-correct QName. Leading and trailing whitespace will be trimmed

Returns: the StructuredQName representation of this lexical QName

Throws: XPathException if the qname is not a lexically-valid QName, or if the name is in a reserved namespace. NamespaceException if the prefix of the qname has not been declared

makeSequenceType

public SequenceType makeSequenceType(String sequenceType)
Process an attribute whose value is a SequenceType

Parameters: sequenceType the source text of the attribute

Returns: the processed sequence type

Throws: XPathException if the syntax is invalid or for example if it refers to a type that is not in the static context

makeSortKeys

protected SortKeyDefinition[] makeSortKeys()
Construct sort keys for a SortedIterator

Returns: an array of SortKeyDefinition objects if there are any sort keys; or null if there are none.

makeTraceInstruction

protected static TraceWrapper makeTraceInstruction(StyleElement source, Expression child)
Create a trace instruction to wrap a real instruction

Parameters: source the parent element child the compiled expression tree for the instruction to be traced

Returns: a wrapper instruction that performs the tracing (if activated at run-time)

markTailCalls

protected boolean markTailCalls()
Mark tail-recursive calls on templates and functions. For most instructions, this returns false.

Returns: true if one or more tail calls were identified

mayContainFallback

protected boolean mayContainFallback()
Determine whether this type of element is allowed to contain an xsl:fallback instruction. Note that this is only relevant if the element is an instruction.

Returns: true if this element is allowed to contain an xsl:fallback

mayContainParam

protected boolean mayContainParam(String attName)
Determine whether this type of element is allowed to contain an xsl:param element

Parameters: attName if null, the method tests whether an xsl:param child is allowed. If non-null, it tests whether an xsl:param child with the given attribute name is allowed

Returns: true if this element is allowed to contain an xsl:param

mayContainSequenceConstructor

protected boolean mayContainSequenceConstructor()
Determine whether this type of element is allowed to contain a sequence constructor

Returns: true if this instruction is allowed to contain a sequence constructor

postValidate

public void postValidate()
Hook to allow additional validation of a parent element immediately after its children have been validated.

prepareAttributes

protected abstract void prepareAttributes()
Set the attribute list for the element. This is called to process the attributes (note the distinction from processAttributes in the superclass). Must be supplied in a subclass

processAllAttributes

protected void processAllAttributes()
Process the attributes of this element and all its children

Throws: XPathException in the event of a static error being detected

processAttributes

protected final void processAttributes()
Process the attribute list for the element. This is a wrapper method that calls prepareAttributes (provided in the subclass) and traps any exceptions

processDefaultCollationAttribute

protected void processDefaultCollationAttribute(String ns)
Process the [xsl:]default-xpath-namespace attribute if there is one

Parameters: ns the namespace of the attribute required, either the XSLT namespace or ""

processDefaultXPathNamespaceAttribute

protected void processDefaultXPathNamespaceAttribute(String ns)
Process the [xsl:]xpath-default-namespace attribute if there is one

Parameters: ns the namespace URI of the attribute required (the default namespace or the XSLT namespace.)

processExcludedNamespaces

protected void processExcludedNamespaces(String ns)
Process the [xsl:]exclude-result-prefixes attribute if there is one

Parameters: ns the namespace URI of the attribute required, either the XSLT namespace or ""

processExtensionElementAttribute

protected void processExtensionElementAttribute(String ns)
Process the [xsl:]extension-element-prefixes attribute if there is one

Parameters: ns the namespace URI of the attribute - either the XSLT namespace or "" for the null namespace

processStandardAttributes

public void processStandardAttributes(String namespace)
Process the standard attributes such as [xsl:]default-collation

Parameters: namespace either "" to find the attributes in the null namespace, or NamespaceConstant.XSLT to find them in the XSLT namespace

processVersionAttribute

protected void processVersionAttribute(String ns)
Process the [xsl:]version attribute if there is one

Parameters: ns the namespace URI of the attribute required, either the XSLT namespace or ""

replaceSubExpression

public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression

Parameters: original the original subexpression replacement the replacement subexpression

Returns: true if the original subexpression is found

reportAbsence

public void reportAbsence(String attribute)
Convenience method to report the absence of a mandatory attribute

Parameters: attribute the name of the attribute whose absence is to be reported

Throws: XPathException if the attribute is missing

seesAvuncularVariables

protected boolean seesAvuncularVariables()
Ask whether variables declared in an "uncle" element are visible.

Returns: true for all elements except xsl:fallback and saxon:catch

setObjectName

public void setObjectName(StructuredQName qName)
Set the object name, for example the name of a function, variable, or template declared on this element

Parameters: qName the object name as a QName

setValidationError

public void setValidationError(TransformerException reason, int circumstances)
Set a validation error. This is an error detected during construction of this element on the stylesheet, but which is not to be reported until later.

Parameters: reason the details of the error circumstances a code identifying the circumstances under which the error is to be reported

substituteFor

public void substituteFor(StyleElement temp)
Make this node a substitute for a temporary one previously added to the tree. See StyleNodeFactory for details. "A node like the other one in all things but its class". Note that at this stage, the node will not yet be known to its parent, though it will contain a reference to its parent; and it will have no children.

Parameters: temp the element which this one is substituting for

typeCheck

public Expression typeCheck(String name, Expression exp)
Type-check an expression. This is called to check each expression while the containing instruction is being validated. It is not just a static type-check, it also adds code to perform any necessary run-time type checking and/or conversion.

Parameters: name the name of the attribute containing the expression to be checked (used for diagnostics) exp the expression to be checked

Returns: the (possibly rewritten) expression after type checking

typeCheck

public Pattern typeCheck(String name, Pattern pattern)
Type-check a pattern. This is called to check each pattern while the containing instruction is being validated. It is not just a static type-check, it also adds code to perform any necessary run-time type checking and/or conversion.

Parameters: name the name of the attribute holding the pattern, for example "match": used in diagnostics pattern the compiled pattern

Returns: the original pattern, or a substitute pattern if it has been rewritten

undeclaredNamespaceError

protected void undeclaredNamespaceError(String prefix, String errorCode)

validate

public void validate()
Check that the stylesheet element is valid. This is called once for each element, after the entire tree has been built. As well as validation, it can perform first-time initialisation. The default implementation does nothing; it is normally overriden in subclasses.

validateChildren

protected void validateChildren()
Validate the children of this node, recursively. Overridden for top-level data elements.

validateSubtree

public void validateSubtree()
Recursive walk through the stylesheet to validate all nodes