If you put your "possibles" in an array rather than a sequence then the index of the first non-empty item
identifies the match.
let $results := [$possible1,$possible2,$possible3,$possible4,$possible5,'FAILED']
let $index:= array:fold-left($results,
-1,
function($acc,$this){
if($acc gt 0)then $acc else
if (exists(array:get($results,-$acc))) then -$acc else $acc -1
})
let $foundIt:= array:get($results,$index)
This seems a bit tricksy, using the BaseX specific higher order function
hof:until
[1] is cleaner
let $index:= hof:until(
function($index){ exists(array:get($results,$index)) },
function($index){ $index+1 },
1)
/Andy