title: PHP SimpleXML XPath get next parent node
body: <p>I've never asked a question here before so please forgive my question if its formatted badly or not specific enough. I am just a dabbler and know very little about PHP and XPath.</p>
  
  <p>I have an XML file like this:</p>
  
  <pre><code>&lt;catalogue&gt;
   &lt;item&gt;
    &lt;reference&gt;A1&lt;/reference&gt;
    &lt;title&gt;My title1&lt;/title&gt;
   &lt;/item&gt;
   &lt;item&gt;
    &lt;reference&gt;A2&lt;/reference&gt;
    &lt;title&gt;My title2&lt;/title&gt;
   &lt;/item&gt;
  &lt;/catalogue&gt;
  </code></pre>
  
  <p>I am pulling this file using SimpleXML:</p>
  
  <pre><code>$file = "products.xml";
  $xml = simplexml_load_file($file) or die ("Unable to load XML file!");
  </code></pre>
  
  <p>Then I am using the reference from a URL parameter to get extra details about the 'item' using PHP:</p>
  
  <pre><code>foreach ($xml-&gt;item as $item) {
  if ($item-&gt;reference == $_GET['reference']) {
   echo '&lt;p&gt;' . $item-&gt;title . '&lt;/p&gt;';
  }
  </code></pre>
  
  <p>So from a URL like www.mysite.com/file.php?reference=A1</p>
  
  <p>I would get this HTML:</p>
  
  <pre><code>&lt;p&gt;My title1&lt;/p&gt;
  </code></pre>
  
  <p>I realise I might not be doing this right and any pointers to improving this are welcome.</p>
  
  <p>My question is, I want to find the next and previous 'item' details. If I know from the URL that reference=A1, how do I find the reference, title etc of the next 'item'? If I only have 'A1' and I know that's a reference node, how do I get HTML like this:</p>
  
  <pre><code>&lt;p&gt;Next item is My title2&lt;/p&gt;
  </code></pre>
  
  <p>I have read about following-sibling but I don't know how to use it. I can only find the following-sibling of the reference node, which isn't what I need.</p>
  
  <p>Any help appreciated.</p>