XSLT <xsl:template>Element
An XSL stylesheet consists of one or more sets of rules called templates.
Each template contains rules that are applied when a specified node is matched.
<xsl:template> Element
The <xsl:template> element is used to build templates.
matchThe attribute is used to associate XML elements and templates. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (for example, match="/" defines the entire document).
Okay, let's look at a simplified version of the XSL file from the previous chapter:
Example
Try it Yourself »
Example Explanation
Since an XSL stylesheet is itself an XML document, it always starts with the XML declaration:<?xml version="1.0" encoding="ISO-8859-1"?>.
The next element,<xsl:stylesheet>, , defines this document as an XSLT stylesheet document (along with the version number and XSLT namespace attributes).
<xsl:template>The element defines a template. Andmatch="/"The attribute associates this template with the root of the XML source document.
The content inside the <xsl:template> element defines the HTML code that is written to the output.
The last two lines define the end of the template and the end of the stylesheet.
The result of this example has a small flaw, because the data has not been copied from the XML document to the output. In the next chapter, you will learn how to use<xsl:value-of>element to select values from XML elements.
Other Extensions