This is a different error, and in fact the XQuery specification doesn't allow cyclic imports in this way, so Saxon is correct to report the error. It's a horrible restriction, however, so Saxon provides a switch that causes it not to be enforced. Add this line to the query prolog of the main module:
 
declare option saxon:allow-cycles "true";
 
but note that if you use this option then your code will not be portable to other XQuery processors. This line must appear after the module imports, but before any variable functions. If I remember correctly, it is needed only in the main query module.
 
Michael Kay
http://www.saxonica.com/


From: Irene Ros [mailto:imirene@gmail.com]
Sent: 15 January 2008 22:09
To: Michael Kay
Subject: Re: [saxon] importing modules into modules

Hi Michael,

Thank you for the quick response. I upgraded my jars to the latest release and had to slightly change the modules to reproduce the error but here are the updated files:

1. module1
module namespace p = " http://www.lotus.com/quicktune/print";

import module namespace p2="http://www.lotus.com/quicktune/print2 " at "file:///E:/development/quicktune/QueryRunner/modules/testModule2.xqy";

declare function p:gen-gen-err($prefix as xs:string, $bDiff as xs:boolean) as xs:string {
    p2:appender($prefix, $bDiff)
}; 


2. module2
module namespace p2 = "http://www.lotus.com/quicktune/print2";

import module namespace p=" http://www.lotus.com/quicktune/print" at "file:///E:/development/quicktune/QueryRunner/modules/testModule.xqy";

declare function p2:appender($prefix as xs:string, $bDiff as xs:boolean) as xs:string {

    if ($bDiff) then
        fn:concat($prefix, ".configdoc.err")
    else
        fn:concat($prefix, ".err")
};

3. Main query:
xquery version "1.0";
declare namespace db = "http://www.lotus.com/dxl/console";

import module namespace p="http://www.lotus.com/quicktune/print " at "file:///E:/development/quicktune/QueryRunner/modules/testModule.xqy";
import module namespace p2="http://www.lotus.com/quicktune/print2" at "file:///E:/development/quicktune/QueryRunner/modules/testModule2.xqy";

p:gen-gen-err("prefix", true())

The error I get is as follows:
Error on line 5 column 1 of file:/E:/development/quicktune/QueryRunner/modules/testModule2.xqy:
  XQST0073: A module cannot import itself directly or indirectly, unless all modules in the
  cycle are in the same namespace
Error on line 5 column 1 of file:/E:/development/quicktune/QueryRunner/modules/testModule.xqy:
  XQST0073: Static errors were reported in the imported library module
Error on line 7 column 1
  XQST0073: Static errors were reported in the imported library module
; Line#: 7; Column#: 1
net.sf.saxon.trans.XPathException: Static errors were reported in the imported library module
    at net.sf.saxon.query.QueryParser.parseLibraryModule (QueryParser.java:324)
    at net.sf.saxon.query.QueryModule.makeQueryModule(QueryModule.java:183)
    at net.sf.saxon.query.QueryParser.applyModuleImport(QueryParser.java:1103)
    at net.sf.saxon.query.QueryParser.processPreamble (QueryParser.java:668)
    at net.sf.saxon.query.QueryParser.parseQuery(QueryParser.java:269)
    at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:103)
    at net.sf.saxon.query.StaticQueryContext.compileQuery (StaticQueryContext.java:338)
    at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:372)
    at runner.Querytest1.main(Querytest1.java:51)

Can you reproduce with the above example? I know it's sort of recursive importing but the actual modules in questions are fairly large so cross use of functions is common.

Thanks!!
-Irene


On Jan 15, 2008 1:55 PM, Michael Kay <mike@saxonica.com> wrote:

Sorry, but I can't reproduce the error.

You haven't actually shown your main module. This is rather critical: it
looks as if the system hasn't recognized that the main module and module1
are both importing the same thing when they import module2. I can't tell why
that should be without seeing both.

I also need to know what environment you are running in. What Saxon version
(the stack trace suggests it's not the latest)? Java or .NET? And how are
you running the query?

Michael Kay