I am trying to manage the output of the map:get function in BaseX.
The mapping file looks as follows:
<around>
<point NR="51151">161</point>
<point NR="31252">82</point>
<point NR="54321">323</point>
<point NR="54321">319</point>
<point NR="54321">327</point>
</around>
and represents some geographic points with the No. as attribute (NR) and the distance from the certain search point as value. There are some points which are present more than one time (as the point 54321 in the example above). This is content-related ok since these are "branches" of the point with the same No.
What I wand to get is the average from the distances if I lookup these NR's.
My query:
let $c :=
<around>
<point NR="51151">161</point>
<point NR="31252">82</point>
<point NR="54321">323</point>
<point NR="54321">319</point>
<point NR="54321">327</point>
</around>
for $r in $c//point
let $m := map { data($r/@NR) := $r/text() }
return
if ( map:contains($m, '54321' ) ) then
avg(map:get($m, '54321'))
else
()
... returns 323 319 327
, thus ignores the "avg" though there is no syntax error message in BaseX.
How could I achieve the above? Many thanks in advance!
{avg($m($p))}
into $w/Data else ()` Thank you! – v_e Jan 06 '13 at 13:29