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