<!-- nscomments.xsl: report on element and attribute namespaces
     in source document. 2003-08-11 Bob DuCharme no warranty
     expressed or implied. -->

<!DOCTYPE xsl:stlesheet [
<!-- To improve readability a bit... -->
<!ENTITY cr "<xsl:text>
</xsl:text>">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

  <!-- Report on namespace of context node. -->
  <xsl:template name="nsRpt">
    <xsl:choose>
      <xsl:when test="namespace-uri(.)">
		  <xsl:text>"</xsl:text>
        <xsl:value-of select="namespace-uri(.)"/>
		  <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:otherwise> (none)</xsl:otherwise>
   </xsl:choose>
  </xsl:template>

  <!-- Copy all elements, but first output a comment
       reporting on namespace of element and its attributes. -->
  <xsl:template match="*">
    <xsl:comment>&cr;
      <xsl:text>Namespace of the following </xsl:text>
		<xsl:value-of select="name()"/>
		<xsl:text> element: </xsl:text>
      <xsl:call-template name="nsRpt"/>
		&cr;
      <xsl:if test="@*">
  		  <xsl:value-of select="name()"/>
		  <xsl:text> attribute namespaces </xsl:text>
        <xsl:for-each select="@*">
          &cr;
          <xsl:text>  </xsl:text>
          <xsl:value-of select="name()"/>
            <xsl:text> </xsl:text>
            <xsl:call-template name="nsRpt"/>
        </xsl:for-each>
      </xsl:if>
		&cr;
    </xsl:comment>
	 &cr;
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- Just copy all other nodes. -->
  <xsl:template match="@*|comment()|processing-instruction()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

