home contribute faq download

FunctX XSLT Functions

functx:trim

Trims leading and trailing whitespace

Google
Webxsltfunctions.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

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:trim" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="arg" as="xs:string?"/>

  <xsl:sequence select="
   replace(replace($arg,'\s+$',''),'^\s+','')
 "/>

</xsl:function>

Examples

XPath 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
Datypic XSLT Services

Recommended Reading:

XQuery