I have encountered a bug (?). Please consider this code:
declare function f:relatedNames($node, $relationship) as xs:string* {
let $fnName :=
function($node) {
let $_DEBUG := trace(count($node), '#node: ')
return name($node)}
let $items :=
switch($relationship)
case 'child' return $node/*
default return error()
return
$items/$fnName(.) => distinct-values() => sort() => string-join(', ')
};
let $doc := <doc><a/><b/><c/></doc>
return f:relatedNames($doc, 'child')
= = = = = = = = = end = = =
= = = = = = = = = output = = =
#node: 3
Stopped at C:/projects/foxpath-examples/pre-balisage/problem-basex2.xq, 15/25:
[XPTY0004] Item expected, sequence found: (<a/>, <b/>, <c/>).
= = = = = = = = = = = = = = = =
The call $fnName(.) receives a single item, but three items arrive at the function item!
PS: The funny switch() seems to play a part in the game, when I removed it, the issue vanished.