home contribute faq download

FunctX XSLT Functions

functx:index-of-string

The position(s) of a substring

Google
Webdatypic.com

Description

The functx:index-of-string function returns one or more integers representing the position of a $substring within $arg. Overlapping substrings are not counted. If $arg does not contain $substring, the empty sequence is returned.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string
$substring xs:string the substring to find
return value xs:integer*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:index-of-string" as="xs:integer*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="arg" as="xs:string?"/>
  <xsl:param name="substring" as="xs:string"/>

  <xsl:sequence select="
  if (contains($arg, $substring))
  then (string-length(substring-before($arg, $substring))+1,
        for $other in
           functx:index-of-string(substring-after($arg, $substring),
                               $substring)
        return
          $other +
          string-length(substring-before($arg, $substring)) +
          string-length($substring))
  else ()
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:index-of-string('abcdabcdabcd','abc')
(1, 5, 9)
functx:index-of-string('abcd','abc')
1
functx:index-of-string('xxx','abc')
()

See Also

functx:index-of-string-firstThe first position of a substring
functx:index-of-string-lastThe last position of a substring

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