title: Passing an xpath expression to an xpath result
body: <p>I'm struggling to understand parts of the lxml library for python.</p>
  
  <p>Take the following html file, <em>sample.html</em>.</p>
  
  <pre><code>&lt;div class="team"&gt;
      &lt;ul class="team-members"&gt;
          &lt;li class="team-member"&gt;
                  &lt;span class="team-member-name"&gt;John Doe&lt;/span&gt;
                  &lt;span class="team-member-age"&gt;30&lt;/span&gt;
              &lt;/li&gt;
          &lt;li class="team-member"&gt;
                  &lt;span class="team-member-name"&gt;Jane Doe&lt;/span&gt;
                  &lt;span class="team-member-age"&gt;32&lt;/span&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;div class="team"&gt;
      &lt;ul class="team-members"&gt;
          &lt;li class="team-member"&gt;
                  &lt;span class="team-member-name"&gt;Joe Smith&lt;/span&gt;
                  &lt;span class="team-member-age"&gt;28&lt;/span&gt;
              &lt;/li&gt;
          &lt;li class="team-member"&gt;
                  &lt;span class="team-member-name"&gt;Jill Smith&lt;/span&gt;
                  &lt;span class="team-member-age"&gt;41&lt;/span&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I can import this html into an lxml tree:</p>
  
  <pre><code>from lxml import html
  
  file = open("sample.html",'r')
  sample = file.read()
  
  tree = html.fromstring(sample)
  </code></pre>
  
  <p>Then I can use an xpath to get a list of all the text atoms in the html like so:</p>
  
  <pre><code>tree.xpath('//text()')
  </code></pre>
  
  <p>My problem arises when I pass an xpath like the following:</p>
  
  <pre><code>elements = tree.xpath("//li")
  </code></pre>
  
  <p>Printing elements yields</p>
  
  <pre><code>[&lt;Element li at 0x48be638&gt;,
   &lt;Element li at 0x48be9f8&gt;,
   &lt;Element li at 0x48beb88&gt;,
   &lt;Element li at 0x48bec78&gt;]
  </code></pre>
  
  <p>I can pass xpaths to each of these, but each one behaves just like the original tree! So for example,</p>
  
  <pre><code>elements[0].xpath('//text()')
  </code></pre>
  
  <p>appears to return exactly the same list as above. However, </p>
  
  <pre><code>elements[0].tag
  </code></pre>
  
  <p>returns 'li', so each elements appears to have some record of where it came from.</p>
  
  <p><em>Question:</em> Ideally, I would like to be able to access each of the list members in the html document individually, and pass an xpath to each. Is something like that possible? What information does each 'Element li' actually contain?</p>