How do I achieve Library module re-use?
Posted: Tue Sep 20, 2011 6:41 pm
I have a library module with some generic functions that are intended for re-use by other library modules AND xquery files in my project.
Unfortunately, I cannot get this to work properly when running inside oxygen, as I get a whole host of "duplicate definition of...." errors.
The problem is that my xquery may indirectly import the library module more than once, depending on which other modules are imported.
Is there not a way for a library module to contain global variables or functions that are to be reused in this way??
Here is the basic use case I'm trying to get to work......
LIBRARY MODULE *****
module namespace lib = "http://xmlns.foo.com/myproject/library";
declare function lib:genericFunction(
$tmpname as xs:string,
$value as element()*) as element()* {
........
};
******
The generic function is popular and is used by many library modules.
VARIOUS LIBRARY MODULES AND THEIR IMPORTS
library module one --> imports lib
library module two --> imports one, three, lib
library module three --> imports lib
library module four --> imports three, lib
XQUERY *****
import module namespace four = "http://xmlns.foo.com/myproject/four";
four:doSomeWork(.)
********
My xquery only imports from module four.
Because four imports the lib module directly AND indirectly (via import of module THREE) I get duplicate definitions of each global variable and function that exists in lib. As you can see the problem is exacerbated even more if I import module two.
Can someone explain how I achieve the kind of re-use I am looking for?
Unfortunately, I cannot get this to work properly when running inside oxygen, as I get a whole host of "duplicate definition of...." errors.
The problem is that my xquery may indirectly import the library module more than once, depending on which other modules are imported.
Is there not a way for a library module to contain global variables or functions that are to be reused in this way??
Here is the basic use case I'm trying to get to work......
LIBRARY MODULE *****
module namespace lib = "http://xmlns.foo.com/myproject/library";
declare function lib:genericFunction(
$tmpname as xs:string,
$value as element()*) as element()* {
........
};
******
The generic function is popular and is used by many library modules.
VARIOUS LIBRARY MODULES AND THEIR IMPORTS
library module one --> imports lib
library module two --> imports one, three, lib
library module three --> imports lib
library module four --> imports three, lib
XQUERY *****
import module namespace four = "http://xmlns.foo.com/myproject/four";
four:doSomeWork(.)
********
My xquery only imports from module four.
Because four imports the lib module directly AND indirectly (via import of module THREE) I get duplicate definitions of each global variable and function that exists in lib. As you can see the problem is exacerbated even more if I import module two.
Can someone explain how I achieve the kind of re-use I am looking for?