xsl:template

Specifies a template rule.

Format

<xsl:template 
               
  [match = "pattern"]
               
  [name = "qname"] 
               
  [mode = "mode"] 
               
  [priority = "priority"]>
               
  template_body
               
</xsl:template>
               

            

Description

The match attribute is required except when you specify the name attribute. The pattern you specify for the match attribute identifies the source node or set of source nodes to which the template rule applies.

The optional name attribute specifies a name for the template. You can use the name of a template to invoke it with the xsl:call-template instruction. The value you specify for name must be a qualified name. If you specify a name attribute, a match attribute is not required.

The optional mode attribute prevents the template from matching nodes selected by an xsl:apply-templates instruction that specifies a different mode. The value of mode must be a qualified name or an asterisk ( *). If you specify an asterisk, it means match any node.

If an xsl:apply-templates instruction contains a mode attribute, the xsl:apply-templates instruction can apply to only those xsl:template instructions that specify a mode attribute with the same value. If an xsl:apply-templates instruction does not contain a mode attribute, the xsl:apply-templates instruction can apply to only those xsl:template instructions that do not specify a mode attribute.

If you specify the match and mode attributes, they have no effect if the template is instantiated by the xsl:call-template instruction. If you specify the name attribute, you can still instantiate the template as a result of an xsl:apply-templates instruction.

If two or more templates have the same name, Stylus Studio uses the template that appears last in the stylesheet.

The template body contains literal results and XSLT instructions. The XSLT processor instantiates the template body for each node identified by pattern. This means the XSLT processor copies literal results to the result document and executes the XSLT instructions.

If there is more than one matching template rule, the XSLT processor chooses the matching template rule with the higher priority. If both have the same priority, the XSLT processor chooses the one that occurs last in the stylesheet.

For examples and additional information about templates, see Working with Templates.

Tip

 

You can create an xsl:template element automatically using the XSLT mapper.

Generate XML Schema

Generate XML Schema data models from one or more XML instance documents, or by converting other data models (DTD's, Relational Schemas, EDIFACT, EDI, etc.)

XML Whitepapers

Learn how XML can help you meet your business objectives by reading free XML Whitepapers covering XML, XML Schema, XQuery, SQL/XML, and FIXML technolgies employed in real world case studies.

Learn XSLT

Free online video demonstrations for learning XSLT and how to design XSLT stylesheets to convert XML to HTML in publishing applications, or how to convert HTML to XML.

Java Code Generation

The Stylus Studio Java Codce Generator lets you generate deployable Java code for XQuery and XSLT at the push of a button!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member