Using Stylus Studio Default Templates

Every stylesheet in Stylus Studio can use two built-in templates, even though they are not explicitly defined. This section covers the following topics to help you use these templates:

Contents of a New Stylesheet Created by Stylus Studio

When Stylus Studio creates a new stylesheet, the stylesheet includes the following built-in templates:

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

Every XSLT stylesheet contains these templates whether or not they are explicitly specified. In other words, the XSLT processor behaves as if they are there even when they are not explicitly specified in the stylesheet.

About the Root/Element Built-In Template

The first built-in template matches *|/. This means it matches every element in the source document and it matches the root node. This is the root/element built-in template.

This root/element built-in template contains only the xsl:apply-templates instruction. The xsl:apply-templates instruction does not specify a select attribute, which means that the XSLT processor operates on the children of the node for which the root/element template was instantiated.

What does the XSLT processor do when it operates on these children nodes? It searches for a template that matches each node. If there is no such template and if the node is an element, the XSLT processor instantiates the root/element built-in template. If the node is a text node and there is no matching template, the XSLT processor instantiates the text/attribute built-in template.

If the node for which the root/element built-in template is instantiated has no children, the XSLT processor does no processing for this node and proceeds to the next selected node.

The XSLT processor instantiates the root/element built-in template when it cannot find a template that explicitly matches the root node or an element in the source document. As you know, the XSLT processor always begins processing by instantiating the template that matches the root node. If you do not define such a template in your stylesheet, the XSLT processor begins processing by instantiating the root/element built-in template.

About the Text/Attribute Built-In Template

The second specified built-in template matches text()|@*. This means it matches the text contents of every text node and every attribute in the source document. This is the text/attribute template.

This template contains only the xsl:value-of instruction. Its select attribute specifies an expression for selecting an XML node. The "." expression identifies the current node, which is the node the template was instantiated for.

This template copies the text contained in the current text node or attribute to the result document.

XQuery Talk Blog

Get the latest XQuery news and information at XQuery-Talk - an online community for discussing XQuery technologies, examples, implementations and more. Bookmark this RSS or ATOM feed now!

Medical Companies That Use Stylus Studio

Medical companies can't solve every ache and pain. That's why when it comes to the struggle of data integration, they turn to Stylus Studio to simplify their pains. Come see which medical companies are injecting Stylus Studio into their work load!

Energy Companies That Use Stylus Studio

Forget red bull! Many energy companies are using Stylus Studio 2006 for their quick pick me up during the work day. Come see which energy companies are getting the boost they need with Stylus Studio!

Retail Companies That Use Stylus Studio

Stores and XML data can get very crowded. That's why retail companies use Stylus Studio to simplify their data. With the power of Stylus Studio these top retail companies are at the front of the line when it comes to XML!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member