2

You can store a module in eXist, such as the following, say under /modules/my.xqm:

module namespace my = "http://www.example.com/";
declare function my:answerToTheUltimateQuestion() as xs:integer { 42 }

And then import it into a query, such as:

import module namespace my="http://www.example.com/" 
                        at "xmldb:exist:///db/modules/my.xqm";
my:answerToTheUltimateQuestion()

Instead of storing the XQuery in a "text file", is it possible to store it in an XML file, which would just be a wrapper around the XQuery? I am thinking about a wrapper similar to the one we use when POSTing queries to eXist (<exist:query><exist:text>). This would make it easier to manipulate XQuery modules with tools that expects XML data stored in the database.

avernet
  • 30,895
  • 44
  • 126
  • 163

1 Answers1

3

You could store your XQuery in XQueryX format into eXist-db and then use a small XQuery and the XSLT from the XQueryX W3C spec within eXist-db to transform this into XQuery and execute it.

  • Adam, thank you for the advice. So I've got my XML file that contains the XQuery for the module in `module.xml`: `XQuery for module`. At the beginning, I add: ``. When I do a GET for `module.xml`, it gets processed by the XSLT, and I get back the XQuery. The only issue is that the content type is text/html, instead of application/xquery. I added an `` to the XSLT, but this doesn't seem to have an effect on the content type. Am I missing something? – avernet Feb 08 '11 at 19:03