How do I achieve Library module re-use?

Issues related to W3C XQuery.
ldueck
Posts: 3

How do I achieve Library module re-use?

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?
alex_jitianu
Posts: 600

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

Fri Sep 30, 2011 5:15 pm

Hello,

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 = "http://xmlns.foo.com/myproject/four" at "location.xq";


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

Regards,
Alex

Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
ldueck
Posts: 3

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

Wed Oct 12, 2011 5:39 pm

I'm using Oxygen 11.2 with the built in Saxon processor (9.2.0.6)
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.

Lynn
alex_jitianu
Posts: 600

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

Thu Oct 13, 2011 6:13 pm

Hello,

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

Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
ldueck
Posts: 3

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

Thu Oct 13, 2011 8:59 pm

Thanks Alex,

I'll give the workaround a try.

Lynn

Return to “XQuery”

Who is online

Users browsing this forum: No registered users and 0 guests