xsl:template
<xsl:template match = "pattern
" priority = "number
" name = "QualifiedName
" mode = "QualifiedName
"> <! -- (xsl:param*, template) -- > </xsl:template>
The xsl:template
top-level element is the key to all of XSLT. Confusingly, the
xsl:template
element itself is
not a template. Rather, it contains a template. The entire
xsl:template
element is called
a template rule. The match
attribute contains a pattern
against which nodes are compared as they're processed. If the
pattern matches a node, then the template (i.e., the contents of
the template rule) is instantiated and inserted into the output
tree.
match
,
optionalA pattern against which nodes can be compared. This
pattern is a location path using only the child
, attribute
, and descendant-or-self
axes or a
combination of several such location paths.
priority
,
optionalA number. If more than one template rule with the same import precedence matches a given node, the one with the highest priority is chosen. If this attribute is not present, then the template rule's priority is calculated in the following way:
Template rules with match patterns composed of
just an element or attribute name (e.g., person
or @profession
) have priority
0.
Template rules with match patterns composed of
just a processing-instruction(
'target
')
node test have priority
0.
Template rules with match patterns in the form
prefix
:*
have priority -0.25.
Template rules with match patterns that just have
a wildcard node test (*
, @*
, comment()
, node( )
, text( )
, and processing-instruction( )
)
have priority -0.5. (This means that built-in template
rules have priority -0.5. However, they are also
imported before all other template rules, and thus never
override any explicit template rule, regardless of
priority.)
Template rules with any other patterns (person[name='Feynman']
,
people/person/@profession
,
person/text( )
, etc.)
have priority 0.5.
It is an error if two or more template rules match a node and have the same priority. However, in this case, most XSLT processors choose the last template rule occurring in the stylesheet, rather than signaling the error.
name
, optionalA name by which this template rule can be invoked from
an xsl:call-template
element, rather than by node matching.
mode
, optionalIf the xsl:template
element has a mode, then this template rule is matched only
when the calling instruction's mode
attribute matches this
mode
attribute's
value.