I have an embedded Base-X database in a web application. I have a huge
XQuery that involves a lot of local functions, many of them recursive.
In several of these functions, I need to query the database to look up
referenced elements. I can't for the life of me figure out a way to
access the database without doing one of two things:
1. My document root is /data. I can let $root := /data and then pass
that into every function. Passing things into functions rather than
setting global variable is certainly and FP way of doing things, but in
this instance it seems to me that it should be the scope I'm working in.
2. If something else I pass into the function is a node in the database,
then I can, for example, use $node/root() to back up to the root node.
But sometimes I'm only passing in a string and I still need to query the
whole database.
Is there some way to access the root easily from within a function? I am
very confused by the whole "context" idea. I've looked all over, but I
must be searching using the wrong terms, or it simply isn't done.
Anyone know a way?
Thanks,
Chas.