<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    First, if you expect your function to return a single integer, then
    it's best to declare this:<br>
    <br>
    <span class="c9Y6TC">declare</span> <span class="c9Y6TC">function</span>
    local:Match($X <span class="c9Y6TC">as</span> xs:string<span
      class="c50HZ4">*</span>,$Y <span class="c9Y6TC">as</span>
    xs:string<span class="c50HZ4">*</span>) as xs:integer { ...<br>
    <br>
    That way, you might get better error messages if the implementation
    of the function is wrong.<br>
    <br>
    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.<br>
    <br>
    &gt;I just want that this function verify if some word in "String1"
    contains in "String2" so in this case it  must return 1<br>
    <br>
    I think you can code the function as<br>
    <br>
    if (tokenize($X) = tokenize($Y)) then 1 else 0<br>
    <br>
    taking advantage of the fact that "=", given two sequences, returns
    true if any pair of items from the two sequences are equal.<br>
    <br>
    If you prefer to spell it out more clearly, you could write<br>
    <br>
    if (some $x in tokenize($X), $y in tokenize($Y) satisfies $x eq $y)
    then 1 else 0<br>
    <br>
    Any particular reason you want to return 1|0 from the function
    rather than true|false?<br>
    <br>
    Michael Kay<br>
    Saxonica<br>
    <br>
    On 20/11/2010 11:07, Mohamed kharrat wrote:
    <blockquote cite="mid:770364.81689.qm@web27003.mail.ukl.yahoo.com"
      type="cite">
      <style type="text/css"><!-- DIV {margin:0px;} --></style>
      <div style="font-family: arial,helvetica,sans-serif; font-size:
        10pt; color: rgb(0, 0, 0);">
        <div>dear all,<br>
          i want to create a function which return 1 or 0<br>
          i wrote this:<br>
          <style>.c9Y6TC { color: rgb(0, 0, 255); }.c50HZ4 { color: rgb(0, 128, 128); }.c4ZSSG { color: rgb(128, 0, 128); }.cPA8 { color: rgb(0, 128, 0); }</style>
          <span class="c9Y6TC">declare</span> <span class="c9Y6TC">function</span>
          local:Match($X <span class="c9Y6TC">as</span> xs:string<span
            class="c50HZ4">*</span>,$Y <span class="c9Y6TC">as</span>
          xs:string<span class="c50HZ4">*</span>)<br>
          {<br>
          <span class="c9Y6TC"></span><br>
          <br>
           <span class="c9Y6TC">for</span> $tok <span class="c9Y6TC">in</span>
          tokenize($X, <span class="c4ZSSG">"\s"</span>)<br>
          <span class="cPA8">(:for $tok2 in tokenize($Y, "\s"):)</span><br>
          <br>
          <span class="c9Y6TC">return</span> <span class="c9Y6TC">if</span>
          (<span class="c9Y6TC">some</span> $l <span class="c9Y6TC">in</span>
          tokenize($Y, <span class="c4ZSSG">"\s"</span>) <span
            class="c9Y6TC">satisfies</span> $l<span class="c50HZ4">=</span>
          $tok<span class="cPA8">(:contains ($l,$tok):)</span>) <span
            class="c9Y6TC">then</span> 1<br>
          <span class="c9Y6TC">else</span> 0<br>
          };<br>
          <style>.c4ZSSG { color: rgb(128, 0, 128); }</style>
          local:Match(<span class="c4ZSSG">'Cata avion nat voiture fff'</span>
          , <span class="c4ZSSG">'avion moto voiture'</span>) <br>
          this function return not only "1" or "0" but a sequence of  0
          1 0 1 0 <br>
          how to fix that?<br>
          i just want that this function verify if some word in
          "String1" contains in "String2" so in this case it  must
          return 1<br>
          thank you<br>
        </div>
      </div>
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:talk@x-query.com">talk@x-query.com</a>
<a class="moz-txt-link-freetext" href="http://x-query.com/mailman/listinfo/talk">http://x-query.com/mailman/listinfo/talk</a></pre>
    </blockquote>
    <br>
  </body>
</html>