<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.max.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.max</api:function-name><api:suggest>fn.max</api:suggest><api:suggest>fn</api:suggest><api:suggest>max</api:suggest><api:function-link mode="xquery" fullname="fn:max">/apidoc/8.0/fn:max.xml</api:function-link><api:function mode="javascript" name="max" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.max"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
Selects an item from the input sequence $arg whose value is greater than or
equal to the value of every other item in the input sequence. If there are
two or more such items, then the specific item whose value is returned is
implementation dependent.
</p><p xmlns="http://www.w3.org/1999/xhtml">
The following rules are applied to the input sequence:
</p>
<ul xmlns="http://www.w3.org/1999/xhtml"><li>Values of type xs:untypedAtomic in $arg are cast to xs:double.</li><li>For numeric values, the numeric promotion rules defined in 6.2 Operators on
Numeric Values are used to promote all values to a single common type.
</li></ul>
<p xmlns="http://www.w3.org/1999/xhtml">
The items in the resulting sequence may be reordered in an arbitrary order. The
resulting sequence is referred to below as the converted sequence.This
function returns an item from the converted sequence rather than the input
sequence.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the converted sequence is empty, the empty sequence is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
All items in $arg must be numeric or derived from a single base type for which
the ge operator is defined. In addition, the values in the sequence must
have a total order. If date/time values do not have a timezone, they are
considered to have the implicit timezone provided by the dynamic context for
purposes of comparison. Duration values must either all be
xs:yearMonthDuration values or must all be xs:dayTimeDuration values.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If any of these conditions is not met, then a type error is raised
  [err:FORG0006].
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the converted sequence contains the value NaN, the value NaN is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the items in the value of $arg are of type xs:string or types derived by
restriction from xs:string, then the determination of the item with the
largest value is made according to the collation that is used. If the type
of the items in $arg is not xs:string and $collation is specified, the
collation is ignored.
</p><p xmlns="http://www.w3.org/1999/xhtml">
The collation used by the invocation of this function is determined according
to the rules in 7.3.1 Collations.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Otherwise, the result of the function is the result of the expression:
</p><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
   if (every $v in $c satisfies $c[1] ge $v)
   then $c[1]
   else fn:max(fn:subsequence($c, 2))
</pre>
<p xmlns="http://www.w3.org/1999/xhtml">
evaluated with $collation as the default collation if specified, and with $c as
the converted sequence.
</p><p xmlns="http://www.w3.org/1999/xhtml">
For detailed type semantics, see
<a href="http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum functions[FS]</a>.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Notes:
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the converted sequence contains exactly one value then that value is
returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
The default type when the fn:max function is applied to xs:untypedAtomic
values is xs:double. This differs from the default type for operators such as
gt, and for sorting in XQuery and XSLT, which is xs:string.
</p>
</api:summary><api:params><api:param name="arg" type="ValueIterator | Array" class="javascript"><api:param-description>
  The sequence of values whose maximum will be returned.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>ValueIterator | Array</api:param-type></api:param><api:param name="collation" type="xs:string" optional="true"><api:param-description>
  The optional name of a valid collation URI.  For information on the
  collation URI syntax, see the <em xmlns="http://www.w3.org/1999/xhtml">Search Developer's Guide</em>.
  </api:param-description><api:param-name>collation</api:param-name><api:param-type>String</api:param-type></api:param></api:params><api:return>xs.anyAtomicType?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
fn.max([3,4,5])
=&gt; 5

fn.max([5, 5.0e0])
=&gt; 5.0e0

fn.max([3,4,"Zero"])
=&gt; raises a type error [err:FORG0006]

fn.max([fn.currentDate(), xs.date("2001-01-01")])
=&gt; typically returns the current date

fn.max(["a", "b", "c"])
=&gt; "c" under a typical default collation
</pre>
</api:example></api:function></api:function-page>