Named templates

When the same output structures are required in a number of circumstances, it is possible to create a template to hold them. This template can be named, and referenced from other templates.

Simple referenced templates

The template is given a name using the Name attribute. For example, a dividing line may need to be output above a number of different output structures:

<xsl:template name="divideLine">
  <BR/><HR/><BR/>
</xsl:template>

This template can be referenced from within other templates using the Call Template element. This element also has a Name attribute, which is used to name the template to use:

<xsl:template name="chapter">
  <xsl:call-template name="divideLine"/> <H1>NEW CHAPTER</H1><xsl:apply-templates/> </xsl:template> ...

Get XSL companion, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.