1

I have a requirement where I need the latest date from the XML below. In Xpath 2.0, there is function called max(). But am using Xpath1.0.

<Info><Date>2014-04-21</Date></Info><Info><Date>2014-05-05</Date></Info><Info><Date>2014-04-28</Date></Info>

Expected Output: 05/05/2014(dd/mm/yyyy)

Any inputs ??

HookUp
  • 393
  • 1
  • 6
  • 20
  • I can't see an efficient way to do all of this in a _single_ XPath 1.0 expression. Would it be acceptable to use one expression to determine which `Info` element has the latest date, and then a second expression to convert it to dd/mm/yyyy? What tool/library/programming language are you using to evaluate your xpaths? – Ian Roberts May 06 '14 at 09:10
  • Yes it is not recommended to use it in a single expression. Could you please tell me how do we do that ? And it is not needed to convert to dd/mm/yyyy, it was just a sample output. The output can be of any format, but with the max date. – HookUp May 06 '14 at 09:14
  • You might able to combine [Sweet Lou's answer](http://stackoverflow.com/a/23490827/1816580) with [this](http://stackoverflow.com/questions/8702039/how-to-find-the-max-attribute-from-an-xml-document-using-xpath-1-0). – Artjom B. May 06 '14 at 12:46

1 Answers1

1

Actually there is small change in my xml. The following is my XML(extra parent node is added).

<CustomContent>
<Info>
<Name>abc</Name>
<Date>2014-04-21</Date>
</Info>
<Info>
<Name>def</Name>
<Date>2014-05-05</Date>
</Info>
<Info>
<Name>ghi</Name>
<Date>2014-04-28</Date>
</Info>
</CustomContent>

Now here is the Xpath to find the max date for the above XML.

//CustomContent/Info/Date[not(text() <= preceding::Date/text()) and not(text() <=following::Date/text
())]/text()

Thanks everyone :)

HookUp
  • 393
  • 1
  • 6
  • 20