Re: [xsl] is there a String indexOf() function in Xpath?

Subject: Re: [xsl] is there a String indexOf() function in Xpath?
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Thu, 28 Jul 2005 18:14:45 -0500
Hi Michael,


> You don't need substring() to implement index-of(). To expand DC's
response,
> here it is:

I don't think I was clear in my warning.  The original poster wanted
an index-of() to
do the below (from his original post):

>Want to do something like this...
>substring($titleText,
>indexOf($titleText, ' findThisTextsIndex ')+5 ,
>indexOf($titleText, 'toHere') )

I was just pointing out that he might get unexpected results if he
created a function and used it in the manner he originally posted,
without accounting for the fact that call to substring would be wrong
since the third argument of substring is length, not index of the
start of the terminating pattern.

That's why I mentioned difference (haven't done a lot of function
building in XSLT 2.0 so you'll just have to accept the pesuedo-code.
Sorry, but I'm planning on playing around more whenever I get another
free weekend).

If you have the function eg:index-of, you'll still need the second
that takes in the third argument as the index-of the string instead of
the length.  Ie if this was some method

substring-using-indexes(string,start_index,end_index) {
return substring(string,start_index, end_index - start_index);
}

or something along those lines (might have a off by one here, trying
to cook dinner and answer email at the same time ;) ).

Jon Gorman

Current Thread