title: How to do group capture in xpath
body: <p>I am looking for something in xpath can do: <code>//foo[@n="$1"]//bar[@n="$2"]</code>
  which can return me <code>$1</code> and <code>$2</code>.  Or at least return me both <code>&lt;foo&gt;</code> and <code>&lt;bar&gt;</code></p>
  
  <p>Here is more detail, I have a xml document:</p>
  
  <pre><code>&lt;xml&gt;
    &lt;foo&gt;
      &lt;a n="1"&gt;
        &lt;b n="1"/&gt;
        &lt;b n="2"/&gt;
      &lt;/a&gt;
    &lt;/foo&gt;
    &lt;a n="2"&gt;
      &lt;b n="1"/&gt;
    &lt;/a&gt;
    &lt;a n="3"&gt;
      &lt;b n="1"/&gt;
      &lt;foo&gt;
        &lt;b n="2"/&gt;
      &lt;/foo&gt;
      &lt;b n="3"/&gt;
    &lt;/a&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>I want generate a string base on the n attribute in <code>&lt;a&gt;</code> and <code>&lt;b&gt;</code>
  So I have xpath: <code>//a[@n]//b[@n]</code>
  Then for every result I get back, I use: <code>./@n</code> and <code>./ancestor::a/@n</code> to get the info I want.</p>
  
  <p>This is working fine, but I need something more intelligent, because I have a lot structure like this, and need auto generate the xpath.</p>
  
  <p>So for above example, I am looking for some xpath like: <code>//a[@n="$1"]//b[@n="$2"]</code>
  Then return me:
  `(1, 1), (1, 2), (2, 1), (3, 1), (3, 2), (3, 3)</p>