[FIX] XQuery: too aggressive optimization of empty(), exists(). Closes #1008