Next / Previous / Contents / TCC Help System / NM Tech homepage

8. Basic template elements

Use the XSLT elements below to define templates that specify how to process selected input elements.

8.1. <xsl:template>: Define a template

This is the basic tag specifying how to process some set of input. There are two basic types of templates:

  • Templates with a match="..." attribute are applied to the input nodes that are selected by that attribute.

  • Templates with a name="..." attribute are called named templates. They are invoked by explicitly calling them with the <xsl:apply-templates> element.

    You must supply either a match attribute or a name attribute.

Attributes of <xsl:template>:

match

An XPath expression that selects a set of nodes. For example, match="trail" specifies a template that matches all <trail> elements.

name

Instead of a match attribute, you can give your template a name and call it using <xsl:call-template>.

For example, if you have a template that looks like

    <xsl:template name="add-links">

then you could call this template using

    <xsl:call-template name="add-links"/>

You can also pass values to a named template using <xsl:with-param>.

mode

Sometimes you want to use the same content in more than one place. For example, chapter titles might appear both at the beginning of a chapter and also in the table of contents.

To do this, define a mode="m" attribute on the template for each place you use that content. Then use <xsl:apply-templates mode="m"...> to process the content with that mode.