title: Get the n-th closest descendant using xpath
body: <p>I have the many similar documents shown below. The names of <code>random0</code>, <code>random1</code>, and <code>random2</code> tags vary across documents. The number of list tags is not fixed. How do I use <code>xpath</code> to get the n-th closest descendant list tag from the content tag i.e. if <code>n == 1</code> return <code>1,2,3,10,11, 12</code>; if <code>n == 2</code> return <code>4,5,6</code>; and so on. Note: The closest descendant list tag may be a child, grandchild or even further.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;content&gt;
       &lt;random0&gt;
          &lt;list&gt;1&lt;/list&gt;
          &lt;list&gt;2&lt;/list&gt;
          &lt;list&gt;3&lt;/list&gt;
          &lt;random1&gt;
              &lt;list&gt;4&lt;/list&gt;
              &lt;list&gt;5&lt;/list&gt;
              &lt;list&gt;6&lt;/list&gt;
              &lt;random2&gt;
                  &lt;list&gt;7&lt;/list&gt;
                  &lt;list&gt;8&lt;/list&gt;
                  &lt;list&gt;9&lt;/list&gt;
              &lt;/random2&gt;
          &lt;/random1&gt;
          &lt;list&gt;10&lt;/list&gt;
          &lt;list&gt;11&lt;/list&gt;
          &lt;list&gt;12&lt;/list&gt;
      &lt;/random0&gt;
  &lt;/content&gt;
  </code></pre>