0

Hi this is probably an odd question but i would like to know how i can declare a function in Xbase.

I was told this is how :

declare function prefix:name($parameter as DataType)
as returnDataType {
..code..
};

I did this :

declare function local:test($i as xs:integer?)
as xs:integer
{
return $i
};

But it keep saying that i have a syntax problem

Expecting expression.

Yuu
  • 49
  • 8

2 Answers2

0

I found the answer to this question, the problem is that when you declare a function in Xbase you have to call it after the declaration like this:

//declare your function
<test>{local:test("Example")}</test>

Otherwise, it will consider it as a syntax problem.

Yuu
  • 49
  • 8
0

Your function should be

declare function local:test($i as xs:integer?)
as xs:integer
{
   $i
};

In XQuery the return keyword is used only in a FLWOR expression.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Yes, sorry, I did (let $i:=1 return $i), I forgot to include it, the problem was not really in the declaration but in the fact that I didn't call the function after declaring it, if you don't Xbase will consider it as a syntax error.. – Yuu Dec 27 '21 at 09:04
  • Well, in future, it helps to post the actual code that gives you the error, otherwise you're wasting everyone's time. – Michael Kay Dec 27 '21 at 12:00