<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>

  <!-- pass the document's children to our converter -->
  <xsl:template match="/">
    <xsl:call-template name="converter">
      <xsl:with-param name="nodes" select="child::node()"/>
    </xsl:call-template>
  </xsl:template>

  <!-- convert all attributes to child elements, leaving rest of document as-is -->
  <xsl:template name="converter">
    <xsl:param name="nodes"/>
    
    <!-- iterate through each node in given nodeset-->
    <xsl:for-each select="$nodes">
    
      <!-- act differently based on each node's type -->
      <xsl:choose>

        <!-- else if current node's a comment, output it as-is -->
        <xsl:when test="self::comment()">
          <xsl:comment><xsl:value-of select="."/></xsl:comment>
        </xsl:when>

        <!-- else if current node's a PI, output it as-is -->
        <xsl:when test="self::processing-instruction()">
          <xsl:processing-instruction name="{name()}"><xsl:value-of select="."/></xsl:processing-instruction>
        </xsl:when>

        <!-- else if current node's text, output it as-is -->
        <xsl:when test="self::text()"><xsl:value-of select="."/></xsl:when>
        
        <!-- else if current node's an element, output it as-is -->  
        <xsl:otherwise>
          <xsl:element name="{name()}">
          
            <!-- output each attribute as a child element -->
            <xsl:for-each select="attribute::*">
              <xsl:element name="{name()}"><xsl:value-of select="."/></xsl:element>
            </xsl:for-each>
            
            <!-- now convert this node's children -->
            <xsl:call-template name="converter">
              <xsl:with-param name="nodes" select="child::node()"/>
            </xsl:call-template>
          </xsl:element>
        </xsl:otherwise>
        
      </xsl:choose>
      
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
