I'm sorry, but it's not clear how $nodes can include the result of my main query:

xquery version "3.0"; declare option output:item-separator ",";
let $db := db:open("CDI")
for $x in $db
let $beginPosition := $x//startTime
let $lon := xs:float($x//longitudine)
let $lat := xs:float($x//latitudine)

where
$beginPosition>="1889-01-01" and $beginPosition<="2015-07-10"
and $lat<=46.733  and  $lat>=-67.81
and $lon<=72.7006667 and $lon >=-79.9666667
return $x
With kind regards,
Menashè
On 07/14/2015 12:51 PM, Christian Grün wrote:
E.g. like that:

  let $count := function($nodes) { count($nodes) }
  let $nodes := (<a/>, <b/>)
  return $count($nodes)



On Tue, Jul 14, 2015 at 12:41 PM, Menashè Eliezer
<meliezer@ogs.trieste.it> wrote:
Thank you, but would you please show me how to pass (only once) for each
function the xml sequence which results from my main query, instead of
simple numbers as in your example?

With kind regards,
Menashè


On 07/14/2015 12:30 PM, Christian Grün wrote:
I hope it's clear.
Sorry, I'm still confuzzled. What is the problem? I guess you want to
define different, exchangable reporting functions for more or less the
same input (dataType, device, ...)?

Here is one way to define functions and call them in a second step:

   let $add := function($a, $b) { $a + $b }
   let $multiply := function($a, $b) { $a * $b }
   for $function in ($add, $multiply)
   return $function(3, 5)

Instead of $add and $multiply, you could have $report-pivoting and
$report-count.



On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer
<meliezer@ogs.trieste.it> wrote:
Hi,
The initial of the code should be modified, so here is only the essence
of
one of the pivoting reports:
for $singleDataType in $dataType

for $singleDevice in $device

for $singleAvailability in $availability

for $singleCountry in  $country

for $singleParameter in $parameter

group by

$singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter
order by

$singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter

return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}"
Availability="{$singleAvailability}" Country="{$singleCountry}"
Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/>

Other report will count all records with one less condition:

group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry
order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry

return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}"
Availability="{$singleAvailability}" Country="{$singleCountry}"
Parameter="Any" NumberOfRecords="{count($current-pre)}"/>

I hope it's clear.

With kind regards,
Menashè