title: PHP XPath selecting last matching element
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/295112/php-simplexml-how-to-get-the-last-item">PHP SimpleXML. How to get the last item?</a><br>
    <a href="https://stackoverflow.com/questions/4672997/xslt-select-all-nodes-containing-a-specific-substring">XSLT Select all nodes containing a specific substring</a>  </p>
  </blockquote>
  
  
  
  <p>I need to find the contents of the last span element with a class of 'myClass'. I've tried various combinations but can't find the answer.</p>
  
  <pre><code>//span[@class='myPrice' and position()=last()]
  </code></pre>
  
  <p>This returns all the elements with class 'myClass', I'm guessing this is because each found element is the last at the time of processing - but I just need the actual last matching element. </p>