Class ApplyTemplates
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.instruct.Instruction
-
- net.sf.saxon.expr.instruct.ApplyTemplates
-
- All Implemented Interfaces:
ComponentInvocation
,ContextOriginator
,ExportAgent
,ITemplateCall
,Locatable
,IdentityComparable
,Traceable
public class ApplyTemplates extends Instruction implements ITemplateCall, ComponentInvocation
An instruction representing an xsl:apply-templates element in the stylesheet
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApplyTemplates.ApplyTemplatesElaborator
protected static class
ApplyTemplates.ApplyTemplatesPackage
An ApplyTemplatesPackage is an object that encapsulates the sequence of nodes to be processed, the mode, the parameters to be supplied, and the execution context.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_useTailRecursion
protected boolean
implicitSelect
protected boolean
inStreamableConstruct
protected Mode
mode
protected RuleManager
ruleManager
protected boolean
useCurrentMode
-
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 Modifier Constructor Description protected
ApplyTemplates()
ApplyTemplates(Expression select, boolean useCurrentMode, boolean useTailRecursion, boolean implicitSelect, boolean inStreamableConstruct, Mode mode, RuleManager ruleManager)
Construct an apply-templates instruction
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathMap.PathMapNodeSet
addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.Expression
copy(RebindingMap rebindings)
Copy an expression.void
export(ExpressionPresenter out)
Diagnostic print of expression structure.WithParam[]
getActualParams()
Get the actual parameters passed to the called templateint
getBindingSlot()
Get the binding slot to be used (for the explicit or implicit reference to the mode).Elaborator
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
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().int
getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposesint
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.Mode
getMode()
Get the ModeRuleManager
getRuleManager()
Expression
getSelect()
Get the select expressionExpression
getSelectExpression()
Get the select expressionExpression
getSeparatorExpression()
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 mode that this invocation referencesComponent.M
getTargetMode(XPathContext context)
Establish the target mode, at run-time.WithParam[]
getTunnelParams()
Get the tunnel parameters passed to the called templateprotected void
init(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode)
boolean
isImplicitSelect()
Ask if the select expression was implicitboolean
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 contextInfo)
Perform optimisation of an expression and its subexpressions.void
setActualParams(WithParam[] params)
void
setBindingSlot(int slot)
Set the binding slot to be used (for the explicit or implicit reference to the mode).void
setMode(SimpleMode target)
Set the mode to be used.void
setSelect(Expression select)
Set the select expressionvoid
setSeparatorExpression(Expression separator)
Set the separator expression (Saxon extension)void
setTunnelParams(WithParam[] params)
Expression
simplify()
Simplify an expression.Expression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform type checking of an expression and its subexpressions.boolean
usesCurrentMode()
Ask if mode="#current" was specifiedboolean
useTailRecursion()
Ask if tail recursion is to be used-
Methods inherited from class net.sf.saxon.expr.instruct.Instruction
alwaysCreatesNewNodes, assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, dynamicError, evaluateAsString, evaluateItem, getExpressionName, getItemType, getNetCost, getSourceLocator, isInstruction, isXSLT, iterate, process, someOperandCreatesNewNodes
-
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getLocalRetainedStaticContext, getLocation, getObjectName, 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, toShortString, toString, 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
-
-
-
-
Field Detail
-
useCurrentMode
protected boolean useCurrentMode
-
_useTailRecursion
protected boolean _useTailRecursion
-
mode
protected Mode mode
-
implicitSelect
protected boolean implicitSelect
-
inStreamableConstruct
protected boolean inStreamableConstruct
-
ruleManager
protected RuleManager ruleManager
-
-
Constructor Detail
-
ApplyTemplates
protected ApplyTemplates()
-
ApplyTemplates
public ApplyTemplates(Expression select, boolean useCurrentMode, boolean useTailRecursion, boolean implicitSelect, boolean inStreamableConstruct, Mode mode, RuleManager ruleManager)
Construct an apply-templates instruction- Parameters:
select
- the select expressionuseCurrentMode
- true if mode="#current" was specifieduseTailRecursion
- true if this instruction is the last in its templateimplicitSelect
- true if the select expression is implicit, that is, if there was no explicit select expression in the call. This information is used only to make error messages more meaningful.inStreamableConstruct
- true if the apply-templates instruction appears within a streamable construct such as a streamable template rulemode
- the mode specified on apply-templatesruleManager
- the rule manager
-
-
Method Detail
-
init
protected void init(Expression select, boolean useCurrentMode, boolean useTailRecursion, Mode mode)
-
setMode
public void setMode(SimpleMode target)
Set the mode to be used.- Parameters:
target
- the attribute set to be used
-
setSeparatorExpression
public void setSeparatorExpression(Expression separator)
Set the separator expression (Saxon extension)- Parameters:
separator
- the separator expression
-
getSeparatorExpression
public Expression getSeparatorExpression()
-
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
-
setActualParams
public void setActualParams(WithParam[] params)
-
setTunnelParams
public void setTunnelParams(WithParam[] params)
-
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
-
getInstructionNameCode
public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes- Overrides:
getInstructionNameCode
in classInstruction
- Returns:
- a code identifying the instruction: typically but not always the fingerprint of a name in the XSLT namespace
-
getImplementationMethod
public int getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is prefered. For instructions this is the process() method.- Overrides:
getImplementationMethod
in classInstruction
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
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 (or the original if unchanged, or if modified in-situ)
- 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 contextInfo) 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 visitorcontextInfo
- 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)
-
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
-
getRuleManager
public RuleManager getRuleManager()
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- a mutable list of (old binding, new binding) pairs that is used to update the bindings held in any local variable references that are copied.- Returns:
- the copy of the original expression
-
mayCreateNewNodes
public final boolean mayCreateNewNodes()
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:
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)
-
getTargetMode
public Component.M getTargetMode(XPathContext context)
Establish the target mode, at run-time. This (a) resolves overrides across packages, and (b) handles mode="#current".- Parameters:
context
- the dynamic context- Returns:
- the mode to be used, as a Component
-
getSelectExpression
public Expression getSelectExpression()
Get the select expression- Returns:
- the select expression
-
isImplicitSelect
public boolean isImplicitSelect()
Ask if the select expression was implicit- Returns:
- true if no select attribute was explicitly specified
-
useTailRecursion
public boolean useTailRecursion()
Ask if tail recursion is to be used- Returns:
- true if tail recursion is used
-
usesCurrentMode
public boolean usesCurrentMode()
Ask if mode="#current" was specified- Returns:
- true if mode="#current" was specified
-
getMode
public Mode getMode()
Get the Mode- Returns:
- the mode, or null if mode="#current" was specified
-
getFixedTarget
public Component 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. Otherwise, return null.- Specified by:
getFixedTarget
in interfaceComponentInvocation
- Returns:
- the bound component if the binding has been fixed
-
getSymbolicName
public SymbolicName getSymbolicName()
Get the symbolic name of the mode that this invocation references- Specified by:
getSymbolicName
in interfaceComponentInvocation
- Returns:
- the symbolic name of the mode used by this instructon, or null if the instruction uses mode="#current"
-
addToPathMap
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.
- Overrides:
addToPathMap
in classExpression
- Parameters:
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be added- Returns:
- the pathMapNodeSet representing the points in the source document that are both reachable by this expression, and that represent possible results of this expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.
-
export
public void export(ExpressionPresenter out) throws XPathException
Diagnostic print 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
- output destination- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
getSelect
public Expression getSelect()
Get the select expression- Returns:
- the select expression
-
setSelect
public void setSelect(Expression select)
Set the select expression- Parameters:
select
- the select expression
-
setBindingSlot
public void setBindingSlot(int slot)
Set the binding slot to be used (for the explicit or implicit reference to the mode). 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 (for the explicit or implicit reference to the mode). 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.
-
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:
- an appropriate
Elaborator
-
-