title: Python, lxml - get a sibling tag's (grand)child's text
body: <p>I have an XML to parse which is proving really tricky for me. </p>
  
  <pre><code>&lt;bundles&gt;
    &lt;bundle&gt;
      &lt;bitstreams&gt;
        &lt;bitstream&gt;
          &lt;id&gt;1234&lt;/id&gt;
        &lt;/bitstream&gt;
      &lt;/bitstream&gt;
      &lt;name&gt;FOO&lt;/name&gt;
    &lt;/bundle&gt;
    &lt;bundle&gt; ... &lt;/bundle&gt;
  &lt;/bundles&gt;
  </code></pre>
  
  <p>I would like to iterate through this XML and locate all the <strong>id</strong> values inside of the <strong>bitstreams</strong> for a <strong>bundle</strong> where the <strong>name</strong> element's value is 'FOO'. I'm not interested in any bundles not named 'FOO', and there may be any number of bundles and any number of bitstreams in the bundles.</p>
  
  <p>I have been using <code>tree.findall('./bundle/name')</code> to find the FOO bundle but this just returns a list that I can't step through for the <strong>id</strong> values:</p>
  
  <pre><code>for node in tree.findall('./bundle/name'):
  if node.text == 'FOO':
   id_values = tree.findall('./bundle/bitstreams/bitstream/id')
   for value in id_values:
       print value.text
  </code></pre>
  
  <p>This prints out <em>all</em> the id values, not those of the bundle 'FOO'. </p>
  
  <p>How can I iterate through this tree, locate the <strong>bundle</strong> with the <strong>name</strong> FOO, take this <strong>bundle</strong> node and collect the <strong>id</strong> values nested in it? Is the XPath argument incorrect here?</p>
  
  <p>I'm working in Python, with <code>lxml</code> bindings - but any XML parser I believe would be alright; these aren't large XML trees.</p>