Docunext


Identity Template

December 15th, 2009

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>
Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022