I have a question on xquery grouping. From what I understand, the usual case would be to use distinct-values on the docs in the for loop, however as I have a condition to fulfill before grouping the values, and I am not quite sure how this can be done.
This is part of my xmldb:
<element tag="0001,0000" name="Pos1>198</element>
<element tag="0001,0001" name="Pos2">123</name>
<element tag="0002,0001" name="Pos3">433</element>
<element tag="000b,0000" name="Pos3">16</element>
<element tag="0005,0000" name="Pos4>532</element>
<element tag="0005,0001" name="Pos5">342</name>
<element tag="0008,0001" name="Pos6">17</element>
The condition to fulfill is that the x-coordinates (number or hexdec) have to be in odd values (e.g. from the above xml, i would only need results from tag="0001,...", tag="000b,...", tag="0005,..."), and then count how many items in each group.
This is how the results should look like:
<group>
<element xcoord="0001">2</element>
<element xcoord="000b">1</element>
<element xcoord="0005">2</element>
</group>
My xquery code so far looks like this, where I could generate results that have odd x-coordinates, but I have no idea how to proceed on from here for the grouping.
import module namespace functx="http://www.functx.com" at "http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq";
for $x in collection('/db/mapdb/')//element
let $coord := number(functx:substring-before-last($x/@tag, ","))
where $coord mod 2 != 0
return $x
Kindly advise me. Thank you very much.