title: How can I use the Xpath function 'contains()' to return nothing if it's search param is blank or missing/false?
body: <p>I'm trying to write an Xpath Statement (1.0) that can read info from a 'search' node and perform a search using it.</p>
  
  <p>I was making some nice progress, but stumbled across an issue where if an attribute (used for a value in the search) is empty or doesn't exist, it fails.</p>
  
  <p><strong>Code Edited to simplify Example:</strong></p>
  
  <p>So Here is my sample XML:</p>
  
  <pre><code>&lt;xml&gt;
      &lt;files&gt;
          &lt;file name="foo" description="" rating="4"/&gt;
          &lt;file name="food" description="" rating="4"/&gt;
          &lt;file name="foobar" description="" rating="3"/&gt;
          &lt;file name="bar" description="" rating="3"/&gt;
          &lt;file name="barter" description="" rating="3"/&gt;
          &lt;file name="barterer" description="" rating="2"/&gt;
      &lt;/files&gt;
      &lt;searches&gt;
          &lt;search id="1"&gt;
              &lt;exclude&gt;
                  &lt;file term="foo"/&gt;
              &lt;/exclude&gt;
          &lt;/search&gt;
      &lt;/searches&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>And working XPATH:</p>
  
  <pre><code>//files/file[
              not(contains(@name, //search[@id='1']/exclude/file/@term))
  ]
  </code></pre>
  
  <p>It works as expected...</p>
  
  <p>However if the an expected attribute is missing or empty it will fail to work. I think because: contains(@attrib, "") matches everything for some-reason, therefore a not() will always match nothing if the attribute is "" or not present.</p>
  
  <p>For Example, if I alter the exclude fragment of XML to this it fails:</p>
  
  <pre><code>            &lt;exclude&gt;
                  &lt;file term=""/&gt;
              &lt;/exclude&gt;
  </code></pre>
  
  <p>with this too:</p>
  
  <pre><code>            &lt;exclude&gt;&lt;/exclude&gt;
  </code></pre>
  
  <p>Is there a way to Check for an empty value and not perform the select? or is there perhaps a better way of structuring the Logic. Bare in mind I cannot use Conditionals or the other functions in Xpath2.0.</p>