net.sf.saxon.expr.instruct

## Class Template

- java.lang.Object
- - net.sf.saxon.expr.instruct.Procedure
  - - net.sf.saxon.expr.instruct.Template

- All Implemented Interfaces:
    Serializable, SourceLocator, LocationProvider, SaxonLocator, Container, InstructionInfo, RuleTarget, Locator

      public class Template
      extends Procedure
      implements RuleTarget

  The runtime object corresponding to an xsl:template element in the stylesheet. Note that the Template object no longer has precedence information associated with it; this is now only in the Rule object that references this Template. This allows two rules to share the same template, with different precedences. This occurs when a stylesheet module is imported more than once, from different places, with different import precedences.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.instruct.Procedure

      `body`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Template()` Create a template

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `apply(XPathContextMajor context)` Process the template, without returning any tail calls.
    `TailCall` | `applyLeavingTail(XPathContextMajor context)` Process this template, with the possibility of returning a tail call package if the template contains any tail calls that are to be performed by the caller.
    `TailCall` | `expand(XPathContext context)` Expand the template.
    `void` | `explain(ExpressionPresenter presenter)` Output diagnostic explanation to an ExpressionPresenter
    `int` | `getConstructType()` Get the type of construct.
    `LocalParam` | `getLocalParam(int id)` Get the local parameter with a given parameter id
    `Pattern` | `getMatchPattern()` Get the match pattern used with this template
    `StructuredQName[]` | `getModeNames()` Get the names of the modes associated with this template rule
    `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.
    `SequenceType` | `getRequiredType()` Get the required type to be returned by this template
    `StructuredQName` | `getTemplateName()` Get the name of the template (if it is named)
    `boolean` | `hasRequiredParams()` Ask whether this template has one or more required parameters
    `boolean` | `isActuallyStreamable(boolean allowExtensions, List<String> reasons)` Ask whether this template satisfies the rules for a guaranteed streamable template
    `boolean` | `isDeclaredStreamable()` Ask whether or not this template is declared as streamable
    `void` | `setBody(Expression body)` Set the expression that forms the body of the template
    `void` | `setDeclaredStreamable(boolean streamable)` Say whether or not this template is declared as streamable
    `void` | `setHasRequiredParams(boolean has)` Set whether this template has one or more required parameters
    `void` | `setMatchPattern(Pattern pattern)` Set the match pattern used with this template
    `void` | `setModeNames(StructuredQName[] modeNames)` Set the names of the modes associated with this template rule
    `void` | `setRequiredType(SequenceType type)` Set the required type to be returned by this template
    `void` | `setTemplateName(StructuredQName templateName)` Initialize the template

    - ### Methods inherited from class net.sf.saxon.expr.instruct.Procedure

      `getBody, getColumnNumber, getColumnNumber, getContainerGranularity, getExecutable, getHostLanguage, getLineNumber, getLineNumber, getLocationProvider, getProperties, getProperty, getPublicId, getStackFrameMap, getSystemId, getSystemId, setExecutable, setHostLanguage, setLineNumber, setStackFrameMap, setSystemId`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Template

          public Template()

      Create a template

  - ### Method Detail

    - #### setTemplateName

          public void setTemplateName(StructuredQName templateName)

      Initialize the template
      Parameters:
        `templateName` - the name of the template (if any) performed by apply-imports

    - #### setMatchPattern

          public void setMatchPattern(Pattern pattern)

      Set the match pattern used with this template
      Parameters:
        `pattern` - the match pattern (may be null for a named template)

    - #### getMatchPattern

          public Pattern getMatchPattern()

      Get the match pattern used with this template
      Returns:
        the match pattern, or null if this is a named template with no match pattern

    - #### setBody

          public void setBody(Expression body)

      Set the expression that forms the body of the template
      Overrides:
        `setBody` in class `Procedure`
      Parameters:
        `body` - the body of the template

    - #### getTemplateName

          public StructuredQName getTemplateName()

      Get the name of the template (if it is named)
      Returns:
        the template name, or null if unnamed

    - #### getObjectName

          public 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. This is used only where the name is known statically.
      Specified by:
        `getObjectName` in interface `InstructionInfo`
      Returns:
        the QName of the object declared or manipulated by this instruction or expression

    - #### setHasRequiredParams

          public void setHasRequiredParams(boolean has)

      Set whether this template has one or more required parameters
      Parameters:
        `has` - true if the template has at least one required parameter

    - #### hasRequiredParams

          public boolean hasRequiredParams()

      Ask whether this template has one or more required parameters
      Returns:
        true if this template has at least one required parameter

    - #### setRequiredType

          public void setRequiredType(SequenceType type)

      Set the required type to be returned by this template
      Parameters:
        `type` - the required type as defined in the "as" attribute on the xsl:template element

    - #### getRequiredType

          public SequenceType getRequiredType()

      Get the required type to be returned by this template
      Returns:
        the required type as defined in the "as" attribute on the xsl:template element

    - #### setModeNames

          public void setModeNames(StructuredQName[] modeNames)

      Set the names of the modes associated with this template rule
      Parameters:
        `modeNames` - the names of the modes for this template rule

    - #### getModeNames

          public StructuredQName[] getModeNames()

      Get the names of the modes associated with this template rule
      Returns:
        the names of the modes for this template rule

    - #### setDeclaredStreamable

          public void setDeclaredStreamable(boolean streamable)

      Say whether or not this template is declared as streamable
      Parameters:
        `streamable` - true if the template belongs to a streamable mode

    - #### isDeclaredStreamable

          public boolean isDeclaredStreamable()

      Ask whether or not this template is declared as streamable
      Returns:
        true if the template belongs to a streamable mode

    - #### getLocalParam

          public LocalParam getLocalParam(int id)

      Get the local parameter with a given parameter id
      Parameters:
        `id` - the parameter id
      Returns:
        the local parameter with this id if found, otherwise null

    - #### apply

          public void apply(XPathContextMajor context)
                     throws XPathException

      Process the template, without returning any tail calls. This path is used by xsl:apply-imports and xsl:next-match
      Parameters:
        `context` - The dynamic context, giving access to the current node,
      Throws:
        `XPathException` - if a dynamic error occurs while evaluating the template

    - #### applyLeavingTail

          public TailCall applyLeavingTail(XPathContextMajor context)
                                    throws XPathException

      Process this template, with the possibility of returning a tail call package if the template contains any tail calls that are to be performed by the caller.
      Parameters:
        `context` - the XPath dynamic context
      Returns:
        null if the template exited normally; but if it was a tail call, details of the call that hasn't been made yet and needs to be made by the caller
      Throws:
        `XPathException` - if a dynamic error occurs while evaluating the template

    - #### expand

          public TailCall expand(XPathContext context)
                          throws XPathException

      Expand the template. Called when the template is invoked using xsl:call-template. Invoking a template by this method does not change the current template.
      Parameters:
        `context` - the XPath dynamic context
      Returns:
        null if the template exited normally; but if it was a tail call, details of the call that hasn't been made yet and needs to be made by the caller
      Throws:
        `XPathException` - if a dynamic error occurs while evaluating the template

    - #### getConstructType

          public int getConstructType()

      Get the type of construct. This will either be the fingerprint of a standard XSLT instruction name (values in `StandardNames`: all less than 1024) or it will be a constant in class `Location`.
      Specified by:
        `getConstructType` in interface `InstructionInfo`
      Returns:
        an integer identifying the kind of construct

    - #### explain

          public void explain(ExpressionPresenter presenter)

      Output diagnostic explanation to an ExpressionPresenter
      Specified by:
        `explain` in interface `RuleTarget`

    - #### isActuallyStreamable

          public boolean isActuallyStreamable(boolean allowExtensions,
                                     List<String> reasons)

      Ask whether this template satisfies the rules for a guaranteed streamable template
      Parameters:
        `allowExtensions` - if true, the method tests for streamability against the Saxon rules rather than the W3C rules
        `reasons` - the caller may supply a list which on return will contain explanations for why the template is not streamable, suitable for inclusion in error messages
      Returns:
        true if the template is within the (Saxon or W3C) definition of guaranteed streamable

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.