Re: xpath string index function

On 9/28/2011 9:26 AM, Steve Harris wrote:
> On 2011-09-28, at 14:07, Sandro Hawke wrote:
>
>> As discussed in yesterday's telecon, I asked an expert (Liam Quin, XML
>> activity lead), who confirmed there is no function in xpath to find the
>> position of a string inside another one, and that people string-before,
>> and can just use the length of that if they really need the position.
>
> I note that will give you the 0-based offset of the string :)
>
> Also, fn:substring-before returns a zero-length string in the case of a non-match, so it's rather tricky to work with:
>
> IF(fn:starts-with(?x, "foo") || fn:string-length(fn:substring-before(?x, "foo"))>  0, fn:string-length(fn:substring-before(?x, "foo")) + 1, 0)
>
> …or something like it will give you the 1-based index of a substring.

isn't there a contains function?

Lee

>
> - Steve
>

Received on Wednesday, 28 September 2011 13:48:28 UTC