Best way to start writing an XSLT

I am frequently asked where to start when writing an XSL?. 

I always start by writing a simple identity transform:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
<xsl:template match="node(  ) | @">
  <xsl:copy>
    <xsl:apply-templates select="@
| node(  )"/>
  </xsl:copy>
</xsl:template>
   
</xsl:stylesheet>

(quoted from “XSLT Cookbook” by Sal Mangano).

This simple stylesheet will do nothing but copy the input XML file element by element, attribute by attribute. You can customize it from here. An empty <xsl:template match=”node( ) | @*”> will “swallow” every node and attribute and can be used to get rid of the “dangling text nodes” problem a lot of my colleagues complain about.