title: XPath query with variable multiple conditions
body: <p>Long-time listener, first-time caller. I'm relatively new to XPath and looked at several other threads here and elsewhere but I can't seem to get a query working, any help would be great.</p>
  
  <p>I have XML as follows:</p>
  
  <pre><code>&lt;catalog&gt;
    &lt;book pgid="28054" lang="en"&gt;
      &lt;title&gt;The Brothers Karamazov&lt;/title&gt;
      &lt;author&gt;Dostoyevsky, Fyodor&lt;/author&gt;
      &lt;friendly_title&gt;The Brothers Karamazov by Fyodor Dostoyevsky&lt;/friendly_title&gt;
      &lt;file&gt;
        &lt;type&gt;ePub&lt;/type&gt;
        &lt;path&gt;cache/generated/28054/&lt;/path&gt;
        &lt;name&gt;pg28054.epub&lt;/name&gt;
        &lt;size&gt;800&lt;/size&gt;
      &lt;/file&gt;
      &lt;file&gt;
        &lt;type&gt;PDF&lt;/type&gt;
        &lt;path&gt;2/8/0/5/28054/&lt;/path&gt;
        &lt;name&gt;28054-pdf.pdf&lt;/name&gt;
        &lt;size&gt;5829&lt;/size&gt;
      &lt;/file&gt;
      &lt;file&gt;
        &lt;type compression="zipped"&gt;PDF&lt;/type&gt;
        &lt;path&gt;2/8/0/5/28054/&lt;/path&gt;
        &lt;name&gt;28054-pdf.zip&lt;/name&gt;
        &lt;size&gt;1693&lt;/size&gt;
      &lt;/file&gt;
      &lt;file&gt;
        &lt;type encoding="utf-8" compression="zipped"&gt;Text&lt;/type&gt;
        &lt;path&gt;2/8/0/5/28054/&lt;/path&gt;
        &lt;name&gt;28054-0.zip&lt;/name&gt;
        &lt;size&gt;726&lt;/size&gt;
      &lt;/file&gt;
    &lt;/book&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>(catalog is the root element, and in this example there are no <code>&lt;contributor&gt;</code> elements)</p>
  
  <p>I have the query working on author, contributor, title, and language searches, but I am getting hung up on adding a file type condition. This query to find books with author OR contributor containing "Dostoyevsky" and title containing "Brothers" with language "en" is <em>working</em> (i.e. giving expected results), but if there's a better way to write it I'm all ears:</p>
  
  <pre><code>/catalog//book/*[(contains(self::author,'Dostoyevsky') or contains(self::contributor,'Dostoyevsky')) and contains(../title,'Brothers') and ../@lang = 'en']
  </code></pre>
  
  <p>What I <em>can't</em> get to work is limiting the query results to files of a certain type, i.e. appending <code>and ../file/type='PDF'</code> or something. Didn't have any luck with <code>|</code> unions either.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Oh, and if it matters, the query needs to be built dynamically (from form input), so it needs to retain a universal syntax that would work with any number of user-supplied criteria.</p>