This function returns all objects contained within the supplied items, regardless of depth.
declare function descendant-objects($seq as item*) as object*
{
for $i in $seq
return typeswitch ($i)
case object return ($i, descendant-objects(values($i)))
case array return descendant-objects($i[])
default return ()
};