title: Select first result in XPath
body: <p>I've looked at this question: <a href="https://stackoverflow.com/questions/453191/select-first-instance-only-with-xpath">Select first instance only with XPath?</a></p>
  
  <p>But if I have a node-set like this:</p>
  
  <pre><code>
  &lt;container value=""&gt;
    &lt;data id="1"&gt;&lt;/data&gt;
    &lt;data id="2"&gt;test&lt;/data&gt;
    &lt;container&gt;
      &lt;data id="1"&gt;test&lt;/data&gt;
      &lt;data id="3"&gt;test&lt;/data&gt;
    &lt;/container&gt;
  &lt;/container&gt;
  </code></pre>
  
  <p>Now my scenario is that this node-set is deep inside a document, and I have a pointer to the inner container. So I have to prefix my XPath with "/container/container" (the path is actually longer, but for this example this should do).</p>
  
  <p>EDIT:
  What I want is a "data" node with an id of 1, which should come from the lowest node first or the closest ancestor. So, if I can't find it on the "current" (/container/container) I should look at the ancestors and get the nearest one (or in the end, not find anything). I have tried this:</p>
  
  <p><b>/container/container/ancestor-or-self::container/data[@id="1"]</b></p>
  
  <p>Which brings back a result set with two nodes. I thought I could use last() to get the deepest one, so I tacked that on the end, but to no avail.</p>