Built-in Template Rules
Although most stylesheets we’ll develop in this book explicitly define how various XML elements should be transformed, XSLT defines several built-in template rules that apply in the absence of any specific rules. These rules have a lower priority than any other templates, so they’re always overridden when you define your own templates. The built-in templates are listed here.
Built-in template rule for element and document nodes
This template processes the document node and any of its children. This processing ensures that recursive processing will continue, even if no template is declared for a given element:
<xsl:template match="*|/"> <xsl:apply-templates/> </xsl:template>
As an example, given this document:
<?xml version="1.0"?>
<x>
<y>
<z/>
</y>
</z>The built-in template rule for element and document nodes
means that we could write a stylesheet containing only a template
with match="z" and the <z> element will still be processed,
even if there are no template rules for the <x> and <y> elements.
Built-in template rule for modes
This template ensures that element and document nodes
are processed, regardless of any mode that might be in effect. (See
Templates à la mode” in Chapter 5 for more information on the mode attribute.)
<xsl:template match="*|/" mode="x"> <xsl:apply-templates mode="x"/> </xsl:template>
Built-in template rule for text and attribute nodes
This template copies the text of all text and attribute nodes to the output tree. Be aware that you have to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access