Adding <xsl:template> elements to XSL files

<xsl: template> elements are the most important elements in XSLT. They are the basis for matching routines to perform a transformation.

The <xsl: template> element should contain at least a match or a name attribute. The match attribute is used to match a pattern. The name attribute is used to give a name to a template. You can also use both in the same template if you want to.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives.

Follow these steps to add an <xsl:template> element to your XSL file. The <xsl:template> element will be displayed in a read-only field as it is created:

  1. Open your XSL file in the XSL editor.
  2. Click the Snippets tab, open the XSL drawer, and then double-click xsl: template element.
  3. The match attribute is used to match a pattern. In the Match field, enter the XPath pattern you want the template to match in the input document. Click XPath if you want to create the XPath pattern using the XPath Expression wizard.
  4. The name attribute is used to give a name to a template. In the Name field, enter the name of the template you want to be able to explicitly call in your style sheet.
  5. The priority attribute is used to assign a priority to the template. Specify the priority you want the template to have in the Priority field. This priority is used to select one template out of all the templates that match the pattern used in an <xsl: apply-templates> element. For example, a template with a priority of 2 would be selected before a template with a priority of 5.
  6. The mode attribute is used to partition templates into different categories. Specify the mode you want the template to have in the Mode field.
  7. Click the Add Parameter button to add a parameter to the template. 
    1. In the Name field, type the name of the parameter.
    2. In the Select field, type the default value of the parameter. Click XPath if you want to use the XPath Expression wizard to create the default value.
  8. Click Finish.
The  <xsl:template> element will be inserted into in the XSL file
Related concepts
XSL editor

Feedback