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.
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(.) };
And then use it in both places with the single definition.