Class NamedTemplate

  • All Implemented Interfaces:
    javax.xml.transform.SourceLocator, ExpressionOwner, Locatable, Location, Traceable, TraceableComponent, org.xml.sax.Locator

    public class NamedTemplate
    extends Actor
    implements TraceableComponent
    The runtime object corresponding to a named 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.

    From Saxon 9.7, the NamedTemplate and TemplateRule objects are separated. A NamedTemplate represents a template with a name attribute; a TemplateRule is a template with a match attribute. If an xsl:template declaration has both attributes, two objects are created.

    • Constructor Detail

      • NamedTemplate

        public NamedTemplate​(StructuredQName templateName)
        Create a named 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
      • setContextItemRequirements

        public void setContextItemRequirements​(ItemType type,
                                               boolean mayBeOmitted,
                                               boolean absentFocus)
        Set the required context item type. Used when there is an xsl:context-item child element
        Parameters:
        type - the required context item type
        mayBeOmitted - true if the context item may be absent
        absentFocus - true if the context item is treated as absent even if supplied (use=absent)
      • getSymbolicName

        public SymbolicName getSymbolicName()
        Description copied from class: Actor
        Get the symbolic name of the component
        Specified by:
        getSymbolicName in class Actor
        Returns:
        the symbolic name
      • getTracingTag

        public java.lang.String getTracingTag()
        Description copied from class: Actor
        Get a string used to identify this kind of component when used in tracing output
        Specified by:
        getTracingTag in interface TraceableComponent
        Overrides:
        getTracingTag in class Actor
        Returns:
        an identifying string
      • gatherProperties

        public void gatherProperties​(java.util.function.BiConsumer<java.lang.String,​java.lang.Object> consumer)
        Get the properties of this object to be included in trace messages, by supplying the property values to a supplied consumer function
        Specified by:
        gatherProperties in interface Traceable
        Parameters:
        consumer - the function to which the properties should be supplied, as (property name, value) pairs.
      • setBody

        public void setBody​(Expression body)
        Set the expression that forms the body of the template
        Specified by:
        setBody in interface TraceableComponent
        Overrides:
        setBody in class Actor
        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 Traceable
        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
      • getRequiredContextItemType

        public ItemType getRequiredContextItemType()
      • isMayOmitContextItem

        public boolean isMayOmitContextItem()
      • isAbsentFocus

        public boolean isAbsentFocus()
      • getLocalParamInfo

        public NamedTemplate.LocalParamInfo getLocalParamInfo​(StructuredQName 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
      • expand

        public TailCall expand​(Outputter output,
                               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:
        output - the destination for the result
        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
      • export

        public void export​(ExpressionPresenter presenter)
                    throws XPathException
        Output diagnostic explanation to an ExpressionPresenter
        Specified by:
        export in class Actor
        Parameters:
        presenter - the expression presenter used to generate the XML representation of the structure
        Throws:
        XPathException