My XML file looks like this:
<log>
<entry entry_id="E200911115777">
<entry_data>
<entry_title>Lorem ipsum dolor</entry_title>
<entry_date>1999-04-15</entry_date>
</entry_data>
</entry>
<entry entry_id="E205011115999">
<entry_data>
<entry_title>Lorem ipsum dolor</entry_title>
<entry_date>2004-12-15</entry_date>
</entry_data>
</entry>
<entry entry_id="E199912119116">
<entry_data>
<entry_title>Lorem ipsum dolor</entry_title>
<entry_date>1990-11-20</entry_date>
</entry_data>
</entry>
</log>
I'm looking for code that will return the highest value of the entry_date tag, in this case, 2004-12-15. I'm using SimpleXML but I'm open to other solutions of course. Cheers.
I. Here is a simple XSLT 1.0 solution that is closest to using a single XPath expression (it isn't possible to have just a single XPath 1.0 expression selecting the wanted node(s) ):
when this transformation is applied on the provided XML document:
the wanted, correct result is produced:
II. A more efficient XSLT 1.0 solution:
when this transformation is applied on the same XML document (above), again the wanted, correct result is produced:
Yeah, should be quite easy with xpath, that is definately the way to go, and simple xml works well with xpath in php.
Check out the docs here: http://www.php.net/manual/en/simplexmlelement.xpath.php
I didn't actually test that code, but should be pretty close to what you need, and timestamps of course have their limits but seems ok for your use.