[xquery-talk] about function

G. Ken Holman gkholman at CraneSoftwrights.com
Mon Nov 29 09:31:42 PST 2010


At 2010-11-29 14:19 +0000, Mohamed kharrat wrote:
>dear all,
>i have this function:
>declare function local:Match($X as xs:string*,$Y as xs:string*)
>{
>
>let $count:=tokenize($X, "\s")
>where
>some $l in $count satisfies
>some $tok2 in tokenize($Y, "\s") satisfies
>contains($l,$tok2)
>return true()
>}
>
>it's ok , it return true where $X exist in $Y
>but the problem is: supposing i have:
>$string1='an '
>$string2= 'the xquery is a language for xml'
>
>this function will return  true because 'an' exist in the word 'language'
>but i want to know how to return true only if the word 'an' exit 
>alone , not in other word of $string2
>
>i hope you understand me.

This question was answered for you on November 11 by me and by others.

Don't use "contains()" and you won't have a problem.

The following function will return true() if any 
non-white-space-string of text in $X is equal to a 
non-white-space-string of text in $Y:

declare function local:Match($X as xs:string*,$Y as xs:string*)
{ tokenize($X,'\s') = tokenize($Y,'\s') };

What has changed in your requirement when you asked this question last week?

I hope the example below helps.

. . . . . . . . . Ken

T:\ftemp>type kharrat.xq
declare function local:Match($X as xs:string*,$Y as xs:string*)
{ tokenize($X,'\s') = tokenize($Y,'\s') };

local:Match( 'an','the xquery is a language for xml' ),
local:Match( 'a','the xquery is a language for xml' )

T:\ftemp>xquery kharrat.xq
<?xml version="1.0" encoding="UTF-8"?>false true
T:\ftemp>




--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:gkholman at CraneSoftwrights.com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



More information about the talk mailing list