Search code examples
xmlxpathstring-length

XPath query to return the element with the max length in value


Given a list of elements containing text:

<root>
  <element>text text text ...</element>
  <element>text text text ...</element>
<root>

I'm trying to write an XPath 1.0 query that will return the element with the max text length.

Unfortunately string-length() returns a single result and not a set, so I'm not sure how to accomplish it.

Thank you.


Solution

  • It is impossible to accomplish using pure XPath 1.0.