home contribute faq download

FunctX XQuery Functions

functx:trim

Trims leading and trailing whitespace

Google
Webxqueryfunctions.com

Description

The functx:trim function removes whitespace at the beginning and end of a string. Unlike the built-in fn:normalize-space function, it only removes leading and trailing whitespace, not whitespace in the middle of the value. Whitespace is defined as it is in XML, namely as space, tab, carriage return and line feed characters. If $arg is the empty sequence, it returns a zero-length string.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to trim
return value xs:string

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:trim
  ( $arg as xs:string? )  as xs:string {

   replace(replace($arg,'\s+$',''),'^\s+','')
 } ;

Examples

XQuery ExampleResults
functx:trim('   xyz   ')
xyz
functx:trim('   xyz')
xyz
functx:trim('x   xyz  ')
x   xyz

See Also

functx:left-trimTrims leading whitespace
functx:right-trimTrims trailing whitespace
fn:normalize-spaceNormalizes whitespace

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