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