1 Reply Latest reply: Mar 9, 2012 12:02 PM by tsuji RSS

    Vlaues comparison error when using 'lt'

      Dear all,
      I have a little problem with the comparison functions (lt, gt, eq, ne). Given the following XML document:

      <node id='10,3,4,12'/>
      <node id='5,4,6'/>
      <node id='0,1,3'/>

      I want to return only nodes having a number less than 3 in their attribute id+. Only the third node should be returned.
      I tried to do this with the following query : //a[tokenize(@id,',')[. <3]] but it does not work even with +*//a[tokenize(@id,',')[. lt '3']]*+.
      I got the error. Effective boolean value is not defined for a sequence of two or more items starting with a string*.

      PS. I tried both with SaxonEE 9.4 under Java, and with oXygen XML Editor.
      Thank you in advance.
        • 1. Re: Vlaues comparison error when using 'lt'
          Not to mention whether your expression is correct or not, tokenize() would a priori return a sequence of string. Using it to compare with ('3') (rather than (3) which would definitely erroneous) is very fragile (in the sense not being robust) and even conceptually wrong in an application, schema-aware application or not.

          To do it properly, one way or another, you have first to make out some user defined function such as this, for instance.
          declare function local:num-seq($s as xs:string?) as xs:double* {
              for $i in tokenize($s,',')
              if (string(number($i)) != 'NaN') then (number($i)) else ()
          And then use it inside the predicate like this.
          for $i in $doc//node[(3) > local:num-seq(@id)] 
          return $i
          Or you can use similar construction but in the format of flwor.