home contribute faq download

FunctX XSLT Functions

functx:index-of-match-first

The first position of a matching substring

Google
Webxsltfunctions.com

Description

The functx:index-of-match-first function returns an integer representing the first position of a substring that matches $pattern within $arg. If $arg does not match $pattern, the empty sequence is returned.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string
$pattern xs:string the pattern to match
return value xs:integer?

XSLT Function Declaration

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

  <xsl:sequence select="
  if (matches($arg,$pattern))
  then string-length(tokenize($arg, $pattern)[1]) + 1
  else ()
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:index-of-match-first(
   'abcdabcdabcd','abc')
1
functx:index-of-match-first(
   'abcdabcdabcd','bcd')
2
functx:index-of-match-first('a1234','\d')
2
functx:index-of-match-first('abc abc','\s')
4
functx:index-of-match-first('abc abc','z')
()

See Also

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

History

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

Recommended Reading:

XQuery