Package net.sf.saxon.expr.instruct

## 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`, `TailCallReturner`, `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.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
    --- | --- | ---
    `int` | `computeCardinality()` | Get the cardinality of the sequence returned by evaluating this instruction
    `Expression` | `copy​(RebindingMap rebindings)` | Copy an expression.
    `void` | `export​(ExpressionPresenter out)` | Export of expression structure.
    `WithParam[]` | `getActualParams()` | Get the actual parameters passed to the called template
    `int` | `getBindingSlot()` | Get the binding slot to be used.
    `StructuredQName` | `getCalledTemplateName()` | Get the name (QName) of the template being called
    `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.
    `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 instruction
    `StructuredQName` | `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 expression
    `SymbolicName` | `getSymbolicName()` | Get the symbolic name of the template being called.
    `Component` | `getTarget()` |
    `NamedTemplate` | `getTargetTemplate()` | Get the target template
    `WithParam[]` | `getTunnelParams()` | Get the tunnel parameters passed to the called template
    `boolean` | `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.
    `TailCall` | `processLeavingTail​(Outputter output, XPathContext context)` | Process this instruction.
    `void` | `setActualParameters​(WithParam[] actualParams, WithParam[] tunnelParams)` | Set the actual parameters on the call
    `void` | `setBindingSlot​(int slot)` | Set the binding slot to be used.
    `void` | `setTargetTemplate​(NamedTemplate target)` | Set the target template
    `Expression` | `simplify()` | Simplify an expression.
    `java.lang.String` | `toShortString()` | Produce a short string identifying the expression for use in error messages
    `java.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, dynamicError, effectiveBooleanValue, equals, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, 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, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers`

    - ### 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:original
        `calledTemplateName` - the name of the template to be called; null in the case of saxon:call-template where this is established dynamically
        `useTailRecursion` - true if the call is potentially tail recursive where the name of the called template is to be calculated dynamically

  - ### 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 parameters
        `tunnelParams` - the tunnel parameters

    - #### 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 interface `ComponentInvocation`
      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 interface `ComponentInvocation`
      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 interface `ITemplateCall`
      Returns:
        the non-tunnel parameters

    - #### getTunnelParams

          public WithParam[] getTunnelParams()

      Get the tunnel parameters passed to the called template
      Specified by:
        `getTunnelParams` in interface `ITemplateCall`
      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 class `Instruction`
      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 interface `ComponentInvocation`
      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 interface `ComponentInvocation`
      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 class `Expression`
      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 class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - 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 class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextItemType` - 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 to `Type.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

          public int computeCardinality()

      Get the cardinality of the sequence returned by evaluating this instruction
      Overrides:
        `computeCardinality` in class `Instruction`
      Returns:
        the static cardinality

    - #### getItemType

          public ItemType getItemType()

      Get the item type of the items returned by evaluating this instruction
      Overrides:
        `getItemType` in class `Instruction`
      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 class `Expression`
      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 class `Expression`
      Returns:
        a set of 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 class `Instruction`
      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. Default implementation works off the results of iterateSubExpressions()

      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 class `Instruction`
      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 class `Instruction`
      Parameters:
        `output` - the destination for the result
        `context` - the dynamic context for this transformation
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### processLeavingTail

          public TailCall processLeavingTail​(Outputter output,
                                             XPathContext context)
                                      throws XPathException

      Process this instruction. If the called template contains a tail call (which may be an xsl:call-template or 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`
      Specified by:
        `processLeavingTail` in class `Instruction`
      Parameters:
        `output` - the destination for the result
        `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.
      Throws:
        `XPathException` - if a dynamic error occurs during the evaluation of the instruction

    - #### 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 interface `Traceable`
      Overrides:
        `getObjectName` in class `Expression`
      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 interface `ExportAgent`
      Specified by:
        `export` in class `Expression`
      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 class `Expression`
      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 class `Expression`
      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 class `Expression`
      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