Page 1 of 1

How do I achieve Library module re-use?

Posted: Tue Sep 20, 2011 6:41 pm
by ldueck
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......


module namespace lib = "";

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.

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 = "";



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?

Re: How do I achieve Library module re-use?

Posted: Fri Sep 30, 2011 5:15 pm
by alex_jitianu

The fact that your library module gets imported multiple times shouldn't be a problem. The XQuery processor will try to resolve the imported module and should recognize that it has already been imported. The problem you described can arise if the resolved module doesn't match with the one already loaded so it will get loaded again.

I couldn't reproduce the error using a module structure like the one you described. Could you tell us what version of Oxygen you are using and what XQuery processor? I'm guessing it's not the built-in Saxon processor since Saxon requires some location information when importing a module, something like:

Code: Select all

import module namespace four = "" at "location.xq";

It might also be helpful if you could send the modules to to see if we can reproduce the problem with them.


Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Re: How do I achieve Library module re-use?

Posted: Wed Oct 12, 2011 5:39 pm
by ldueck
I'm using Oxygen 11.2 with the built in Saxon processor (
I am using the location as you describe - I just missed adding it into the sample code I sent.

I have created a sample package which I will send off to support to see what they have to say.


Re: How do I achieve Library module re-use?

Posted: Thu Oct 13, 2011 6:13 pm
by alex_jitianu

Thanks to the files you sent, we managed to identify this as a Saxon problem that relates to the catalog use. Basically Saxon checks if a module has already been loaded by comparing the module's unresolved URI with the catalog resolved URIs of the already loaded modules. Because of that it will end up loading the module again although it shouldn't. We will report this issue to Saxon. Until it is resolved, a possible solution is to use absolute paths (the ones who should be resolved through the catalog) only in the main file Process.xquery (assuming you have this flexibility). All other xquery files should use relative paths.

Thank you,

Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Re: How do I achieve Library module re-use?

Posted: Thu Oct 13, 2011 8:59 pm
by ldueck
Thanks Alex,

I'll give the workaround a try.