home contribute faq download

FunctX XQuery Functions

functx:min-determine-type

The minimum value in a sequence, figuring out its type (numeric or string)

Google
Webdatypic.com

Description

The functx:min-determine-type function returns the minimum of the values in $seq. It differs from the built-in fn:min function only in the way it treats untyped data. The built-in fn:min function treats all untyped data as numeric and raises an error if a value cannot be cast to xs:double. This function tests whether untyped values are numeric, and if so, sorts them as numbers. If untyped values are not numeric, it sorts them like strings. If your values are typed, or all numeric, there is no need to use this function instead of the built-in fn:min function.

Arguments and Return Type

NameTypeDescription
$seq xs:anyAtomicType* the sequence of values to test
return value xs:anyAtomicType?

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:min-determine-type
  ( $seq as xs:anyAtomicType* )  as xs:anyAtomicType? {

   if (every $value in $seq satisfies ($value castable as xs:double))
   then min(for $value in $seq return xs:double($value))
   else min(for $value in $seq return xs:string($value))
 } ;

Examples

let $in-xml :=
<values>
   <nums>
      <num>12</num>
      <num>23</num>
      <num>115</num>
      <num>12.5</num>
   </nums>
   <strings>
      <str>def</str>
      <str>abc</str>
   </strings>
</values>
return
XQuery ExampleResults
functx:min-determine-type($in-xml//num)
12
functx:min-determine-type($in-xml//str)
abc
functx:min-determine-type($in-xml//(num|str))
115

See Also

fn:minThe minimum of a sequence of values
functx:min-stringThe minimum of a sequence of values, treating them like strings
functx:max-determine-typeThe maximum value in a sequence, figuring out its type (numeric or string)

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery