tags:

views:

41

answers:

2

xquery version "1.0";

declare function con($s1 as xs:anyAtomicType, $s2 as xs:anyAtomicType) as xs:string {
return concat($s1, $s2 ) };

declare variable $str1 as xs:string:="samah"; declare variable $str2 as xs:string:="sama"; declare variable $comstring:=con($str1 ,$str2 ); {$comstring }

A: 

Your query has a syntax error. return is only valid following a for, let, where or order by clause. Remove the word return.

Secondly, { and } are only valid inside node content, and so should be removed.

Finally functions and variables cannot be declared in the XQuery functions namespace, so these functions and variables will have to be declared in another namespace.

Surely the compiler errors should have told you all this?

declare namespace test = "http://www.example.org/test";

declare function test:con($s1 as xs:anyAtomicType, $s2 as xs:anyAtomicType) as xs:string
{
    concat($s1, $s2)
};

declare variable $test:str1 as xs:string:="samah";
declare variable $test:str2 as xs:string:="sama";
declare variable $test:comstring:=test:con($test:str1 ,$test:str2 );

$test:comstring
Oliver Hallam
+1  A: 

This works too:

xquery version "1.0";

declare namespace local = "local";

declare variable $str1 as xs:string:="samah"; 
declare variable $str2 as xs:string:="sama"; 
declare variable $comstring := local:con($str1 ,$str2 ); 

declare function local:con($s1 as xs:anyAtomicType, $s2 as xs:anyAtomicType) as xs:string 
{
  concat($s1, $s2 ) 
};

$comstring 
Pabs