[xquery-talk] query problem
Michael Kay
mike at saxonica.com
Sat Nov 20 11:38:16 PST 2010
First, if you expect your function to return a single integer, then it's
best to declare this:
declare function local:Match($X as xs:string*,$Y as xs:string*) as
xs:integer { ...
That way, you might get better error messages if the implementation of
the function is wrong.
The reason your function returns a sequence of integers is that the
"return" clause of the FLWOR expression is executed once for each value
of $tok, that is, once for each of the tokens in the input.
>I just want that this function verify if some word in "String1"
contains in "String2" so in this case it must return 1
I think you can code the function as
if (tokenize($X) = tokenize($Y)) then 1 else 0
taking advantage of the fact that "=", given two sequences, returns true
if any pair of items from the two sequences are equal.
If you prefer to spell it out more clearly, you could write
if (some $x in tokenize($X), $y in tokenize($Y) satisfies $x eq $y) then
1 else 0
Any particular reason you want to return 1|0 from the function rather
than true|false?
Michael Kay
Saxonica
On 20/11/2010 11:07, Mohamed kharrat wrote:
> dear all,
> i want to create a function which return 1 or 0
> i wrote this:
> declare function local:Match($X as xs:string*,$Y as xs:string*)
> {
>
>
> for $tok in tokenize($X, "\s")
> (:for $tok2 in tokenize($Y, "\s"):)
>
> return if (some $l in tokenize($Y, "\s") satisfies $l= $tok(:contains
> ($l,$tok):)) then 1
> else 0
> };
> local:Match('Cata avion nat voiture fff' , 'avion moto voiture')
> this function return not only "1" or "0" but a sequence of 0 1 0 1 0
> how to fix that?
> i just want that this function verify if some word in "String1"
> contains in "String2" so in this case it must return 1
> thank you
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20101120/07bf0347/attachment.htm
More information about the talk
mailing list