Creating and copying elements

Perhaps the most significant task a stylesheet performs is the generation of XML output, including element tags. XSLT includes further methods for creating elements, and for copying elements from the source document directly to the output document.

Create element

An element can be created in the output document using the Element element, with the element name specified using the Name attribute, and an optional namespace specified using the Namespace attribute. At first, there appears to be little point to this, as the following two examples are equivalent, and the first is easier to create and interpret:

<template match="section">
  <html:H3>
    <apply-templates/>
  </html:H3>
</template>


<template match="section">
  <element ...

Get XML Companion, The, Third Edition 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.