home contribute faq download

FunctX XQuery Functions

functx:substring-after-if-contains

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

Google
Webxqueryfunctions.com

Description

The functx:substring-after-if-contains function performs substring-after, returning the entire string if it does not contain the delimiter. It differs from the built-in fn:substring-after 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?

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:substring-after-if-contains 
  ( $arg as xs:string? ,
    $delim as xs:string )  as xs:string? {
       
   if (contains($arg,$delim))
   then substring-after($arg,$delim)
   else $arg
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function substring-after-if-contains 
  ( $arg as xs:string? ,
    $delim as xs:string )  as xs:string? {
       
   if (fn:contains($arg,$delim))
   then fn:substring-after($arg,$delim)
   else $arg
 }

Examples

XQuery ExampleResults
functx:substring-after-if-contains('abcd','b')
cd
functx:substring-after-if-contains('abcd','x')
abcd

See Also

fn:substring-afterThe substring after the first occurrence of a delimiter
functx:substring-after-lastThe substring after the last occurrence of a delimiter
functx:substring-after-last-matchThe substring after the last text that matches a regex
functx:substring-before-if-containsPerforms substring-before, 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, 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