On 12/19/2022 10:58 PM, Graydon wrote:
On Mon, Dec 19, 2022 at 10:43:25PM +0100, Leo Studer scripsit:
In the code below I encounter the problem, that I have to define the same xPath function variable $organizations twice and I do not understand why.
In line 10, you've used a let clause to bind a variable of type function to the name organizations. That's in context a specific FLOWR expression.
The expression in the return clause of that FLOWR expression returns an element constructor where the contents expression contains another FLOWR expression. The first definition on line 10 will be out of scope in there.
I don't think so, the variable is not out of scope, it is bound for each item in the group to that function, meaning that value in the return clause of the group is a sequence of functions and that way
head($organizations)($country)
would work.
You could define the function with scope for the module:
declare function local:getOrganizations($in as element(country)) as xs:string* { let $thisCountry as xs:string := $in/@id/string(); return $doc//organization[members/@country = $thisCountry]/@abbrev/string(.) };
That is certainly the cleaner way.