<?xml version="1.0"?> 
<!-- nslist.xsl: report on element and attribute namespaces
     in source document. 2003-08-11 Bob DuCharme no warranty
     expressed or implied. -->


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

<xsl:output method="xml" indent="yes" encoding="us-ascii"/>

  <!-- Report on namespace of context node. -->
  <xsl:template name="nsRpt">
    <xsl:choose>
      <xsl:when test="namespace-uri(.)">
        <xsl:value-of select="namespace-uri(.)"/>
      </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><xsl:text>
</xsl:text>
      <xsl:text>* Namespaces for following element *</xsl:text>
      <xsl:text>
</xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text> element - </xsl:text>
      <xsl:call-template name="nsRpt"/>
      <xsl:if test="@*">
        <xsl:text>
</xsl:text>
        <xsl:text>attr namespaces - </xsl:text>
        <xsl:for-each select="@*">
          <xsl:text>
</xsl:text>
          <xsl:text>  </xsl:text>
          <xsl:value-of select="name()"/>
            <xsl:text> </xsl:text>
            <xsl:call-template name="nsRpt"/>
        </xsl:for-each>
      </xsl:if>
    </xsl:comment><xsl:text>
</xsl:text>
    <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>
