Yuu
Yuu

Reputation: 49

How to declare a function in Xbase

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.

Upvotes: 0

Views: 127

Answers (2)

Michael Kay
Michael Kay

Reputation: 163322

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.

Upvotes: 0

Yuu
Yuu

Reputation: 49

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.

Upvotes: 0

Related Questions