Class CallTemplate
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.instruct.Instruction
-
- net.sf.saxon.expr.instruct.CallTemplate
-
- All Implemented Interfaces:
ComponentInvocation
,ContextOriginator
,ExportAgent
,ITemplateCall
,Locatable
,IdentityComparable
,Traceable
public class CallTemplate extends Instruction implements ITemplateCall, ComponentInvocation
Instruction representing an xsl:call-template element in the stylesheet.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CallTemplate.CallTemplateElaborator
static class
CallTemplate.CallTemplatePackage
A CallTemplatePackage is an object that encapsulates the name of a template to be called, the parameters to be supplied, and the execution context.
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description CallTemplate(NamedTemplate template, StructuredQName calledTemplateName, boolean useTailRecursion, boolean inStreamable)
Construct a CallTemplate instruction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
computeCardinality()
Get the cardinality of the sequence returned by evaluating this instructionExpression
copy(RebindingMap rebindings)
Copy an expression.void
export(ExpressionPresenter out)
Export of expression structure.WithParam[]
getActualParams()
Get the actual parameters passed to the called templateint
getBindingSlot()
Get the binding slot to be used.StructuredQName
getCalledTemplateName()
Get the name (QName) of the template being calledElaborator
getElaborator()
Make an elaborator for this expressionComponent
getFixedTarget()
Get the target component if this is known in advance, that is, if the target component is private or final, or in some other cases such as xsl:original.int
getInstructionNameCode()
Return the name of this instruction.int
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.ItemType
getItemType()
Get the item type of the items returned by evaluating this instructionStructuredQName
getObjectName()
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.java.lang.String
getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expressionSymbolicName
getSymbolicName()
Get the symbolic name of the template being called.Component
getTarget()
NamedTemplate
getTargetTemplate()
Get the target templateWithParam[]
getTunnelParams()
Get the tunnel parameters passed to the called templateboolean
mayCreateNewNodes()
Determine whether this instruction creates new nodes.java.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.Expression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform optimisation of an expression and its subexpressions.void
process(Outputter output, XPathContext context)
Process this instruction, without leaving any tail calls.void
setActualParameters(WithParam[] actualParams, WithParam[] tunnelParams)
Set the actual parameters on the callvoid
setBindingSlot(int slot)
Set the binding slot to be used.void
setTailRecursive(boolean tailRecursive)
Mark the instruction as tail-recursive (or not)void
setTargetTemplate(NamedTemplate target)
Set the target templateExpression
simplify()
Simplify an expression.java.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesjava.lang.String
toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.Expression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform type checking of an expression and its subexpressions.boolean
usesTailRecursion()
Ask whether this is a tail call-
Methods inherited from class net.sf.saxon.expr.instruct.Instruction
alwaysCreatesNewNodes, assembleParams, assembleTunnelParams, computeSpecialProperties, dynamicError, evaluateAsString, evaluateItem, getExpressionName, getImplementationMethod, getNetCost, getSourceLocator, isInstruction, isXSLT, iterate, someOperandCreatesNewNodes
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getLocalRetainedStaticContext, getLocation, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
CallTemplate
public CallTemplate(NamedTemplate template, StructuredQName calledTemplateName, boolean useTailRecursion, boolean inStreamable)
Construct a CallTemplate instruction.- Parameters:
template
- the template to be called. This is provisional, and applies only if the template is not overridden in another package; the template supplied will be the one with matching name in the same package. Null in the case of saxon:call-template, and also in the case where the supplied name is xsl:originalcalledTemplateName
- the name of the template to be called; null in the case of saxon:call-template where this is established dynamicallyuseTailRecursion
- true if the call is potentially tail recursive where the name of the called template is to be calculated dynamicallyinStreamable
- true if the call-template instruction appears within a construct that is declared streamable, for example a streamable template rule
-
-
Method Detail
-
setActualParameters
public void setActualParameters(WithParam[] actualParams, WithParam[] tunnelParams)
Set the actual parameters on the call- Parameters:
actualParams
- the parameters that are not tunnel parameterstunnelParams
- the tunnel parameters
-
setTailRecursive
public void setTailRecursive(boolean tailRecursive)
Mark the instruction as tail-recursive (or not)- Parameters:
tailRecursive
- true if the call appears in a tail position
-
getCalledTemplateName
public StructuredQName getCalledTemplateName()
Get the name (QName) of the template being called- Returns:
- the name of the target template
-
getSymbolicName
public SymbolicName getSymbolicName()
Get the symbolic name of the template being called. This is essentially the component kind (template) plus the QName of the target template- Specified by:
getSymbolicName
in interfaceComponentInvocation
- Returns:
- the symbolic name of the target template, or null in the case of saxon:call-template where the name is defined dynamically
-
getTarget
public Component getTarget()
-
getFixedTarget
public Component getFixedTarget()
Description copied from interface:ComponentInvocation
Get the target component if this is known in advance, that is, if the target component is private or final, or in some other cases such as xsl:original. Otherwise, return null.- Specified by:
getFixedTarget
in interfaceComponentInvocation
- Returns:
- the bound component if the binding has been fixed
-
getActualParams
public WithParam[] getActualParams()
Get the actual parameters passed to the called template- Specified by:
getActualParams
in interfaceITemplateCall
- Returns:
- the non-tunnel parameters
-
getTunnelParams
public WithParam[] getTunnelParams()
Get the tunnel parameters passed to the called template- Specified by:
getTunnelParams
in interfaceITemplateCall
- Returns:
- the tunnel parameters
-
setTargetTemplate
public void setTargetTemplate(NamedTemplate target)
Set the target template- Parameters:
target
- the target template
-
getTargetTemplate
public NamedTemplate getTargetTemplate()
Get the target template- Returns:
- the target template
-
usesTailRecursion
public boolean usesTailRecursion()
Ask whether this is a tail call- Returns:
- true if this is a tail call
-
getInstructionNameCode
public int getInstructionNameCode()
Return the name of this instruction.- Overrides:
getInstructionNameCode
in classInstruction
- Returns:
- a code identifying the instruction: typically but not always the fingerprint of a name in the XSLT namespace
-
setBindingSlot
public void setBindingSlot(int slot)
Set the binding slot to be used. This is the offset within the binding vector of the containing component where the actual target template is to be found. The target template is not held directly in the CallTemplate instruction itself because it can be overridden in a using package.- Specified by:
setBindingSlot
in interfaceComponentInvocation
- Parameters:
slot
- the offset in the binding vector of the containing package where the target template can be found.
-
getBindingSlot
public int getBindingSlot()
Get the binding slot to be used. This is the offset within the binding vector of the containing component where the actual target template is to be found.- Specified by:
getBindingSlot
in interfaceComponentInvocation
- Returns:
- the offset in the binding vector of the containing package where the target template can be found.
-
simplify
public Expression simplify() throws XPathException
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression).- Overrides:
simplify
in classExpression
- Returns:
- the simplified expression
- Throws:
XPathException
- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Description copied from class:Expression
Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
- Overrides:
typeCheck
in classExpression
- Parameters:
visitor
- an expression visitorcontextInfo
- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Description copied from class:Expression
Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimize
in classExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
computeCardinality
protected int computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction- Overrides:
computeCardinality
in classInstruction
- Returns:
- the static cardinality
-
getItemType
public ItemType getItemType()
Get the item type of the items returned by evaluating this instruction- Overrides:
getItemType
in classInstruction
- Returns:
- the static item type of the instruction
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- Variables that need to be re-bound- Returns:
- the copy of the original expression
-
getIntrinsicDependencies
public int getIntrinsicDependencies()
Description copied from class:Expression
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".- Overrides:
getIntrinsicDependencies
in classExpression
- Returns:
- an integer containing bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
-
mayCreateNewNodes
public final boolean mayCreateNewNodes()
Determine whether this instruction creates new nodes. This implementation currently returns true unconditionally.- Overrides:
mayCreateNewNodes
in classInstruction
- Returns:
- true if the instruction creates new nodes under some input conditions (or if it can't be proved that it doesn't)
-
operands
public java.lang.Iterable<Operand> operands()
Description copied from class:Expression
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.
- Specified by:
operands
in classInstruction
- Returns:
- an iterator containing the sub-expressions of this expression
-
process
public void process(Outputter output, XPathContext context) throws XPathException
Process this instruction, without leaving any tail calls.- Overrides:
process
in classInstruction
- Parameters:
output
- the destination for the resultcontext
- the dynamic context for this transformation- Throws:
XPathException
- if a dynamic error occurs
-
getObjectName
public StructuredQName getObjectName()
Description copied from interface:Traceable
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.- Specified by:
getObjectName
in interfaceTraceable
- Overrides:
getObjectName
in classExpression
- Returns:
- the QName of the object declared or manipulated by this instruction or expression
-
export
public void export(ExpressionPresenter out) throws XPathException
Export of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classExpression
- Parameters:
out
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
toString
public java.lang.String toString()
Description copied from class:Expression
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression. The expression produced should be equivalent to the original making certain assumptions about the static context. In general the expansion will make no assumptions about namespace bindings, except that (a) the prefix "xs" is used to refer to the XML Schema namespace, and (b) the default function namespace is assumed to be the "fn" namespace.
In the case of XSLT instructions and XQuery expressions, the toString() method gives an abstracted view of the syntax that is not designed in general to be parseable.
- Overrides:
toString
in classExpression
- Returns:
- a representation of the expression as a string
-
toShortString
public java.lang.String toShortString()
Description copied from class:Expression
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classExpression
- Returns:
- a short string, sufficient to identify the expression
-
getStreamerName
public java.lang.String getStreamerName()
Description copied from class:Expression
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerName
in classExpression
- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
getElaborator
public Elaborator getElaborator()
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- a suitable elaborator
-
-