Directs the XSLT processor to find the appropriate template to apply, based on the type and context of each selected node.
<xsl:apply-templates select = Expression mode = QName>
Can be used to process nodes selected by an expression instead of processing all children. The value of the select attribute is an expression. The expression must evaluate to a node-set. The selected set of nodes is processed in document order unless a sorting specification is present.
The mode attribute allows an element to be processed multiple times, each time producing a different result. If <xsl:template> does not have a match attribute, it must not have a mode attribute. If an <xsl:apply-templates> element has a mode attribute, it applies only to those template rules from <xsl:template> elements that have a mode attribute with the same value; if an <xsl:apply-templates> element does not have a mode attribute, it applies only to those template rules from <xsl:template> elements that do not have a mode attribute.
The <xsl:apply-templates> element first selects a set of nodes using the query specified in the select attribute. If this attribute is left unspecified, all children of the current node are selected. For each of the selected nodes, <xsl:apply-templates> directs the XSLT processor to find an appropriate <xsl:template> to apply. Templates are tested for applicability by comparing the node to the XPath expression specified in the template's match attribute. If more than one template satisfies the match pattern, the one appearing with the highest priority is chosen. If several templates have the same priority, the last in the style sheet is chosen.
For more information, see Handling Irregular Data Hierarchies.
The following style sheet formats customer data in XML into an HTML <TABLE> element, where each row represents a customer and the columns represent the customer's name, address, and phone number. The <xsl:sort> element sorts the customers by state, with all customers from a single state sorted by name.