Unnamed (Match) Templates
Unnamed templates, also known as match templates, include a match attribute that contains an XPath expression to specify the criteria for nodes upon which the template should be invoked. In the following example, the template applies to the element named route that is a child of the current context and that has a child element named next-hop whose value starts with the string 10.10..
<xsl:template match="route[starts-with(next-hop, '10.10.')]">
<!-- ... body of the template ... -->
</xsl:template>
By default, when XSLT processes a document, it recursively traverses the entire document hierarchy, inspecting each node, looking for a template that matches the current node. When a matching template is found, the contents of that template are evaluated.
The <xsl:apply-templates> element can be used inside an unnamed template to limit and control XSLT’s default, hierarchical traversal of nodes. If the <xsl:apply-templates> element has a select attribute, only nodes matching the XPath expression defined by the attribute are traversed. Otherwise all children of the context node are traversed. If the select attribute is included, but does not match any nodes, nothing is traversed and nothing happens.
In the following example, the template rule matches the <route> element in the XML hierarchy. All the nodes containing a changed attribute are processed. All <route> elements containing a changed attribute are replaced with a <new> element.
<xsl:template match="route">
<new>
<xsl:apply-templates select="*[@changed]"/>
</new>
</xsl:template>
Using unnamed templates allows the script to ignore the location of a tag in the XML hierarchy. For example, if you want to convert all <author> tags into <div class="author"> tags, using templates enables you to write a single rule that converts all <author> tags, regardless of their location in the input XML document.