0

I have been trying to use xPath 1.0 to find the value of an ID attribute where the date attribute is the minimum and am having no luck. Can someone help me figure this out?

Example:

<Job id="1" date="12/10/2015"/>
<Job id="2" date="12/05/2015"/>
<Job id="3" date="12/15/2015"/>

I've tried Job[@date = min(Job/@date)][1]/@id

but I am not returning anything on my expression tester I am using. I only return null.

Any help would be appreciated. I'd like to find the ID of the Job with the lowest date.

Correct result would be that my expression returns ID 2.

Rawbam
  • 13
  • 4
  • First off, your example XML is not well-formed. is missing end tag, and showing. Please show valid XML. Also, @date is assuming the "date" is an attribute, but you are showing it as an element. – OldProgrammer Dec 15 '15 at 17:39
  • I've made the changes to better reflect the question. – Rawbam Dec 16 '15 at 16:59
  • http://stackoverflow.com/questions/3601293/shortest-xpath-to-find-minimum-maximum-of-sibling-datetime-nodes - maybe this question will help you. – Newcomer Dec 17 '15 at 19:11
  • or this one: http://stackoverflow.com/questions/1128745/how-can-i-use-xpath-to-find-the-minimum-value-of-an-attribute-in-a-set-of-elemen - I'm afraid, you cant with dates MM/DD/YY. It should work with YY/MM/DD – guillaume girod-vitouchkina Dec 18 '15 at 23:44
  • None of the examples you provided actually return a different attribute than the one they are sorting off of. I want to find the ID where the date is the highest. Those threads just return the highest date, not the ID attribute that the date belongs to. – Rawbam Dec 21 '15 at 18:16

0 Answers0