net.sf.saxon.instruct

Class CallTemplate

Implemented Interfaces:
SourceLocator, EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator, TailCallReturner

public class CallTemplate
extends Instruction

Instruction representing an xsl:call-template element in the stylesheet.

Field Summary

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

CallTemplate(Template template, boolean useTailRecursion, Expression calledTemplateExpression, NamespaceResolver nsContext)
Construct a CallTemplate instruction.

Method Summary

int
computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction
Expression
copy()
Copy an expression.
boolean
createsNewNodes()
Determine whether this instruction creates new nodes.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
InstructionInfo
getInstructionInfo()
Set additional trace properties appropriate to the kind of instruction.
int
getInstructionNameCode()
Return the name of this instruction.
int
getIntrinsicDependencies()
ItemType
getItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction
Template
getTargetTemplate(XPathContext context)
Get the template, in the case where it is specified dynamically.
Iterator
iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
void
process(XPathContext context)
Process this instruction, without leaving any tail calls.
TailCall
processLeavingTail(XPathContext context)
Process this instruction.
protected void
promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
boolean
replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
void
setActualParameters(WithParam[] actualParams, WithParam[] tunnelParams)
Set the actual parameters on the call
Expression
simplify(ExpressionVisitor visitor)
Simplify an expression.
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Methods inherited from class net.sf.saxon.instruct.Instruction

assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, createsNewNodes, dynamicError, evaluateAsString, evaluateItem, getImplementationMethod, getInstructionInfo, getInstructionNameCode, getItemType, getSourceLocator, isXSLT, iterate, process, processLeavingTail, promote, promoteInst, simplify

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Constructor Details

CallTemplate

public CallTemplate(Template template,
                    boolean useTailRecursion,
                    Expression calledTemplateExpression,
                    NamespaceResolver nsContext)
Construct a CallTemplate instruction.
Parameters:
template - the Template object identifying the template to be called, in the normal case where this is known statically
useTailRecursion - true if the call is potentially tail recursive
calledTemplateExpression - expression to calculate the name of the template to be called at run-time, this supports the saxon:allow-avt option
nsContext - the static namespace context of the instruction, needed only in the case where the name of the called template is to be calculated dynamically

Method Details

computeCardinality

public int computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction
Overrides:
computeCardinality in interface Instruction
Returns:
the static cardinality

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

createsNewNodes

public final boolean createsNewNodes()
Determine whether this instruction creates new nodes. This implementation currently returns true unconditionally.
Overrides:
createsNewNodes in interface Instruction

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
Overrides:
explain in interface Expression

getInstructionInfo

public InstructionInfo getInstructionInfo()
Set additional trace properties appropriate to the kind of instruction. This implementation adds the template property, which identities the template to be called
Specified by:
getInstructionInfo in interface InstructionInfoProvider
Overrides:
getInstructionInfo in interface Instruction

getInstructionNameCode

public int getInstructionNameCode()
Return the name of this instruction.
Overrides:
getInstructionNameCode in interface Instruction

getIntrinsicDependencies

public int getIntrinsicDependencies()
Overrides:
getIntrinsicDependencies in interface Expression

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction
Overrides:
getItemType in interface Instruction
Parameters:
th - the type hierarchy cache
Returns:
the static item type of the instruction

getTargetTemplate

public Template getTargetTemplate(XPathContext context)
            throws XPathException
Get the template, in the case where it is specified dynamically.
Parameters:
context - The dynamic context of the transformation
Returns:
The template to be called
Throws:
XPathException - if a dynamic error occurs: specifically, if the template name is computed at run-time (Saxon extension) and the name is invalid or does not reference a known template

iterateSubExpressions

public Iterator iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Overrides:
iterateSubExpressions in interface Expression

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            throws XPathException
Overrides:
optimize in interface Expression

process

public void process(XPathContext context)
            throws XPathException
Process this instruction, without leaving any tail calls.
Overrides:
process in interface Instruction
Parameters:
context - the dynamic context for this transformation
Throws:
XPathException - if a dynamic error occurs

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
            throws XPathException
Process this instruction. If the called template contains a tail call (which may be an xsl:call-template of xsl:apply-templates instruction) then the tail call will not actually be evaluated, but will be returned in a TailCall object for the caller to execute.
Specified by:
processLeavingTail in interface TailCallReturner
Overrides:
processLeavingTail in interface Instruction
Parameters:
context - the dynamic context for this transformation
Returns:
an object containing information about the tail call to be executed by the caller. Returns null if there is no tail call.

promoteInst

protected void promoteInst(PromotionOffer offer)
            throws XPathException
Handle promotion offers, that is, non-local tree rewrites.
Overrides:
promoteInst in interface Instruction
Parameters:
offer - The type of rewrite being offered
Throws:
XPathException -

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Replace one subexpression by a replacement subexpression
Overrides:
replaceSubExpression in interface Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

setActualParameters

public void setActualParameters(WithParam[] actualParams,
                                WithParam[] tunnelParams)
Set the actual parameters on the call
Parameters:
actualParams - the parameters that are not tunnel parameters
tunnelParams - the tunnel parameters

simplify

public Expression simplify(ExpressionVisitor visitor)
            throws XPathException
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression).
Overrides:
simplify in interface Instruction
Parameters:
visitor - an expression visitor
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Overrides:
typeCheck in interface Expression