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="http://www.w3.org/1999/XSL/Transform"> <!-- Whenever you match any node or any attribute --> <xsl:template match="node( )|@*"> <!-- Copy the current node --> <xsl:copy> <!-- Including any attributes it has and any child nodes --> <xsl:apply-templates select="@*|node( )"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
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 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.