I would like to find a clean way of referencing the default context of my main module, where I can easily do "let $x := //whatever", but after I move this line to a function declaration.
I'm sorry, the context item will always be reset within functions both in XQuery 1.0 and 3.0, so the only way is to pass on the relevant node. A minor detail: If you put the doc() function inside the function instead of passing it on its result, you might benefit from some more optimizations, as a path expression can only be rewritten for index access if the accessed database is known at compile time.
Hope this helps, Christian