考虑一个定义为的 xml 文件:
<?xml version="1.0"?>
<sports>
<teams>
<team tno="t100">
<tname>Knights</tname>
<city>London</city>
</team>
<team tno="t200">
<tname>Dukes</tname>
<city>Surrey</city>
</team>
<team tno="t300">
<tname>Kings</tname>
<city>Leeds</city>
</team>
</teams>
<players>
<player pid="p501">
<pname>Simon</pname>
<city>London</city>
</player>
<player pid="p502">
<pname>Andrew</pname>
<city>Birmingham</city>
</player>
<player pid="p503">
<pname>Mike</pname>
<city>London</city>
</player>
</players>
<parts>
<part pno="801">
<pname>Right Gloves</pname>
<price>8.99</price>
</part>
<part pno="901">
<pname>Left Gloves</pname>
<price>9.99</price>
</part>
<part pno="851">
<pname>Left Pad</pname>
<price>33.00</price>
</part>
<part pno="951">
<pname>Right Pad</pname>
<price>43.00</price>
</part>
</parts>
<orders>
<order ono="61" playerNum="p501" team="t200" >
<kits>
<kit>
<pNum>801</pNum>
<qty>11</qty>
</kit>
</kits>
</order>
<order ono="62" playerNum="p501" team="t100" >
<kits>
<kit>
<pNum>901</pNum>
<qty>12</qty>
</kit>
</kits>
</order>
<order ono="63" playerNum="p502" team="t300" >
<kits>
<kit>
<pNum>851</pNum>
<qty>9</qty>
</kit>
</kits>
</order>
<order ono="64" playerNum="p503" team="t300" >
<kits>
<kit>
<pNum>951</pNum>
<qty>16</qty>
</kit>
</kits>
</order>
<order ono="65" playerNum="p503" team="t200" >
<kits>
<kit>
<pNum>801</pNum>
<qty>12</qty>
</kit>
<kit>
<pNum>901</pNum>
<qty>16</qty>
</kit>
<kit>
<pNum>851</pNum>
<qty>13</qty>
</kit>
</kits>
</order>
</orders>
</sports>
我尝试运行的查询是获取某个订单的总定价(比如订单 65)。BaseX 中的查询是:
let $d:=doc("sports.xml")
let $o:=$d/sports/orders/order[@ono=65]
let $p:=$d/sports/parts/part
for $k in $o/kits/kit
return <OrderCost>
({$k/qty})*({$p[@pno=$k/pNum]/price})
</OrderCost>
我的输出:
<OrderCost>
(<qty>12</qty>)*(<price>8.99</price>)
</OrderCost>
<OrderCost>
(<qty>16</qty>)*(<price>9.99</price>)
</OrderCost>
<OrderCost>
(<qty>13</qty>)*(<price>33.00</price>)
</OrderCost>
我无法将数量与相应的价格相乘,然后得到总和。我在这里做错了什么?