[xslt] equality expression bug?



Consider this stylesheet that tests three != 0 expressions. You can run it
against any XML file, as all it does it output messages to indicate
expression results.

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

<xsl:template match="/">
  <xsl:variable name="text" select="'A'"/>
  <xsl:variable name="node">B</xsl:variable>

  <xsl:choose>
    <xsl:when test="$text != 0">
      <xsl:message>text value A is not equal to zero</xsl:message>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>text value A is *not* not equal to zero!</xsl:message>
    </xsl:otherwise>
  </xsl:choose>

  <xsl:choose>
    <xsl:when test="$node != 0">
      <xsl:message>node value B is not equal to zero</xsl:message>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>node value B is *not* not equal to zero!</xsl:message>
    </xsl:otherwise>
  </xsl:choose>

  <xsl:choose>
    <xsl:when test="string($node) != 0">
      <xsl:message>node string value B is not equal to zero</xsl:message>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>node string value B is *not* not equal to
zero!</xsl:message>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

When I run it with xsltproc from libxslt version 10114CVS1011 on Windows XP,
I get:

text value A is not equal to zero
node value B is *not* not equal to zero!
node string value B is not equal to zero

Does anyone else think the middle test produces the wrong result?  My
understanding is that in equality expressions, if one operand is a number
then the other is converted to a number.  Converting a node means first
converting it to a string and then converting that string to a number.  So
that node conversion should yield NaN, which should not be equal to zero. Am
I missing something, or should I file a bug report?

Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs sagehill net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]