home contribute faq download

FunctX XSLT Functions

functx:substring-before-if-contains

Performs substring-before, returning the entire string if it does not contain the delimiter

Google
Webdatypic.com

Description

The functx:substring-before-if-contains function performs substring-before, returning the entire string if it does not contain the delimiter. It differs from the built-in fn:substring-before function, which returns a zero-length string if the delimiter is not found.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to substring
$delim xs:string the delimiter
return value xs:string?

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:substring-before-if-contains" as="xs:string?"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="arg" as="xs:string?"/>
  <xsl:param name="delim" as="xs:string"/>

  <xsl:sequence select="
   if (contains($arg,$delim))
   then substring-before($arg,$delim)
   else $arg
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:substring-before-if-contains('abcd','c')
ab
functx:substring-before-if-contains('abcd','x')
abcd

See Also

fn:substring-beforeThe substring before the first occurrence of a delimiter
functx:substring-before-lastThe substring before the last occurrence of a delimiter
functx:substring-after-if-containsPerforms substring-after, returning the entire string if it does not contain the delimiter

History

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

Recommended Reading:

XQuery