Hi
with the  factbook.xml database open in the 7.0.2 gui

declare function local:linkto($id as xs:string){
  let $d:=//city
  let $a:=$d[@id=$id]
  return $a
};
local:linkto("f0_1461")

Gives the "no context item for root" error on the //city line, but

declare function local:linkto($id as xs:string){
  let $a:=//city[@id=$id]
  return $a
};
local:linkto("f0_1461")

Works fine. Should it give the same error?
If it should, and I try to pass the nodes into the function then the relative performance is not good at all.
declare function local:linkto2($id as xs:string,$nodes as node()*){
 let $c:=$nodes[@id=$id]
 let $n:=name($c[1])
 return <a href="/fb/{$n}/{$id}">
 {$c/name/string()}
 </a>
};

let $caps:=//country/@capital/string()
for $id in $caps
return local:linkto2($id,//city)

/Andy