<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
  
  <!-- start recursive-descent processing at the root -->
  <xsl:template match="/">
    <xsl:apply-templates select="child::node()"/>
  </xsl:template>
  
  <!-- output elements, with attributes converted to child elements -->
  <xsl:template match="*">
    <xsl:element name="{name()}">
      <!-- convert attributes to child elements -->
      <xsl:for-each select="attribute::*">
        <xsl:element name="{name()}"><xsl:value-of select="."/></xsl:element>
      </xsl:for-each>
      <!-- preserve namespace nodes -->
      <xsl:for-each select="namespace::*">
        <!-- not easy; best to wait for XSLT 2.0 -->
      </xsl:for-each>
      <xsl:apply-templates select="child::node()"/>
    </xsl:element>
  </xsl:template>
  
  <!-- output text verbatim -->
  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>
  
  <!-- output PIs verbatim -->
  <xsl:template match="processing-instruction()">
    <xsl:processing-instruction name="{name()}"><xsl:value-of select="."/></xsl:processing-instruction>
  </xsl:template>
  
  <!-- output comments verbatim -->
  <xsl:template match="comment()">
    <xsl:comment><xsl:value-of select="."/></xsl:comment>
  </xsl:template>
  
</xsl:stylesheet>
