title: XPath predicate with sub-paths with lxml?
body: <p>I'm trying to understand and XPath that was sent to me for use with ACORD XML forms (common format in insurance).  The XPath they sent me is (truncated for brevity):</p>
  
  <pre><code>./PersApplicationInfo/InsuredOrPrincipal[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd="AN"]/GeneralPartyInfo
  </code></pre>
  
  <p>Where I'm running into trouble is that Python's <a href="http://lxml.de/" rel="noreferrer"><code>lxml</code> library</a> is telling me that <code>[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd="AN"]</code> is an <code>invalid predicate</code>.  I'm not able to find anywhere in the <a href="http://www.w3.org/TR/xpath/#NT-Predicate" rel="noreferrer">XPath spec on predicates</a> which identifies this syntax so that I can modify this predicate to work.</p>
  
  <p>Is there any documentation on what exactly this predicate is selecting?  Also, is this even a valid predicate, or has something been mangled somewhere?</p>
  
  <p><strong>Possibly related:</strong></p>
  
  <p>I believe the company I am working with is an MS shop, so this XPath may be valid in C# or some other language in that stack?  I'm not entirely sure.</p>
  
  <p><strong>Updates:</strong></p>
  
  <p>Per comment demand, here is some additional info.</p>
  
  <p>XML sample:</p>
  
  <pre><code>&lt;ACORD&gt;
    &lt;InsuranceSvcRq&gt;
      &lt;HomePolicyQuoteInqRq&gt;
        &lt;PersPolicy&gt;
          &lt;PersApplicationInfo&gt;
              &lt;InsuredOrPrincipal&gt;
                  &lt;InsuredOrPrincipalInfo&gt;
                      &lt;InsuredOrPrincipalRoleCd&gt;AN&lt;/InsuredOrPrincipalRoleCd&gt;
                  &lt;/InsuredOrPrincipalInfo&gt;
                  &lt;GeneralPartyInfo&gt;
                      &lt;Addr&gt;
                          &lt;Addr1&gt;&lt;/Addr1&gt;
                      &lt;/Addr&gt;
                  &lt;/GeneralPartyInfo&gt;
              &lt;/InsuredOrPrincipal&gt;
          &lt;/PersApplicationInfo&gt;
        &lt;/PersPolicy&gt;
      &lt;/HomePolicyQuoteInqRq&gt;
    &lt;/InsuranceSvcRq&gt;
  &lt;/ACORD&gt;
  </code></pre>
  
  <p>Code sample (with full XPath instead of snippet):</p>
  
  <pre><code>&gt;&gt;&gt; from lxml import etree
  &gt;&gt;&gt; tree = etree.fromstring(raw)
  &gt;&gt;&gt; tree.find('./InsuranceSvcRq/HomePolicyQuoteInqRq/PersPolicy/PersApplicationInfo/InsuredOrPrincipal[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd="AN"]/GeneralPartyInfo/Addr/Addr1')
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "lxml.etree.pyx", line 1409, in lxml.etree._Element.find (src/lxml/lxml.etree.c:39972)
    File "/Library/Python/2.5/site-packages/lxml-2.3-py2.5-macosx-10.3-i386.egg/lxml/_elementpath.py", line 271, in find
      it = iterfind(elem, path, namespaces)
    File "/Library/Python/2.5/site-packages/lxml-2.3-py2.5-macosx-10.3-i386.egg/lxml/_elementpath.py", line 261, in iterfind
      selector = _build_path_iterator(path, namespaces)
    File "/Library/Python/2.5/site-packages/lxml-2.3-py2.5-macosx-10.3-i386.egg/lxml/_elementpath.py", line 245, in _build_path_iterator
      selector.append(ops[token[0]](_next, token))
    File "/Library/Python/2.5/site-packages/lxml-2.3-py2.5-macosx-10.3-i386.egg/lxml/_elementpath.py", line 207, in prepare_predicate
      raise SyntaxError("invalid predicate")
  SyntaxError: invalid predicate
  </code></pre>