Next / Previous / Contents / Shipman's homepage

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:

Attributes of xsl:template:


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


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 this:

    <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.


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.