Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I declare a global variable in xquery in Marklogic Server?

I want a global variable which I can use in my different .xqy pages. Can I declare such a variable in xquery in Marklogic Server ?

like image 509
Puneet Pant Avatar asked Jun 15 '12 08:06

Puneet Pant


People also ask

How do you declare a variable in XQuery?

declare variable $x := 7.5; declare variable $x as xs:integer := 7; Functions. “XQuery allows users to declare functions of their own. A function declaration specifies the name of the function, the names and datatypes of the parameters, and the datatype of the result.

How does XQuery interface with Marklogic document store database?

It uses XML and JSON documents, along with RDF triples, as its data model, and stores the documents within a transactional repository. It indexes the words and values from each of the loaded documents, as well as the document structure.


2 Answers

You can declare a variable in any module. For instance, it is config.xqy.

declare variable $PRECISION as xs:integer := 4;

For using this variable you need to import this module in your work module.

import module namespace config = "http://your-namespace" at "config.xqy";

And refer to this variable:

$config:PRECISION
like image 137
Andrei Orlov Avatar answered Oct 24 '22 08:10

Andrei Orlov


If your application is running on a single E-node, you can use server fields , which are sort of designed for this use case as well.

like image 27
Eric Bloch Avatar answered Oct 24 '22 06:10

Eric Bloch