XQuery Modules

A guide to using XQuery modules in XmlPrime.

This topic contains the following sections.

Overview

A module is a collection of functions and global variables, all in the same target namespace that can be called from within an XQuery program, XPath expression or XSL transformation. A library is a set of modules all with the same target namespace. XmlPrime supports three types of modules: Built in modules, XQuery modules and native .NET modules. This document explains how XQuery modules are created and managed, and how to use them with XmlPrime.

XQuery modules

XQuery modules can be called from XQuery programs, XPath expressions and XSL transformations. The following code details how an XQuery module can be pre-compiled for use in an XSL transformation.

 
        
using XmlPrime;
        
// Create the XQuerySettings with an XmlUrlResolver used to resolve module location hints.
XQuerySettings moduleSettings = new XQuerySettings {ModuleResolver = new XmlUriResolver() };

// Create a library set.
LibrarySet librarySet = new LibrarySet();

// Add a module with target namespace "urn:module" with source code ing "module.xqm"
librarySet.Add(moduleSettings, "urn:module", "module.xqm");

// Compile the library set.
librarySet.Compile();

// Create the XsltSettings instance.
XsltSettings settings = new XsltSettings { LibrarySet = librarySet };

// Compile a transformation using functions defined in module "urn:module".
var xslt = Xslt.Compile("transform-using-extension.xsl", settings);