i have multiple xml docs, each of them has multiple LightSpot and EquipmentType. I would like to extract a single aggregated value over all the documents. So i tried to nest two queries in order to apply a double aggregation. The second query aggregation returns empty values for NumberOfLightSpots and EquipmentType even though if i return the variable $grouped_sheet the output not aggregated is displayed.
This is the code i used in eXist-db
let $grouped_sheets := for $sheet in collection('/db/light')
return
<sheet
NumberOfLightSpots ="{count($sheet//LightSpot)}"
EquipmentType ="{distinct-values($sheet//EquipmentType)}"
/>
for $grouped_sheet in $grouped_sheets
return <sheet
NumberOfLightSpots ="{count($grouped_sheet//NumberOfLightSpots)}"
EquipmentType ="{distinct-values($grouped_sheet//EquipmentType)}"
/>
The final return value is empty, in fact i have this output:
<sheet NumberOfLightSpots="0" EquipmentType=""/>
<sheet NumberOfLightSpots="0" EquipmentType=""/>
<sheet NumberOfLightSpots="0" EquipmentType=""/>
....
Thanks
Edit:
The structure of the return should be:
<sheet>
<NumberOfLightSpots>{count($sheet//LightSpot)</NumberOfLightSpots>
<EquipmentType>{distinct-values($sheet//EquipmentType)}</EquipmentType>
</sheet>