title: xpath - get count of rows based on some text
body: <p>I'm writing xpaths to select all the links under each category on left sidebar from following page:
  http://www.indexmundi.com/commodities/'><a href="http://www.indexmundi.com/commodities/" rel="nofollow">http://www.indexmundi.com/commodities/</a></p>
  
  <p>I want to select the link under each category one by one. I've written the following xpath and it is selecting the link under first category(Commodity Price Indices) somehow. But I was wondering how I will select the links under other categories. I want to add a check on <strong>h3</strong> tha if it's text is <strong>Energy</strong>, count and select all the rows before that, then if <strong>h3</strong> text is <strong>Beverages</strong>, count and select all rows between <strong>Energy and Beverages</strong> </p>
  
  <p>.//*[@id='dlCommodities']/tbody/tr[position()&lt; count(following-sibling::tr/td/h3)-1]/td/a</p>
  
  <p>Here is another xpath:
  .//*[@id='dlCommodities']/tbody/tr[preceding-sibling::tr/td/h3[. = 'Energy'] and following-sibling::tr/td/h3[. = 'Beverages']]/td/a</p>
  
  <p>It is fulfilling the second requirement i.e. select rows between specific headings but it is missing one node.</p>
  
  <p>Please help me fix these xpaths or suggest a better one.</p>
  
  <p>Thanks </p>