[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
xsl when test self
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.