home contribute faq download

FunctX XSLT Functions

functx:substring-after-last

The substring after the last occurrence of a delimiter

Google
Webxsltfunctions.com

Description

The functx:substring-after-last function returns the part of $arg that appears after the last occurrence of $delim. If $arg does not contain $delim, the entire $arg is returned. If $arg is the empty sequence, a zero-length string is returned.

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-after-last" 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="
   replace ($arg,concat('^.*',functx:escape-for-regex($delim)),'')
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:substring-after-last('abc-def-ghi', '-')
ghi
functx:substring-after-last('abcd-abcd', 'ab')
cd
functx:substring-after-last('abcd-abcd', 'x')
abcd-abcd

Depends On

functx:escape-for-regexEscapes regex special characters

See Also

fn:substring-afterThe substring after the first occurrence of a delimiter
functx:substring-before-lastThe substring before the last occurrence of a delimiter
functx:substring-after-last-matchThe substring after the last text that matches a regex

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