Testing the type of the current node

Subject: Testing the type of the current node
From: Warren Hedley <w.hedley@xxxxxxxxxxxxxx>
Date: Fri, 24 Mar 2000 16:12:26 +1200
Hi

Can anyone tell me what is wrong with the following stylesheet?

In the "analyse_node" (I speak English, not American) template
I'm trying to determine the type of the current node and print
out an appropriate message. Currently only the element test
self::* works. I would have thought that self::text() would
return true if the current node was text - but it keeps passing
straight through to the <xsl:otherwise> branch.

Thanks in advance.

----

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">


<xsl:output method="text" />


<xsl:template name="indent">
  <xsl:param name="indent" />
  <xsl:if test="$indent > 0">
    <xsl:text>  </xsl:text>
    <xsl:call-template name="indent">
      <xsl:with-param name="indent" select="$indent - 1" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>


<xsl:template name="analyse_node">
  <xsl:param name="indent" />

  <xsl:call-template name="indent">
    <xsl:with-param name="indent" select="$indent" />
  </xsl:call-template>

  <xsl:for-each select="child::node()">
    <xsl:choose>
      <xsl:when test="self::*">
        <xsl:text>ELEMENT : `</xsl:text>
        <xsl:value-of select="name(.)" />
        <xsl:text>'
</xsl:text>
        <xsl:call-template name="analyse_node">
          <xsl:with-param name="indent" select="$indent + 1" />
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="self::text()">
        <xsl:text>TEXT : `</xsl:text>
        <xsl:value-of select="." />
        <xsl:text>'
</xsl:text>
      </xsl:when>
      <xsl:when test="self::comment()">
        <xsl:text>COMMENT : `</xsl:text>
        <xsl:value-of select="." />
        <xsl:text>'
</xsl:text>
      </xsl:when>
      <xsl:when test="self::processing-instruction()">
        <xsl:text>PI : `</xsl:text>
        <xsl:value-of select="." />
        <xsl:text>'</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>UNKNOWN OBJECT : ` </xsl:text>
        <xsl:value-of select="." />
        <xsl:text>'
</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>


<xsl:template match="/">
  <xsl:call-template name="analyse_node">
    <xsl:with-param name="indent" select="0" />
  </xsl:call-template>
</xsl:template>


</xsl:stylesheet>

-- 
Warren Hedley
Department of Engineering Science
Auckland University
New Zealand


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread