net.sf.saxon.instruct

Class ApplyTemplates

public class ApplyTemplates extends Instruction

An instruction representing an xsl:apply-templates element in the stylesheet
Field Summary
protected WithParam[]actualParams
protected booleanimplicitSelect
protected Modemode
protected Expressionselect
protected WithParam[]tunnelParams
protected booleanuseCurrentMode
protected booleanuseTailRecursion
Constructor Summary
protected ApplyTemplates()
ApplyTemplates(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode, boolean implicitSelect)
Construct an apply-templates instructino
Method Summary
protected TailCallapply(XPathContext context, boolean returnTailCall)
static TailCallapplyTemplates(SequenceIterator iterator, Mode mode, ParameterSet parameters, ParameterSet tunnelParameters, XPathContextMajor context, int locationId)
Process selected nodes using the handlers registered for a particular mode.
Expressioncopy()
Copy an expression.
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
static voiddefaultAction(NodeInfo node, ParameterSet parameters, ParameterSet tunnelParams, XPathContext context, int locationId)
Perform the built-in template action for a given node.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
WithParam[]getActualParams()
Get the actual parameters passed to the called template
intgetInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes
ModegetMode()
Get the Mode
ExpressiongetSelectExpression()
Get the select expression
WithParam[]getTunnelParams()
Get the tunnel parameters passed to the called template
booleanhasLoopingSubexpression(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
protected voidinit(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode, boolean implicitSelect)
booleanisImplicitSelect()
Ask if the select expression was implicit
Iterator<Expression>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)
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
voidprocess(XPathContext context)
TailCallprocessLeavingTail(XPathContext context)
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
voidsetActualParameters(WithParam[] actualParams, WithParam[] tunnelParams)
Set the actual parameters on the call
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
booleanusesCurrentMode()
Ask if mode="#current" was specified
booleanuseTailRecursion()
Ask if tail recursion is to be used

Field Detail

actualParams

protected WithParam[] actualParams

implicitSelect

protected boolean implicitSelect

mode

protected Mode mode

select

protected Expression select

tunnelParams

protected WithParam[] tunnelParams

useCurrentMode

protected boolean useCurrentMode

useTailRecursion

protected boolean useTailRecursion

Constructor Detail

ApplyTemplates

protected ApplyTemplates()

ApplyTemplates

public ApplyTemplates(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode, 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 implicitSelect true if the select attribute was defaulted

Method Detail

apply

protected TailCall apply(XPathContext context, boolean returnTailCall)

applyTemplates

public static TailCall applyTemplates(SequenceIterator iterator, Mode mode, ParameterSet parameters, ParameterSet tunnelParameters, XPathContextMajor context, int locationId)
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) 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.

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).

defaultAction

public static void defaultAction(NodeInfo node, ParameterSet parameters, ParameterSet tunnelParams, XPathContext context, int locationId)
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 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.

Parameters: out output destination

getActualParams

public WithParam[] getActualParams()
Get the actual parameters passed to the called template

Returns: the non-tunnel parameters

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes

getMode

public Mode getMode()
Get the Mode

Returns: the mode, or null if mode="#current" was specified

getSelectExpression

public Expression getSelectExpression()
Get the select expression

Returns: the select expression

getTunnelParams

public WithParam[] getTunnelParams()
Get the tunnel parameters passed to the called template

Returns: the tunnel parameters

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

Parameters: child the immediate subexpression

Returns: true if the child expression is evaluated repeatedly

init

protected void init(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode, boolean implicitSelect)

isImplicitSelect

public boolean isImplicitSelect()
Ask if the select expression was implicit

Returns: true if no select attribute was explicitly specified

iterateSubExpressions

public Iterator<Expression> 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)

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

process

public void process(XPathContext context)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

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

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)
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression).

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)

usesCurrentMode

public boolean usesCurrentMode()
Ask if mode="#current" was specified

Returns: true if mode="#current" was specified

useTailRecursion

public boolean useTailRecursion()
Ask if tail recursion is to be used

Returns: true if tail recursion is used