Hi
Using Basex 7.0.2 and the factbook.xml database, I observe the following:
declare variable $data:=db:open("factbook");
declare function local:myid1($id){
$data//*[@id=$id]
};
(: get a 1000 ids to test :)
let $ids:=subsequence($data//@province/string(.),1,1000)
for $s in $ids return local:myid1($s)
for $s in $ids return $data//*[@id=$s]