Microsoft XML 2.5 SDK


 

xsl:template Element

[This is preliminary documentation and subject to change.]

Defines a template for the desired output for nodes of a particular type and context.

Syntax

<xsl:template

    language="language-name"

    match="node-context"  >

</xsl:template>

Attributes

language

Active Scripting language used within this template. If left unspecified, the current scripting language is used, as specified by a language attribute on an ancestor. If no such attribute exists, JScript® (compatible with ECMA 262 language specification) is used. This attribute accepts the same values as the language attribute on the HTML SCRIPT element.

match

Context for which the template should be executed. This attribute can be used to change the context of the source document, and provides a convenient way to navigate down into the document tree. The default is "node() | / | @*", to match all nodes. For a description of the syntax, see XSL Pattern Syntax.

Element Information

Number of occurrences Unlimited
Parent elements xsl:apply-templates, xsl:stylesheet
Child elements xsl:apply-templates, xsl:attribute, xsl:choose, xsl:comment, xsl:copy, xsl:element, xsl:eval, xsl:for-each, xsl:if, xsl:pi, xsl:value-of, output elements
Requires closing tag Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed.

Remarks

Note that the template need not generate a complete XML document (even the root template unless using transformNodeToObject), but only a fragment of XML. It is possible to include unenclosed text or multiple document elements defined by the template. This facilitates the generation of raw text and XML fragments that can be further processed by an application (for example, HTML fragments inserted into an HTML page).

Example

The following template (in this case defined by the xsl:template element) has a pattern that identifies elements of type "stock" and produces an output DIV element with the attribute STYLE="font-weight:bold".

<xsl:template match="stock">
  <DIV STYLE="font-weight:bold">
    Symbol: <xsl:value-of match="symbol" />, Price: <xsl:value-of match="price" />
  </DIV>
</xsl:template>

See Also

Handling Documents and Irregular Data, Authoring Match Patterns