XML & XSL - xsl:template


Defines a template for the desired output for nodes of a particular type and context. What this means is that one can pattern match a specific tag within an XML file and designate that that tag and its contents will be displayed in a manner specified by the template. This also implies that differeing tags accessed within the same XSL style sheet can have different templates applied in the same style sheet. The result is multple display formats for the same XML tree. This is the purpose of using templates.

Syntax

<xsl:template language="language-name" match="node-context">

Attributes

Parent Elements

Child Elements

Purpose

Using templating one can pattern match a specific tag within an XML file and designate that that tag and its contents will be displayed in a manner specified by the template. This also implies that differeing tags accessed within the same XSL style sheet can have different templates applied in the same style sheet. The result is multple display formats for the same XML tree. This is the purpose of using templates.

The example below enforces a specific output for every security pattern element found, depending on how the template is applied.

<xsl:template match="security">
  <DIV STYLE="font-weight:bold">
    Symbol: <xsl:value-of match="symbol" />, Net Asset Value: <xsl:value-of match="NAV" />
  </DIV>
</xsl:template>