Defines a processing rule for source elements or other nodes of a particular type.
Available in XSLT 1.0 and later versions. Available in all Saxon editions.
- Category: declaration
- Content: (
xsl:param*, *sequence-constructor* )
- Permitted parent elements:
- Pattern to identify the type of node to be processed. The most common form of pattern is simply an element name. However, more complex patterns may also be used: the syntax of patterns is given in more detail in XSLT Pattern Syntax. The following examples show some of the possibilities:
||Matches any element whose name (tag) is
||Matches any element|
||Matches any element with an
||Matches any character data node|
||Matches any attribute|
||Matches the document node|
- If this is present, the template may be invoked directly using
matchattribute then becomes optional.
- If there are several
xsl:templateelements that all match the same node, the one that is chosen is determined by the optional
priorityattribute: the template with highest priority wins. The priority is written as a floating-point number; the default priority is
1. If two matching templates have the same priority, the one that appears last in the stylesheet is used.
- If this is present, the template will only be matched when the same mode is used in the invoking
xsl:apply-templateselement. The value can be a list of mode names, indicating that the template matches more than one mode; this list can include the token
#defaultto indicate that the template matches the default (unnamed) mode. Alternatively the
modeattribute can be set to
#all, to indicate that the template matches all modes. (This can be useful in conjunction with
xsl:next-match; one can write a template rule that matches in all modes, and then call
xsl:next-matchto continue processing in the original mode.)
- Defines the required type of the result. The result of evaluating the sequence constructor is converted to this required type using the function conversion rules. The default is
"public" | "private" | "final" | "abstract"
- New in XSLT 3.0. Determines the potential visibility of the component corresponding to this template; the default is
- Allows additional type information to be supplied using Saxon extension syntax.
Notes on the Saxon implementation¶
The extension attribute
saxon:explain can be used on an
xsl:template element. If the attribute has value
yes, then at compile time Saxon outputs (to the standard error output) a representation of the optimized expression tree for that template.
Saxon-EE 9.8 introduces just-in-time compilation of template rules. With this enabled, the static analysis of a template rule happens only the first time that the rule fires. This dramatically reduces compilation costs for large stylesheets that define many rules for rarely-used elements (the DITA and DocBook stylesheets are typical examples). This has the consequence that static errors in unused rules may go unreported. The feature can therefore be disabled, for example by using
-opt:-j on the command line.
A simple XSLT template for a particular element. This example causes all
<ptitle> elements in the source document to be output as HTML
<xsl:template match="ptitle"> <h2> <xsl:apply-templates/> </h2> </xsl:template>