It's not clear exactly what you want to do with the index of a substring [update: it is clearer now - thanks] but you may be able to use the function substring-after
or substring-before
:
substring-before('My name is Fred', 'Fred')
returns 'My name is '
.
If you need more detailed control, the substring()
function can take two or three arguments: string, starting-index, length. Omit length to get the whole rest of the string.
There is no index-of()
function for strings in XPath per se(only for sequences, in XPath 2.0). You can use string-length(substring-before($string, $substring))+1
if you specifically need the position (but you'll get a zero-based result, so you need to add 1 if you're going to use the result as the second argument of substring()
).
There is also contains($string, $substring)
. These are all documented here. In XPath 2.0 you can use regular expression matching.
(XSLT mostly uses XPath for selecting nodes and processing values, so this is actually more of an XPath question. I tagged it thus.)