XQuery/Returning the Longest String

Motivation
You want to find the longest string(s) in a sequence of strings.

Sample Program
[/basics/longeststring.xq Execute]

Discussion
This XQuery creates a local function that takes zero or more strings:

and returns one or more strings:

It uses the max XPath function that looks at a sequence of values and returns the highest.

Note that if there are several strings in the input set that each have the same max length, it will return all strings of max length.

If you only want the first returned, add "[1]" to the return expression:

''