not() Function  
Returns the negation of its argument. If the argument is not a boolean value already, it is converted to a boolean value using the rules described in the boolean() function entry.
 
Inputs

A boolean value, or more commonly, an XPath expression that evaluates to a boolean value.

 
Output

false if the input parameter is true; true if the input parameter is false.

 
Defined in

XPath section 4.3, Boolean Functions.

 
Example

To demonstrate the not() function, we'll use the same stylesheet and XML document we used for the boolean() function. Here's our XML document:

<?xml version="1.0"?>
<test>
<p>This is a test XML document used by several 
of our sample stylesheets.</p>
<question>
<text>When completed, the Eiffel Tower was the 
tallest building in the world.</text>
<true>Yes!  The Eiffel Tower was the world's 
tallest building until 1932, when
New York's Empire State Building opened. </true>
<false>No, the Eiffel Tower was the world's 
tallest building for over 30 years.</false>
</question>
</test>

We'll process this document with the following stylesheet, which uses the not() to negate all boolean() function calls:

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

  <xsl:output method="text"/>

  <xsl:variable name="newline">
<xsl:text>
</xsl:text>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:value-of select="$newline"/>
    <xsl:text>Tests of the not() function:</xsl:text>

    <xsl:value-of select="$newline"/>
    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean(true()))">
        <xsl:text>   "not(boolean(true()))"   returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean(true()))"   returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean(true))">
        <xsl:text>   "not(boolean(true))"     returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean(true))"     returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean('false'))">
        <xsl:text>   "not(boolean('false'))"  returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean('false'))"  returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean('7'))">
        <xsl:text>   "not(boolean('7'))"      returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean('7'))"      returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean(/true))">
        <xsl:text>   "not(boolean(/true))"    returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean(/true))"    returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="$newline"/>
    <xsl:choose>
      <xsl:when test="not(boolean(//true))">
        <xsl:text>   "not(boolean(//true))"   returned true!</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>   "not(boolean(//true))"   returned false!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

Here are the results:


Tests of the not() function:

   "not(boolean(true()))"   returned false!
   "not(boolean(true))"     returned true!
   "not(boolean('false'))"  returned false!
   "not(boolean('7'))"      returned false!
   "not(boolean(/true))"    returned true!
   "not(boolean(//true))"   returned false!

As you'd expect, these results are the exact opposite of the results we got when we tested the boolean() function.