Description
The functx:max-determine-type function returns the maximum of the values in $seq. The built-in fn:max function treats all untyped data as numeric and raises an error if a value cannot be cast to xs:double. This function, by contrast, tests whether values are numeric, and if so, sorts them as numbers. If values are not numeric, it sorts them like strings.
If your values are definitely numeric, there is no need to use this function instead of the built-in fn:max function.
Arguments and Return Type| Name | Type | Description |
$seq |
xs:anyAtomicType* |
the sequence of values to test |
| return value |
xs:anyAtomicType? |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:max-determine-type
( $seq as xs:anyAtomicType* ) as xs:anyAtomicType? {
if (every $value in $seq satisfies ($value castable as xs:double))
then max(for $value in $seq return xs:double($value))
else max(for $value in $seq return xs:string($value))
} ; | | XQuery Syntax for July 2004 - November 2005 (CR): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:max-determine-type
( $seq as xdt:anyAtomicType* ) as xdt:anyAtomicType? {
if (every $value in $seq satisfies ($value castable as xs:double))
then max(for $value in $seq return xs:double($value))
else max(for $value in $seq return xs:string($value))
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function max-determine-type
( $seq as xdt:anyAtomicType* ) as xdt:anyAtomicType? {
if (every $value in $seq satisfies ($value castable as xs:double))
then fn:max(for $value in $seq return xs:double($value))
else fn:max(for $value in $seq return xs:string($value))
} |
Exampleslet $in-xml := | <values>
<nums>
<num>12</num>
<num>23</num>
<num>115</num>
<num>12.5</num>
</nums>
<strings>
<string>def</string>
<string>abc</string>
</strings>
</values> | return |
| XQuery Example | Results |
|---|
functx:max-determine-type($in-xml//num)
|
115
|
functx:max-determine-type($in-xml//string)
|
def
|
functx:max-determine-type(
$in-xml//(num|string))
|
def
|
See AlsoHistory |
|