<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="expressions" page="comparisons" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Comparisons</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: Comparisons"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Comparisons</h1>
      <p>The simplest comparison operators are <code>eq</code>, <code>ne</code>, <code>lt</code>
<code>le</code>, <code>gt</code>, <code>ge</code>. These compare two atomic values of the same type,
for example two integers, two dates, or two strings. In the case of strings, the default collation
is used (see 
<a class="bodylink" href="../extensions/instructions/collation.xml">saxon:collation</a>). 
If the operands are not atomic values, an error is raised.</p>
      <p>The operators <code>=</code>, <code>!=</code>, <code>&lt;</code>, <code>&lt;=</code>,
<code>&gt;</code>, and <code>&gt;=</code> can compare arbitrary sequences. The result is true
if any pair of items from the two sequences has the specified relationship, for example
<code>$A = $B</code> is true if there is an item in <code>$A</code> that is equal to
some item in <code>$B</code>. If an argument is a node, the effect depends on whether the
source document has been validated against a schema. In Saxon-EE, with a validated source document,
Saxon will use the typed value of the node in the comparison. Without schema validation, the
type of the node is <code>untypedAtomic</code>, and the effect is that the value is converted
to the type of the other operand.</p>
      <p>The operator <code>is</code> tests whether the operands represent the same
(identical) node. For example, <code>title[1] is *[@note][1]</code> is true if the first <code>title</code>
child is the first child element that has a <code>@note</code> attribute. If either operand is an
empty sequence the result is an empty sequence (which will usually be treated as false).</p>
      <p>The operators <code>&lt;&lt;</code> and <code>&gt;&gt;</code> test whether one node precedes
or follows another in document order.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="instanceof.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>