How to declare Global variable of XQuery in XML
In this article we will discuss about how to declare and use the Global variables of XQuery.
Global variable are those variables which are declared at the top of any module and can be accessed by any part of the module. We can also use the concept of Global variables in XQuery. We can declare variables outside the XQuery modules and can use it in any part of that XQuery module. We will use the declare keyword to declare the variables and assign them any kind of value.
Here is the example of declaring and assigning the global variables in the XQuery module.
declare variable $message := ("message1","message2");
<output>
<print>{$message[1]}</print>
<print>{$message[2]}</print>
</output>
|
Output:
<?xml version="1.0" encoding="utf-8" ?>
<output>
<print>message1</print>
<print>message2</print>
</output>
|
There is another example of it.
declare variable $mm := ();
declare variable $value := "Honesty";
declare variable $twice := (<example />, "Honesty");
<output>{$twice[2]}</output>
|
In this example we have seen in the first line that a variable can be assigned even an empty value .i.e.( ). Here $twice[2] means second value of the twice variable has been accessed.
Output:
<?xml version="1.0" encoding="utf-8" ?>
<output>Honesty</output>
|
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here