Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

Template Rules

Each <xsl:template> element or template rule consists of two components: a match pattern, and the template itself.

<xsl:template match="region">
[template]
</xsl:template>

Match Patterns

The match pattern consists of a match attribute and an XML Path Language (XPath) expression, which specifies which portions of the source tree are processed by the template rule. For example, the following match pattern processes all <region> elements in the source tree.

<xsl:template match="region">

Similarly, the following match pattern selects all the books_sold attributes for processing.

<xsl:template match="@books_sold">

Because match patterns are XPath-based, they are not limited to selecting only an element from the source tree. They can also select text, processing instructions, comments, CDATA declarations, and so on. For more information, see Using XPath Expressions to Select Nodes.

Templates

Each time the template locates something in the source tree that matches the match pattern, it places content in the result tree. That is, the template rule instantiates the template for each match.

Exactly what goes into a given template depends on how the template is to transform the source document. If transforming to HTML, for example, the template might consist of HTML markup, plain text content, comments, scripts, and so on.

See Also

How XSLT Template Rules Depend on Context | Using Named Template Rules in XSLT | xsl:template Element | xsl:apply-templates Element | xsl:call-template Element