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

From: Irene Ros []
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 = "";

import module namespace p2=" " 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 = "";

import module namespace p="" 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")
        fn:concat($prefix, ".err")

3. Main query:
xquery version "1.0";
declare namespace db = "";

import module namespace p=" " at "file:///E:/development/quicktune/QueryRunner/modules/testModule.xqy";
import module namespace p2="" 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 (
    at net.sf.saxon.query.QueryModule.makeQueryModule(
    at net.sf.saxon.query.QueryParser.applyModuleImport(
    at net.sf.saxon.query.QueryParser.processPreamble (
    at net.sf.saxon.query.QueryParser.parseQuery(
    at net.sf.saxon.query.QueryParser.makeXQueryExpression(
    at net.sf.saxon.query.StaticQueryContext.compileQuery (
    at net.sf.saxon.query.StaticQueryContext.compileQuery(
    at runner.Querytest1.main(

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.


On Jan 15, 2008 1:55 PM, Michael Kay <> 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