JokkeMedKniven
JokkeMedKniven

Reputation: 81

XPath for element with maximum value?

I have a XML file containing different publications. I want to find the publication with the highest amount of timesCited which is published before 2010. I have this as of now:

/publications/publication[timesCited = max(/publications/publication/timesCited)]
                         [yearFinished < 2010]

The problem is that this checks for the highest timesCited, which is a publication from 2011, and thus returns nothing. I want to find the publication with the highest amount of citations before 2010. How would I go about this?

Upvotes: 1

Views: 1563

Answers (2)

kjhughes
kjhughes

Reputation: 111591

This XPath,

//publication[yearFinished < 2010]
             [timesCited = max(//publication[yearFinished < 2010]/timesCited)]

will select the pre-2010 publication element with the maximum timesCited, as requested.

Upvotes: 1

gtosto
gtosto

Reputation: 1341

The following expression should works

/publications/publication[yearFinished < 2010][timesCited = max(/publications/publication[yearFinished < 2010]/timesCited)]

hope it helps

Upvotes: 1

Related Questions