net.sf.saxon.instruct

Class ApplyTemplates

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

public class ApplyTemplates
extends Instruction

An instruction representing an xsl:apply-templates 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

ApplyTemplates(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode, boolean backwardsCompatible, boolean implicitSelect)
Construct an apply-templates instructino

Method Summary

static TailCall
applyTemplates(SequenceIterator iterator, Mode mode, ParameterSet parameters, ParameterSet tunnelParameters, XPathContextMajor context, boolean backwardsCompatible, int locationId)
Process selected nodes using the handlers registered for a particular mode.
Expression
copy()
Copy an expression.
boolean
createsNewNodes()
Determine whether this instruction creates new nodes.
static void
defaultAction(NodeInfo node, ParameterSet parameters, ParameterSet tunnelParams, XPathContext context, boolean backwardsCompatible, int locationId)
Perform the built-in template action for a given node.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
InstructionInfo
getInstructionInfo()
Set additional trace properties appropriate to the kind of instruction.
int
getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes
Expression
getSelectExpression()
Get the select expression
boolean
hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly
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)
TailCall
processLeavingTail(XPathContext context)
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

ApplyTemplates

public ApplyTemplates(Expression select,
                      boolean useCurrentMode,
                      boolean useTailRecursion,
                      Mode mode,
                      boolean backwardsCompatible,
                      boolean implicitSelect)
Construct an apply-templates instructino
Parameters:
select - the select expression
useCurrentMode - true if mode="#current" was specified
useTailRecursion - true if this instruction is the last in its template
mode - the mode specified on apply-templates
backwardsCompatible - true if XSLT backwards compatibility is enabled
implicitSelect - true if the select attribute was defaulted

Method Details

applyTemplates

public static TailCall applyTemplates(SequenceIterator iterator,
                                      Mode mode,
                                      ParameterSet parameters,
                                      ParameterSet tunnelParameters,
                                      XPathContextMajor context,
                                      boolean backwardsCompatible,
                                      int locationId)
            throws XPathException
Process selected nodes using the handlers registered for a particular mode.
Parameters:
iterator - an Iterator over the nodes to be processed, in the correct (sorted) order
mode - Identifies the processing mode. It should match the mode defined when the element handler was registered using setHandler with a mode parameter. Set this parameter to null to invoke the default mode.
parameters - A ParameterSet containing the parameters to the handler/template being invoked. Specify null if there are no parameters.
tunnelParameters - A ParameterSet containing the parameters to the handler/template being invoked. Specify null if there are no parameters.
context - A newly-created context object (this must be freshly created by the caller, as it will be modified by this method)
backwardsCompatible - true if running in backwards compatibility mode
locationId - location of this apply-templates instruction in the stylesheet
Returns:
a TailCall returned by the last template to be invoked, or null, indicating that there are no outstanding tail calls.
Throws:
XPathException - if any dynamic error occurs

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 returns true (which is almost invariably the case, so it's not worth doing any further analysis to find out more precisely).
Overrides:
createsNewNodes in interface Instruction

defaultAction

public static void defaultAction(NodeInfo node,
                                 ParameterSet parameters,
                                 ParameterSet tunnelParams,
                                 XPathContext context,
                                 boolean backwardsCompatible,
                                 int locationId)
            throws XPathException
Perform the built-in template action for a given node.
Parameters:
node - the node to be processed
parameters - the parameters supplied to apply-templates
tunnelParams - the tunnel parameters to be passed through
context - the dynamic evaluation context
backwardsCompatible - true if in 1.0 mode (currently makes no difference)
locationId - location of the instruction (apply-templates, apply-imports etc) that caused the built-in template to be invoked
Throws:
XPathException - if any dynamic error occurs

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
Parameters:
out - output destination

getInstructionInfo

public InstructionInfo getInstructionInfo()
Set additional trace properties appropriate to the kind of instruction. This implementation adds the mode attribute
Specified by:
getInstructionInfo in interface InstructionInfoProvider
Overrides:
getInstructionInfo in interface Instruction

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes
Overrides:
getInstructionNameCode in interface Instruction

getSelectExpression

public Expression getSelectExpression()
Get the select expression
Returns:
the select expression

hasLoopingSubexpression

public boolean hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly
Overrides:
hasLoopingSubexpression in interface Expression
Parameters:
child - the immediate subexpression
Returns:
true if the child expression is evaluated repeatedly

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
Overrides:
process in interface Instruction

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
            throws XPathException
Specified by:
processLeavingTail in interface TailCallReturner
Overrides:
processLeavingTail in interface Instruction

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 - represents the contained xsl:with-param elements having tunnel="no" (the default)
tunnelParams - represents the contained xsl:with-param elements having tunnel="yes"

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 - the 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