title: How to use python XPath to return a parent element with filtered children
body: <p>I'm working with a dataset where the 'parent' element tag is an unknown at runtime but I need to return both it and any child elements that have a certain attribute, I'm was hoping to do this with XPath but I'm no longer certain I can; can anyone give me a hand?</p>
  
  <p>Here's an example dataset:</p>
  
  <pre><code>&lt;Images&gt;
      &lt;Unknown1&gt;
          &lt;Image url="http://a.jpg" type="art" id="1"/&gt;
      &lt;/Unknown1&gt;
      &lt;Unknown2&gt;
          &lt;Image url="http://b.jpg" type="art" id="1"/&gt;
          &lt;Image url="http://c.jpg" type="art" id="2"/&gt;
          &lt;Image url="http://d.jpg" type="draft" id="3"/&gt;
          &lt;Image url="http://e.jpg" type="draft" id="4"/&gt;
          &lt;Image url="http://f.jpg" type="poster" id="5"/&gt;
          &lt;Image url="http://g.jpg" type="poster" id="6"/&gt;
      &lt;/Unknown2&gt;
  &lt;/Images&gt;
  </code></pre>
  
  <p>Now I need to filter by 'type' so what I'm looking to return is something like (if I filtered using 'art'):</p>
  
  <pre><code>    &lt;Unknown1&gt;
          &lt;Image url="http://a.jpg" type="art" id="1"/&gt;
      &lt;/Unknown1&gt;
      &lt;Unknown2&gt;
          &lt;Image url="http://b.jpg" type="art" id="1"/&gt;
          &lt;Image url="http://c.jpg" type="art" id="2"/&gt;
      &lt;/Unknown2&gt;
  </code></pre>
  
  <p>Annoyingly I don't simply need a list of all the 'Image' elements but instead a list (containing the 'Unknown' elements (the actual tags not known at runtime) and the filtered children they contain (structured like above).</p>
  
  <p>Is there any guru who could help me out? A pure XPath solution would be preferable but I'm not sure if it's feasible?</p>
  
  <p>Thanks in advance.</p>