W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2011

Re: xpath string index function

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Wed, 28 Sep 2011 09:47:48 -0400
Message-ID: <4E832584.9020408@thefigtrees.net>
To: Steve Harris <steve.harris@garlik.com>
CC: Sandro Hawke <sandro@w3.org>, SPARQL Working Group <public-rdf-dawg@w3.org>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:46 GMT