Your result asked for in the original question, if it also was meant to indicate some CSV representation, could be achieved using
declare option output:method "csv"; declare option output:csv "header=yes";
<csv> { (["f", [1, 2, 3]], ["g", [4, 5]]) ! (let $key := ?1, $values := ?2?* return $values! <record> <key>{$key}</key> <value>{.}</value> </record> ) } </csv>
Can such an XQuery script variant be adapted also for the handling of items from a subtree instead of the shown number array?
Regards, Markus