Package net.sf.saxon.expr.instruct
Class TemplateRule
java.lang.Object
net.sf.saxon.expr.instruct.TemplateRule
- All Implemented Interfaces:
SourceLocator,ExpressionOwner,Location,InstructionInfo,RuleTarget,Locator
public class TemplateRule
extends Object
implements RuleTarget, Location, ExpressionOwner, InstructionInfo
The runtime object corresponding to an xsl:template element in the stylesheet.
Note that the Template object no longer has precedence information associated with it; this is now only in the Rule object that references this Template. This allows two rules to share the same template, with different precedences. This occurs when a stylesheet module is imported more than once, from different places, with different import precedences.
From Saxon 9.7, the old Template class is split into NamedTemplate and TemplateRule.
From Saxon 9.8, a subclass is used in Saxon-EE
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Expressionprotected Patternprotected List<TemplateRule> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(XPathContextMajor context) Process the template, without returning any tail calls.applyLeavingTail(XPathContext context) Process this template, with the possibility of returning a tail call package if the template contains any tail calls that are to be performed by the caller.copy()Create a copy of a template rule.protected voidcopyTo(TemplateRule tr) voidexplainProperties(ExpressionPresenter presenter) voidexport(ExpressionPresenter presenter) Output diagnostic explanation to an ExpressionPresentergetBody()intGet the column number.intintGet the type of construct.intintGet the line number.Get the match pattern used with this templateGet a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.Get an iterator over all the properties available.getProperty(String name) Get the value of a particular property of the instruction.Get the Public IDGet the required type to be returned by this templategetRules()Get the rules that use this template.Get the system ID.booleanAsk whether this template has one or more required parametersvoidEnsure that any first-time initialization has been done.booleanbooleanvoidprepareInitializer(Compilation compilation, ComponentDeclaration decl, StructuredQName modeName) Prepare for JIT compilation.voidregisterRule(Rule rule) Register a rule for which this is the targetGet an immutable copy of this Location object.voidsetBody(Expression body) Set the expression that forms the body of the templatevoidsetChildExpression(Expression expr) voidsetContextItemRequirements(ItemType type, boolean absentFocus) Set the required context item type.voidsetDeclaredStreamable(boolean streamable) Say whether or not this template is declared as streamablevoidsetHasRequiredParams(boolean has) Set whether this template has one or more required parametersvoidsetLineNumber(int line) voidsetMatchPattern(Pattern pattern) Set the match pattern used with this templatevoidsetPackageData(PackageData data) voidsetRequiredType(SequenceType type) Set the required type to be returned by this templatevoidvoidsetSystemId(String id) voidUpdate the properties of template rules that have been marked as slave copies of this one (typically the same template, but in a different mode).
-
Field Details
-
body
-
matchPattern
-
slaveCopies
-
-
Constructor Details
-
TemplateRule
public TemplateRule()Create a template
-
-
Method Details
-
setMatchPattern
Set the match pattern used with this template- Parameters:
pattern- the match pattern (may be null for a named template)
-
getBody
-
setContextItemRequirements
Set the required context item type. Used when there is an xsl:context-item child element- Parameters:
type- the required context item typeabsentFocus- true if the context item is treated as absent even if supplied (use="absent")
-
getComponentKind
public int getComponentKind() -
getMatchPattern
Get the match pattern used with this template- Returns:
- the match pattern, or null if this is a named template with no match pattern. In the case of a template rule whose pattern is a union pattern, this will be the original union pattern; the individual Rule objects contain the branches of the union pattern.
-
setBody
Set the expression that forms the body of the template- Parameters:
body- the body of the template
-
setStackFrameMap
-
getStackFrameMap
-
setHasRequiredParams
public void setHasRequiredParams(boolean has) Set whether this template has one or more required parameters- Parameters:
has- true if the template has at least one required parameter
-
hasRequiredParams
public boolean hasRequiredParams()Ask whether this template has one or more required parameters- Returns:
- true if this template has at least one required parameter
-
setRequiredType
Set the required type to be returned by this template- Parameters:
type- the required type as defined in the "as" attribute on the xsl:template element
-
getRequiredType
Get the required type to be returned by this template- Returns:
- the required type as defined in the "as" attribute on the xsl:template element
-
registerRule
Register a rule for which this is the target- Specified by:
registerRulein interfaceRuleTarget- Parameters:
rule- a rule in which this is the target
-
getRules
Get the rules that use this template. For a template with no match pattern, this will be an empty list. For a union pattern, there will be one rule for each branch of the union.- Returns:
- the rules corresponding to this template.
-
getContainerGranularity
public int getContainerGranularity() -
getPackageData
-
setPackageData
-
getPublicId
Description copied from interface:LocationGet the Public ID- Specified by:
getPublicIdin interfaceLocation- Specified by:
getPublicIdin interfaceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Returns:
- usually null
-
getSystemId
Description copied from interface:LocationGet the system ID. This should be the system identifier of an XML external entity; if a stylesheet module comprises multiple external entities, the distinction should be retained. This means, for example, that an instruction in a stylesheet can have a different system identifier from its parent instruction. However, SAX parsers only provide location information at the element level, so when part of an XPath expression is in a different external entity from other parts of the same expression, this distinction is lost.The system identifier of a node is in general not the same as its base URI. The base URI is affected by xml:base attributes; the system identifier is not.
- Specified by:
getSystemIdin interfaceLocation- Specified by:
getSystemIdin interfaceLocator- Specified by:
getSystemIdin interfaceSourceLocator- Returns:
- the system ID, or null if the information is not available.
-
setSystemId
-
getLineNumber
public int getLineNumber()Description copied from interface:LocationGet the line number. This line number is relative to the external entity identified by the system identifier. Line numbers start at 1. The value may be an approximation; SAX parsers only provide line number information at the level of element nodes.- Specified by:
getLineNumberin interfaceLocation- Specified by:
getLineNumberin interfaceLocator- Specified by:
getLineNumberin interfaceSourceLocator- Returns:
- the line number, or -1 if the information is not available.
-
setLineNumber
public void setLineNumber(int line) -
getColumnNumber
public int getColumnNumber()Description copied from interface:LocationGet the column number. This column number is relative to the line identified by the line number. Column numbers start at 1.- Specified by:
getColumnNumberin interfaceLocation- Specified by:
getColumnNumberin interfaceLocator- Specified by:
getColumnNumberin interfaceSourceLocator- Returns:
- the column number, or -1 if the information is not available.
-
saveLocation
Get an immutable copy of this Location object. By default Location objects may be mutable, so they should not be saved for later use. The result of this operation holds the same location information, but in an immutable form.- Specified by:
saveLocationin interfaceLocation
-
getRequiredContextItemType
-
isAbsentFocus
public boolean isAbsentFocus() -
getLocalParams
-
prepareInitializer
public void prepareInitializer(Compilation compilation, ComponentDeclaration decl, StructuredQName modeName) Prepare for JIT compilation.- Parameters:
compilation- the XSLT compilationdecl- the component declaration of this template rule
-
initialize
Ensure that any first-time initialization has been done. Used in Saxon-EE to do JIT compilation- Throws:
XPathException
-
apply
Process the template, without returning any tail calls. This path is used by xsl:apply-imports and xsl:next-match- Parameters:
context- The dynamic context, giving access to the current node,- Throws:
XPathException- if a dynamic error occurs while evaluating the template
-
applyLeavingTail
Process this template, with the possibility of returning a tail call package if the template contains any tail calls that are to be performed by the caller.- Parameters:
context- the XPath dynamic context- Returns:
- null if the template exited normally; but if it was a tail call, details of the call that hasn't been made yet and needs to be made by the caller
- Throws:
XPathException- if a dynamic error occurs while evaluating the template
-
getConstructType
public int getConstructType()Get the type of construct. This will either be the fingerprint of a standard XSLT instruction name (values inStandardNames: all less than 1024) or it will be a constant in classLocationKind.- Specified by:
getConstructTypein interfaceInstructionInfo- Returns:
- an integer identifying the kind of construct
-
export
Output diagnostic explanation to an ExpressionPresenter- Specified by:
exportin interfaceRuleTarget- Parameters:
presenter- the destination for the explanation- Throws:
XPathException
-
setDeclaredStreamable
public void setDeclaredStreamable(boolean streamable) Say whether or not this template is declared as streamable- Parameters:
streamable- true if the template belongs to a streamable mode; set to false if it does not belong to a streamable mode, or if it is found that the template is not actually streamable, and fallback to non-streaming has been requested.
-
isDeclaredStreamable
public boolean isDeclaredStreamable() -
explainProperties
- Throws:
XPathException
-
getInterpretedBody
-
copy
Create a copy of a template rule. This is needed when copying a rule from the "omniMode" (mode=#all) to a specific mode. Because we want the rules to be chained in the right order within the mode object, we create the copy as soon as we know it is needed. The problem is that at this stage many of the properties of the template rule are still uninitialised. So we mark the new copy as a slave of the original, and at the end of the compilation process we update all the slave copies to match the properties of the original. -
updateSlaveCopies
public void updateSlaveCopies()Update the properties of template rules that have been marked as slave copies of this one (typically the same template, but in a different mode). -
copyTo
-
setChildExpression
- Specified by:
setChildExpressionin interfaceExpressionOwner
-
getObjectName
Description copied from interface:InstructionInfoGet 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.- Specified by:
getObjectNamein interfaceInstructionInfo- Returns:
- the QName of the object declared or manipulated by this instruction or expression
-
getProperty
Description copied from interface:InstructionInfoGet the value of a particular property of the instruction. Properties of XSLT instructions are generally known by the name of the stylesheet attribute that defines them.- Specified by:
getPropertyin interfaceInstructionInfo- Parameters:
name- The name of the required property- Returns:
- The value of the requested property, or null if the property is not available
-
getProperties
Description copied from interface:InstructionInfoGet 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. The iterator may return properties whose value is null.- Specified by:
getPropertiesin interfaceInstructionInfo- Returns:
- an iterator over the properties.
-