An important part of learning XSL is understanding the identity template.

What is the “XSL Identity Template”?

An XSL identity template will transform an XML document into itself, meaning the input will be the same as the output.

It doesn’t sound very important, but it actually is. The importance comes with the ability to change only a tiny bit of the document, or a selection of the document.

The identity template can be implemented many ways. Here’s an example:

<!-- XHTML FRIENDLY IDENTITY TEMPLATE FOR ELEMENTS-->
<xsl:template match="node()">
  <xsl:element name="{name()}">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:element>
</xsl:template>
<!-- XHTML FRIENDLY IDENTITY TEMPLATE FOR CONTENT AND ATTRIBUTES -->
<xsl:template match="@*|text()|processing-instruction()">
  <xsl:copy/>
</xsl:template>
<xsl:template match="comment()">
  <xsl:copy/>
</xsl:template>