How to declare local variable in XML using XQuery

In this article we will discuss about how to declare and use the local variables in XQuery.
  • 22475

Local variable are those variables which are only accessible in the block in which they are declared. We can declare local variable in XQuery as well. Local variable can be declared  and assigned a value using the let clause in XQuery and unlike the global variables local variables can be accessed only within the scope in which they are declared.

Here is the example to declare and use the Local variables in XQuery.

declare variable $msg := ("msg1","msg2");
declare function local : print ($num as xs:integer) as item() {
                  let $x := 1;
                  return local : print($x)
                  let $x := 2;
                  return local : print($x)

Here $x is the local variable.


<?xml version="1.0" encoding="utf-8" ?>





Ask Your Question

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.