Understanding the Built-in Template Rules

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

Understanding the Built-in Template Rules

MSXML supports various built-in template rules when the XSLT processor cannot find a template rule explicitly declared.

Rules for Root and Element Nodes

The built-in template rule for the root and element nodes is as follows:

<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>

This rule instructs the processor to recursively process all children of the root node and of all element nodes, according to applicable template rules explicitly declared in the style sheet. To enforce transformation in which only the explicitly declared template rules are used, override this built-in rule as follows:

<xsl:template match="*|/"/>

Rules for Text and Attribute Nodes

The built-in template rule for text or attribute nodes is as follows:

<xsl:template match="text()|@*">
   <xsl:value-of select="."/>
</xsl:template>

For every text or attribute node, this template specifies that the text content of each matched node is to be output straight to the result tree.

Note   Because XSLT treats newline characters, along with other white space characters, as text nodes, this built-in rule applies to white space characters as well. For more information about XSLT and white space, see Overriding <xsl:preserve-space> and <xsl:strip-space>.

Rules for Comment Nodes and Processing-Instruction Nodes

The following is the built-in template rule for comment and processing-instruction nodes.

<xsl:template match="processing-instruction()|comment()" />

The effect of this built-in template rule is to suppress output in the result tree. If you need to reproduce comments in the result tree, supply the following template rule to override the built-in one:

<xsl:template match="processing-instruction()" />

<xsl:template match="comment()">
    <xsl:value-of select="." />
</xsl:template>

See Also

Processing Template Rules | Processing Multiple Matching Templates Rules