# saxon:import-query

The saxon:import-query element is a top-level declaration that causes an XQuery library module to be imported into the stylesheet.

The effect is that the functions defined in the library module become available for calling from any XPath expression in the stylesheet, as extension functions. They are available in all modules of the stylesheet.

Only the functions actually defined in the given XQuery module are imported. Functions that the specified module imports from other XQuery modules are not imported. This follows the semantics of XQuery's `import module` declaration. Variables defined in an imported module are not (currently) imported into the stylesheet.

The imported functions do not have any specific import precedence. If a stylesheet contains two `saxon:import-query` declarations importing the same namespace, then they are assumed to refer to the same library module, and all but the first are ignored. As with other extension functions, the `override="yes|no"` attribute on `xsl:function` can be used to determine whether a stylesheet function overrides an imported XQuery function of the same name.

The `saxon:import-xquery` function has two optional arguments. The `href` argument is the (absolute or relative) URI of the XQuery module. The `namespace` argument identifies the module namespace of the imported module. If href alone is specified, then the module is loaded from the given location. If namespace alone is specified, then the module must already be present in Saxon's `Configuration` object (you can share a Configuration between multiple stylesheets, which means that imported XQuery modules will not need to be recompiled for each one). If both attributes are specified, then Saxon uses an already-loaded module for the namespace if it can, otherwise it fetches it from the specified location, and checks that the namespace is correct. I would recommend specifying both attributes.

Expand | Up Next