I'm fairly new to XQuery and only started to use it and BaseX last week. So far I've been very impressed with the capabilities of both.
I have one question about user-defined functions. From what I can tell so far that I learned about XQuery, user-defined functions are only accessible when they are declared in the prolog of the query. In itself I suppose there's a certain logic to that. My project is most likely very atypical from your average XQuery usage, but it would be much more convenient, and probably also much more efficient if I could somehow (optionally) declare user-defined functions and reuse them for several queries in a row.
I don't think importing a module would be a solution because a) that would be even more inefficient and b) I don't think it wouldn't work with dynamically created functions. (I'm executing queries that contain queries that get executed...)
So I was wondering if there's a way to accomplish this. And even if this is currently not possible, would it be complicated for an accomplished Java developer to add as a custom extension? Any tips or ideas will be greatly appreciated.
Mark
Dear Mark,
thanks for your mail. Just some quick feedback: correct, user-defined functions are defined in the prolog of a query. They look as follows:
declare function local:nameOfFunction($optionalArg) { ...expression... };
...and can be called as follows…
local:nameOfFunction(...)
Another example is given at..
http://www.w3schools.com/XQuery/xquery_functions.asp
If your function block isn't excessively long, you shouldn't care about performance, as the parsing and compilation steps are very fast in BaseX. If you should indeed encounter any bottlenecks in practice, feel free to tell us.
Christian
On Mon, Nov 22, 2010 at 11:41 PM, Mark Boon mboon@avatar-reality.com wrote:
I'm fairly new to XQuery and only started to use it and BaseX last week. So far I've been very impressed with the capabilities of both.
I have one question about user-defined functions. From what I can tell so far that I learned about XQuery, user-defined functions are only accessible when they are declared in the prolog of the query. In itself I suppose there's a certain logic to that. My project is most likely very atypical from your average XQuery usage, but it would be much more convenient, and probably also much more efficient if I could somehow (optionally) declare user-defined functions and reuse them for several queries in a row.
I don't think importing a module would be a solution because a) that would be even more inefficient and b) I don't think it wouldn't work with dynamically created functions. (I'm executing queries that contain queries that get executed...)
So I was wondering if there's a way to accomplish this. And even if this is currently not possible, would it be complicated for an accomplished Java developer to add as a custom extension? Any tips or ideas will be greatly appreciated.
Mark _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de