Hi I am trying to match records from two different documents. Match key consists of two parts, so I simply build up a string from first and second match key and separate it by a hypen Here are source documents *Events.xml* <EVENTS>** * *<MSG id=*"{e8e85fdd-04d8-43ea-8090-e72337c3a30d}"* location=*"Prague"* event=*"Christmass"*/>** * *<MSG id=*"{7c94b2fc-b97c-4c09-b694-9993bfb2b93c}"* location=* "Bratislava"* event=*"Easterns"*/>** * *<MSG id=*"{bdbb11da-2c92-425d-9bf5-87c1e96e1bd4}"* location=*"Berlin"* event=*"Berlinale"*/>** </EVENTS>** * * *Reports.xml* <REPORTS>** * *<MSG id=*"{abcd}"* location=*"Prague"* event=*"Christmass"*/>** * *<MSG id=*"{efgh}"* location=*"Bratislava"* event=*"Easterns"*/>** * *<MSG id=*"{ijkl}"* location=*"Paris"* event=*"FassionFest"*/>** * *<MSG id=*"{mnqr}"* location=*"Moscow"* event=*"BalletFestival"*/>** </REPORTS> I am trying to find for each report all events, which are having the same location and event attributes So I build intermediate variables, containing pre-calculated keys And finally I try to find related events *match.xq* (:* *Construct* *matching* *keys* **for** *events* *:)** *let** **$event-msg-keys** *:=* * * *(*for** **$event** **in** */EVENTS/MSG** * **return** * * *<EVENT-MSG id="{$event/@id}" key="{concat($event/@location, '-', $event/@event)}"/>** * *)** * * (:* *Construct* *matching* *keys* **for** *reports* *:)** * * *let** **$report-msg-keys** *:=* * * *(*for** **$report** **in** */REPORTS/MSG* * * **return** * * *<REPORT-MSG id="{$report/@id}" key="{concat($report/@location, '-', $report/@event)}"/>** * *)** * * (:* *Find* *all* *events,* *related* **to** *each* *report:)** *for** **$report-msg** **in** **$report-msg-keys*** *let** **$report-msg-id** *:=* **$report-msg*/@id** *let** **$report-msg-key** *:=* **$report-msg*/@key** * * *let** **$related-events** *:=* * * *(*for** **$event-msg** **in** **$event-msg-keys*** * **where** **$event-msg*/@key* *=* **$report-msg-key*** * **return** **$event-msg*)** * * *return*** <REPORT-MSG id="{$report-msg-id}" key="{$report-msg-key}">** * *<RELATED-EVENTS>{$related-events}</RELATED-EVENTS></REPORT-MSG> However, resulting dokument does not show any related events <REPORT-MSG id=*"{abcd}"* key=*"Prague-Christmass"*>** * *<RELATED-EVENTS/>** </REPORT-MSG>** <REPORT-MSG id=*"{efgh}"* key=*"Bratislava-Easterns"*>** * *<RELATED-EVENTS/>** </REPORT-MSG>** <REPORT-MSG id=*"{ijkl}"* key=*"Paris-FassionFest"*>** * *<RELATED-EVENTS/>** </REPORT-MSG>** <REPORT-MSG id=*"{mnqr}"* key=*"Moscow-BalletFestival"*>** * *<RELATED-EVENTS/>** </REPORT-MSG> *Versions of BaseX* All the time I worked with GUI 1. I started testing on BaseX 6.3.4 2. I used a bit more complex data and query 3. After failing I tried on 6.3.1 4. There I was unable to open the collection with complains about Index out of bound Java error 5. Then I dropped the database and created it again. Trying to run the XQuery I got the same error. 6. returned back to 6.3.4 7. rewrote it to shorted sample, shown above I wonder, what I am doing wrong. Any advice? With best regards Jan Vlčinský