Am 26.02.2020 um 12:42 schrieb Ben Engbers:
Hi,
I want to declare a function that can operate on various elements of a record. It should be possible to pass the element-name as parameter to the function.
I tried this:
declare function local:cloudWords( $Veld as xs:string ) as xs:string* { let $base := collection('IncidentRemarks/Incidentsv')/csv/record let $txt := string-join( $base/$Veld/text(), " ") let $words := tokenize($txt,'(\s|[,.!:;]|[n][b][s][p][;])+') return ($words) };
let $retValue := local:cloudWords("INC_RM") return $retValue
But I get this error: [XPTY0019] text(): node expected, xs:string found: "INC_RM".
Should I use xquery:eval to transform "$base/$Veld/text()" into "$base/INC_RM/text()"
For such simple cases with an element name it seems
$base/*[local-name() = $Veld]
suffices.