Re: Testing for listItem

Hi Mark,

Am Donnerstag, den 18.10.2007, 15:06 +0100 schrieb Mark Birbeck:
> The first thing to do is make your test include a space, since that is
> the delimiter in a list of items:
> 
>   contains(flavors, 'a ')
> 
> That stops 'a' getting mixed up with 'ab'.
> 
> Of course, the problem now is that if the item you're testing for is
> the last in the list then it won't have a space after it; you will
> therefore also need to change the item you are testing against:
> 
>   contains(concat(flavors, ' '), 'a ')
> 
> I haven't tested that, but I recall having to do something along these
> lines quite a while ago. (It's also much the same as you would do in
> JavaScript when testing for @class values.)

That looks promising, although a bit complicated. But I think it should
be possible to wrap this into a custom function for my internal needs.

I had hoped that there would be a more elegant solution. Wouldn't
something like "list-contains()" be a good addition to the set of XForms
specific functions, or maybe to EXSLT? As you stated with the @class
example, this kind of check is not that unusual.

EXSLT has a quite useful extension in this regard: str:tokenize() (and
str:split(), but that one's less supported). So using EXSLT, something
like this should work, too:

        str:tokenize(flavors)/token = 'a'

Cheers,
Frederik

Received on Thursday, 18 October 2007 14:54:40 UTC