public class TemplateRule extends java.lang.Object implements RuleTarget, Location, ExpressionOwner, TraceableComponent
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
Modifier and Type | Field and Description |
---|---|
protected Expression |
body |
protected Pattern |
matchPattern |
protected java.util.List<TemplateRule> |
slaveCopies |
Constructor and Description |
---|
TemplateRule()
Create a template
|
Modifier and Type | Method and Description |
---|---|
void |
apply(Outputter output,
XPathContextMajor context)
Process the template, without returning any tail calls.
|
TailCall |
applyLeavingTail(Outputter output,
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.
|
TemplateRule |
copy()
Create a copy of a template rule.
|
protected void |
copyTo(TemplateRule tr) |
void |
explainProperties(ExpressionPresenter presenter) |
void |
export(ExpressionPresenter presenter)
Output diagnostic explanation to an ExpressionPresenter
|
void |
gatherProperties(java.util.function.BiConsumer<java.lang.String,java.lang.Object> consumer)
Get the properties of this object to be included in trace messages, by supplying
the property values to a supplied consumer function
|
Expression |
getBody()
Get the expression at the root of the expression tree used to evaluate this construct
|
Expression |
getChildExpression() |
int |
getColumnNumber()
Get the column number.
|
int |
getComponentKind() |
int |
getContainerGranularity() |
Expression |
getInterpretedBody() |
int |
getLineNumber()
Get the line number.
|
java.util.List<LocalParam> |
getLocalParams() |
Location |
getLocation() |
Pattern |
getMatchPattern()
Get the match pattern used with this template
|
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.
|
PackageData |
getPackageData() |
java.lang.String |
getPublicId()
Get the Public ID
|
ItemType |
getRequiredContextItemType() |
SequenceType |
getRequiredType()
Get the required type to be returned by this template
|
java.util.List<Rule> |
getRules()
Get the rules that use this template.
|
SlotManager |
getStackFrameMap() |
java.lang.String |
getSystemId()
Get the system ID.
|
java.lang.String |
getTracingTag()
Get a string to identify the type of component
|
boolean |
hasRequiredParams()
Ask whether this template has one or more required parameters
|
void |
initialize()
Ensure that any first-time initialization has been done.
|
boolean |
isAbsentFocus() |
boolean |
isDeclaredStreamable() |
void |
prepareInitializer(Compilation compilation,
ComponentDeclaration decl,
StructuredQName modeName)
Prepare for JIT compilation.
|
void |
registerRule(Rule rule)
Register a rule for which this is the target
|
Location |
saveLocation()
Get an immutable copy of this Location object.
|
void |
setBody(Expression body)
Set the expression that forms the body of the template
|
void |
setChildExpression(Expression expr) |
void |
setColumnNumber(int col) |
void |
setContextItemRequirements(ItemType type,
boolean absentFocus)
Set the required context item type.
|
void |
setDeclaredStreamable(boolean streamable)
Say whether or not this template is declared as streamable
|
void |
setHasRequiredParams(boolean has)
Set whether this template has one or more required parameters
|
void |
setLineNumber(int line) |
void |
setMatchPattern(Pattern pattern)
Set the match pattern used with this template
|
void |
setPackageData(PackageData data) |
void |
setRequiredType(SequenceType type)
Set the required type to be returned by this template
|
void |
setStackFrameMap(SlotManager map) |
void |
setSystemId(java.lang.String id) |
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).
|
protected Expression body
protected Pattern matchPattern
protected java.util.List<TemplateRule> slaveCopies
public void setMatchPattern(Pattern pattern)
pattern
- the match pattern (may be null for a named template)public Expression getBody()
TraceableComponent
getBody
in interface TraceableComponent
public Expression getChildExpression()
getChildExpression
in interface ExpressionOwner
public Location getLocation()
getLocation
in interface Locatable
public void gatherProperties(java.util.function.BiConsumer<java.lang.String,java.lang.Object> consumer)
gatherProperties
in interface Traceable
consumer
- the function to which the properties should be supplied, as (property name,
value) pairs.public void setContextItemRequirements(ItemType type, boolean absentFocus)
type
- the required context item typeabsentFocus
- true if the context item is treated as absent even if supplied (use="absent")public int getComponentKind()
public Pattern getMatchPattern()
public void setBody(Expression body)
setBody
in interface TraceableComponent
body
- the body of the templatepublic void setStackFrameMap(SlotManager map)
public SlotManager getStackFrameMap()
public void setHasRequiredParams(boolean has)
has
- true if the template has at least one required parameterpublic boolean hasRequiredParams()
public void setRequiredType(SequenceType type)
type
- the required type as defined in the "as" attribute on the xsl:template elementpublic SequenceType getRequiredType()
public void registerRule(Rule rule)
registerRule
in interface RuleTarget
rule
- a rule in which this is the targetpublic java.util.List<Rule> getRules()
public int getContainerGranularity()
public PackageData getPackageData()
public void setPackageData(PackageData data)
public java.lang.String getPublicId()
Location
getPublicId
in interface javax.xml.transform.SourceLocator
getPublicId
in interface Location
getPublicId
in interface org.xml.sax.Locator
public java.lang.String getSystemId()
Location
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.
getSystemId
in interface javax.xml.transform.SourceLocator
getSystemId
in interface Location
getSystemId
in interface org.xml.sax.Locator
public void setSystemId(java.lang.String id)
public int getLineNumber()
Location
getLineNumber
in interface javax.xml.transform.SourceLocator
getLineNumber
in interface Location
getLineNumber
in interface org.xml.sax.Locator
public void setLineNumber(int line)
public void setColumnNumber(int col)
public int getColumnNumber()
Location
getColumnNumber
in interface javax.xml.transform.SourceLocator
getColumnNumber
in interface Location
getColumnNumber
in interface org.xml.sax.Locator
public Location saveLocation()
saveLocation
in interface Location
public ItemType getRequiredContextItemType()
public boolean isAbsentFocus()
public java.util.List<LocalParam> getLocalParams()
public void prepareInitializer(Compilation compilation, ComponentDeclaration decl, StructuredQName modeName)
compilation
- the XSLT compilationdecl
- the component declaration of this template rulemodeName
- the mode namepublic void initialize() throws XPathException
XPathException
- if any error occurspublic void apply(Outputter output, XPathContextMajor context) throws XPathException
output
- the destination for the resultcontext
- The dynamic context, giving access to the current node,XPathException
- if a dynamic error occurs while evaluating
the templatepublic TailCall applyLeavingTail(Outputter output, XPathContext context) throws XPathException
output
- the destination for the resultcontext
- the XPath dynamic contextXPathException
- if a dynamic error occurs while evaluating
the templatepublic void export(ExpressionPresenter presenter) throws XPathException
export
in interface RuleTarget
presenter
- the destination for the explanationXPathException
- if output failspublic void setDeclaredStreamable(boolean streamable)
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.public boolean isDeclaredStreamable()
public void explainProperties(ExpressionPresenter presenter) throws XPathException
XPathException
public Expression getInterpretedBody()
public TemplateRule copy()
public void updateSlaveCopies()
protected void copyTo(TemplateRule tr)
public void setChildExpression(Expression expr)
setChildExpression
in interface ExpressionOwner
public StructuredQName getObjectName()
Traceable
getObjectName
in interface Traceable
public java.lang.String getTracingTag()
TraceableComponent
getTracingTag
in interface TraceableComponent
Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.