home contribute faq download

FunctX XQuery Functions

functx:is-a-number

Whether a value is numeric

Google
Webxqueryfunctions.com

Description

The functx:is-a-number function returns true if the value is number (can be cast to a numeric type) and is not the value NaN. If the argument is the empty sequence or a zero-length string, it returns false.

Arguments and Return Type

NameTypeDescription
$value xs:anyAtomicType? the value to test
return value xs:boolean

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:is-a-number 
  ( $value as xs:anyAtomicType? )  as xs:boolean {
       
   string(number($value)) != 'NaN'
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:is-a-number 
  ( $value as xdt:anyAtomicType? )  as xs:boolean {
       
   string(number($value)) != 'NaN'
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function is-a-number 
  ( $value as xdt:anyAtomicType? )  as xs:boolean {
       
   fn:string(fn:number($value)) != 'NaN'
 }

Examples

let $in-xml :=
<in-xml>
   <a>123</a>
   <b>abc</b>
</in-xml>
return
XQuery ExampleResults
functx:is-a-number('123')
true
functx:is-a-number(123)
true
functx:is-a-number('  123  ')
true
functx:is-a-number('')
false
functx:is-a-number('123abc')
false
functx:is-a-number('NaN')
false
functx:is-a-number($in-xml/a)
true
functx:is-a-number($in-xml/b)
false

See Also

fn:numberConverts a value or a node to a number

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley