title: How to perform set operations in XPath 1.0
body: <p>I've seen on SO and other places that the following is supposed to work (this example is lifted directly from O'Reilly's XSLT Cookbook):</p>
  
  <pre><code>(: intersection :)
  $set1[count(. | $set2) = count($set2)]
  
  (: difference :)
  $set1[count(. | $set2) != count($set2)]
  </code></pre>
  
  <p>and it looks like it should be OK, however this seems to fail when used with actual paths rather than variables. For example, given the following document</p>
  
  <pre><code>&lt;a&gt;
    &lt;new&gt;
      &lt;val&gt;1&lt;/val&gt;
      &lt;val&gt;2&lt;/val&gt;
    &lt;/new&gt;
    &lt;old&gt;
      &lt;val&gt;2&lt;/val&gt;
      &lt;val&gt;3&lt;/val&gt;
    &lt;/old&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>and the XPath expression <code>/a/new/val[count(. | /a/old/val)=count(/a/old/val)]/text()</code> I would expect to get the node-set <code>{ 2 }</code> but instead am getting <code>{ 1 2 }</code>. Any ideas what I'm doing wrong?</p>