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,
                             Configuration config)
        Create a named template
        templateName - the name of the template (if any)
    • Method Detail

      • setTemplateName

        public void setTemplateName​(StructuredQName templateName)
        Initialize the template
        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
        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
        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
        getTracingTag in class Actor
        a diagnostic string used to identify the component when tracing
      • 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
        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
        setBody in class Actor
        body - the body of the template
      • getTemplateName

        public StructuredQName getTemplateName()
        Get the name of the template (if it is named)
        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
        the QName of the object declared or manipulated by this instruction or expression
      • setRequiredType

        public void setRequiredType​(SequenceType type)
        Set the required type to be returned by this template
        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
        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
        id - the parameter id
        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.
        output - the destination for the result
        context - the XPath dynamic context
        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
        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
        presenter - the expression presenter used to generate the XML representation of the structure
        XPathException - if things go wrong, for example an I/O failure