home contribute faq download

FunctX XQuery Functions

functx:word-count

The number of words

Google
Webxqueryfunctions.com

Description

The functx:word-count function returns the number of words in a string (or node that is atomized). Word boundaries are determined by the definition of "word characters" in Unicode. If $arg is the empty sequence, it returns zero.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to measure
return value xs:integer

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for July 2004 - January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:word-count 
  ( $arg as xs:string? )  as xs:integer {
       
   count(tokenize($arg, '\W+')[. != ''])
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function word-count 
  ( $arg as xs:string? )  as xs:integer {
       
   fn:count(fn:tokenize($arg, '\W+')[. != ''])
 }

Examples

XQuery ExampleResults
functx:word-count('hello there world')
3
functx:word-count(' hello  world    ')
2
functx:word-count('a.b.c')
3

See Also

functx:line-countThe number of lines
functx:contains-wordWhether one string contains another, as a separate word

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