First, I enjoyed the question. I do not know nearly enough about XQuery, and I have been trying to learn more. Thanks.
<rant>
Am I the only person that is frustrated when questions are posted as a picture, instead of text that can be copied and pasted for further experimentation?
I know there are some that want to discourage "cheating" on the QOTD, but I would think accessible scripts would be a better way to learn something. True, one could type this question up, and thank you Paul for doing that, but I would rather have these question, especially longer and more esoteric questions such as this one, be accessible by default.
</rant>
Despite my rant, I do thank you for the question, and the discussion it has created.
Have a good one,
Matt