xsl:template (match)

A template is invoked by the processor when called by name or when it matches a XML node.

A template in XSLT is the equivalent of a method in Java.

  • Use the 'match' attribute to specify an XPath that should be matched by a node in the XML document.

  • Matches the root.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        ...
      </xsl:template>
    </xsl:stylesheet>
    					
  • Matches any test attribute.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="*/@test">
        ...
      </xsl:template>
    </xsl:stylesheet>
    					

Note

The context-node for a template is the node matched by the match attribute.