Mayoco
Mayoco

Reputation: 87

XQuery Error: XPTY0019: Required item type of first operand of '/' is node();

I want to grab some data from xml by xquery. The original xml is something like:

<mondial>
<country id="AAA" name="BBB" gdp_total="XXX" population_growth="XXX">
<name>BBB</name>
<city id="CCC" country="AAA">
<name>DDD</name>
<population>XXXX</population>
<located_at type="XX"/>
</city>
...
</country>
...
</mondial>

I write a XQuery like that:

declare function local:globals_1(){
let $countries:=("mondial-3.0.xml")//country[@gdp_total > number(100000) and @population_growth > number(0.3)]
let $cities:=("mondial-3.0.xml")//city
for $country in $countries
for $city in $cities
where $country/@id = $city/@country 
order by number($city/@population)
return $city
};
<globals>
{local:globals_1()}
</globals>

An error came up:

F [Saxon-PE XQuery 9.6.0.7] XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:string

enter image description here

Upvotes: 0

Views: 1388

Answers (1)

har07
har07

Reputation: 89285

("mondial-3.0.xml") is just a sequence of string containing single item. It is not a kind of node(), hence the error. I believe you want to call doc() function instead to read data from file :

let $countries := doc("mondial-3.0.xml")//......
let $cities := doc("mondial-3.0.xml")//city
......

Upvotes: 1

Related Questions