title: lxml/Python : get previous-sibling
body: <p>I have the following html:</p>
  
  <pre><code>&lt;div id = "big"&gt;
      &lt;span&gt;header 1&lt;/span&gt;
      &lt;ul id = "outer"&gt;
          &lt;li id = "inner"&gt;aaa&lt;/li&gt;
          &lt;li id = "inner"&gt;bbb&lt;/li&gt;
      &lt;/ul&gt;
  
      &lt;span&gt;header 2&lt;/span&gt;
      &lt;ul id = "outer"&gt;
          &lt;li id = "inner"&gt;ccc&lt;/li&gt;
          &lt;li id = "inner"&gt;ddd&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want it to loop it in the order:</p>
  
  <pre><code>header 1
  aaa
  bbb
  header 2
  ccc
  ddd
  </code></pre>
  
  <p>I have tried looping through each ul and then printing the header and the li values. However, I don't know how to get the span header that is associated with a ul.</p>
  
  <pre><code>sets = tree.xpath("//div[@id='big']//ul[@id='outer']")
  
  for set in sets:
  
      # Print header. Not sure how to get it
      header = set.xpath(".//li/preceding-sibling::span")
      print header 
  
      # Print texts. This works.
      values = set.xpath(".//li//text()")
      for v in values:
          print v 
  </code></pre>
  
  <p>Just looping all text nodes won't work because I need to know if it is a header or li value.</p>