I read this question while trying to do something similar. The answer given there does not solve my problem.
I want to use a visit statement to determine the 'mass' of each subtree, so for each node I want to sum the masses of all descendants. For example, a visiting step which encounters this node expression with a list in it:
\anode([\bnode()[@mass=1], \bnode()[@mass=2]], \cnode()[@mass=5])
should yield this:
\anode([\bnode()[@mass=1], \bnode()[@mass=2]], \cnode()[@mass=5])[@mass=8]
So I do not just want to filter out the non-nodes, but actually traverse them. Including a case for lists in my visit statement does not work (at least not obviously) because lists cannot have annotations.
Is there a natural way to propagate the complete annotation information up a tree?