4

I have few module namespace xquery files which were used in multiple files. I want to have the namespaces in one common xquery file and import that file whereever I want to use.

Say for example,

I have process-lib.xqy, util-lib.xqy and query-lib.xqy. I used to import these in multiple files like following,

import module namespace util = "util" at "util-lib.xqy";
import module namespace process = "process" at "process-lib.xqy";
import module namespace query = "query" at "query-lib.xqy";

Now I tried to use them in one common file named as common-import.xqy and import this file in multiple files.

when I tried this approach,

import module namespace common-import= "common-import" at "common-import.xqy";

It throws exception as prefix util has no namespace binding.

How to achieve this?

  • 1
    I think you're saying that common-import.xqy imports util, process, and query, then in some other XQuery module you're importing just common-import and trying to call a util namespace function. Is that correct? – Dave Cassel Oct 29 '15 at 13:12
  • yes Dave.you are right.can we achieve this???? –  Oct 30 '15 at 05:41
  • See dirkk's answer, that's what I was going to write. – Dave Cassel Oct 30 '15 at 11:02

1 Answers1

2

This is not possible, at least not in the way you want to do it and rightfully so. The XQuery spec doesn't allow this:

Module imports are not transitive—that is, importing a module provides access only to function and variable declarations contained directly in the imported module. For example, if module A imports module B, and module B imports module C, module A does not have access to the functions and variables declared in module C.

This is a deliberate design decision. If you want to have access in this way you could write a wrapper function for each function you want to access, e.g. in your common-import.xqy file you could have:

declare function common-import:test() { 
  util:test() 
};

But of course this can require a tremendous amount of wrapper functions. I would recommend you stick simply to inserting all required libraries. I see no benefit in doing otherwise.

dirkk
  • 6,160
  • 5
  • 33
  • 51