Template concepts

Template matching

Formatting using XSLT works by selecting an element in the source document, then choosing an appropriate template. The chosen template specifies an output format to apply to that element. A template is represented by the XML element Template:

						<template>...</template>
					

The Match attribute is used to specify which element the template applies to. In the following example, the template is targetted at elements named 'para'. It is not used to process the 'title' and 'note' elements:

<template match="para">...</template>

   <title>The Title</title>
   <para>A source paragraph.</para>
   <note>A note.</note>
   <para>Another source paragraph.</para>
					

To be more precise, an element name appearing in the Match attribute is actually ...

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.