xquery version "3.0";
let $data :=
<data>
<elem><x>1</x><y>b</y></elem>
<elem><x>2</x><y>a</y></elem>
</data>
let $ord-x := fn:true()
for $e in $data/elem
order by if ($ord-x) then $e/x else $e/y
return $e
But I get a parser error "Cannot resolve function 'if'".
XQuery allows an expression in an order by clause (https://www.w3.org/TR/xquery-30/#id-order-by-clause), for example:
But I get a parser error "Cannot resolve function 'if'".