[xquery-talk] get highest number

Michael Kay mike at saxonica.com
Wed May 14 15:20:00 PDT 2008

> Or switch to a better XQuery processor. I find it hard to 
> imagine why a product should take noticeably longer to 
> evaluate max(//@id) than it takes to evaluate //@id.

Or if you can't do that, try coding it yourself as

declare function local:max($n as xs:double+) {
  if (count($n) eq 1)
  then $n
      let $halfway = count($n) idiv 2
      let $maxleft = local:max($n[position() le $halfway)
      let $maxright = local:max($n[position() gt $halfway)
      return if ($maxleft gt $maxright) then $maxleft else $maxright


Michael Kay


More information about the talk mailing list