I would prefer to avoid the creation of another BaseX database for each query result.
Just fine as well. If you use XQuery, you can bind your query results to variables for further processing.
I guess that a popular use case is to count items also in XML data structures. The computed numbers would be passed then to aggregate functions for further data analyses, wouldn't they?
Some more insight into what you’ve done so far would be helpful.