The Talented Identity Transformation

The XSLT identity transformation is a stylesheet that transforms a document into itself. It does this using a single template that matches any node or any attribute ("node( )|@*") and whose content is the single <xsl:copy> action that copies the current node. Example 9.1 shows what the identity transformation looks like:

Example 9-1. The XSLT Identity Transformation

<!-- The Identity Transformation -->
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <!-- Whenever you match any node or any attribute -->
  <xsl:template match="node( )|@*">
    <!-- Copy the current node -->
      <!-- Including any attributes it has and any child nodes -->
      <xsl:apply-templates select="@*|node( )"/>

The <xsl:copy> action copies the current node and its namespaces; however, by default it doesn’t copy any of the current node’s attributes or child nodes. You indicate which attributes and child nodes should be copied by instantiating them in the body of the <xsl:copy> element. In the case of the identity transformation, the template selects all attributes and all child nodes to be included recursively.

Renaming and Suppressing Elements

Whenever you want to make global changes to a document but leave its fundamental structure intact, the identity transformation is a great place to start. By importing the Identity.xsl stylesheet into your new transformation, you can provide additional templates ...

Get Building Oracle XML Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.