Hello Shaun,

 

seems like a simple mistake with your parathesis. It should be:

 

declare variable $diagramSelection := xquery:eval(file:read-text("D:\\XQuery\\VPExchange Queires\\diagramSelectionCoR.xq"), $bindings);

 

Instead, you applied $bindings to the file:read-text() function, which expects a string as a second parameter, thus BaseX tries to atomize the map to a string, which fails as you have seen.

 

Hope this helps

Dirk

 


Senacor Technologies Aktiengesellschaft - Sitz: Eschborn - Amtsgericht Frankfurt am Main - Reg.-Nr.: HRB 105546
Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Daniel Grözinger

Von: basex-talk-bounces@mailman.uni-konstanz.de [mailto:basex-talk-bounces@mailman.uni-konstanz.de] Im Auftrag von Shaun Flynn
Gesendet: Samstag, 21. Oktober 2017 08:07
An: BaseX <basex-talk@mailman.uni-konstanz.de>
Betreff: [basex-talk] xquery:eval Issue with bindings

 

Hello there,

 

I am trying to use xquery:eval method supplying bindings as map, and following the example on the website where the bindings are supplied as a map. However, when I run the following query, I get the error "Items of type map(*) cannot be atomized". What am I doing wrong?

 

(:Filter out the required diagrams from $diagrams:)

declare variable $depotConstraint external := "OC";

declare variable $resConstraint external := "NIL";

declare variable $lowerDiagNoConstraint external := "NIL";

declare variable $upperDiagNoConstraint external := "NIL";

 

(:Bindings for diagramSelectionCoR.xq:)

declare variable $bindings := map {

  xs:QName("depotConstraint") : $depotConstraint, 

  xs:QName("resConstraint") : $resConstraint, 

  xs:QName("loweDiagNoConstraint") : $lowerDiagNoConstraint, 

  xs:QName("upperDiagNoConstraint") : $upperDiagNoConstraint};

 

declare variable $diagramSelection := xquery:eval(file:read-text("D:\\XQuery\\VPExchange Queires\\diagramSelectionCoR.xq", $bindings));

 

$diagramSelection

 

For completeness, the query being loaded in the $diagramExchange "xquery:eval" is:

 

declare default element namespace "http://www.scfy.com/TTVP_Interface";

 

declare variable $date := "2017-07-10";

declare variable $daysRun := 3;

declare variable $diagrams := diagramExchange/unitDiagramList/unitDiagram[@startdate<=$date][@enddate>=$date][substring(@daysrun,$daysRun,1)="Y"];

 

declare variable $depotConstraint external := "NIL";

declare variable $resConstraint external := "NIL";

declare variable $lowerDiagNoConstraint external := "NIL";

declare variable $upperDiagNoConstraint external := "NIL";

 

declare variable $depots := tokenize($depotConstraint," ");

declare variable $resources := tokenize($resConstraint," ");

declare variable $lowerDiagNo := tokenize($lowerDiagNoConstraint," ");

declare variable $upperDiagNo := tokenize($upperDiagNoConstraint," ");

 

declare function local:begin($diagrams, $index) {

  local:applyDiagStartFilter($diagrams,$index)

};

 

(: Chain of responsibility pattern used here : once one function exits, passes to the next:)

 

declare function local:applyDiagStartFilter($diagrams, $index) {

  let $diagNo := $lowerDiagNo[$index]

  return

  if($diagNo = "NIL") then 

  (local:applyDiagEndFilter($diagrams, $index)) 

  else 

  (local:applyDiagEndFilter($diagrams[@id >= $diagNo cast as xs:integer], $index))

};

 

declare function local:applyDiagEndFilter($diagrams, $index) {

  let $diagNo := $upperDiagNo[$index]

  return

  if($diagNo= "NIL") then 

  (local:applyResFilter($diagrams, $index)) 

  else 

  (local:applyResFilter($diagrams[@id <= $diagNo cast as xs:integer], $index))

};

 

declare function local:applyResFilter($diagrams, $index) {

  let $res := $resources[$index]

  return

  if($res = "NIL") 

  then 

  (local:applyDepotFilter($diagrams, $index)) 

  else 

  (local:applyDepotFilter($diagrams[res/@id = $res], $index))

};

 

declare function local:applyDepotFilter($diagrams, $index) {

  let $depot := $depots[$index]

  return

  if($depot = "NIL")

  then 

  ($diagrams) 

  else 

  ($diagrams[depot/@id = $depot])

};

 

for $depot in $depots

count $count

return local:begin($diagrams, $count)