Question: how do xslt templates work?
Answer: Whenever xsl:apply-templates is called, the XSLT processor examines the patterns of all the stylesheet's template rules. For each node being iterated over, it first finds all the template rules with patterns that match the node and then instantiates the best-matching template rule among them.