对于问题2,我应该返回所有产品的名称和价格,加价幅度恰好为25%。但是,我不太确定如何解决我当前正在处理的xquery的错误,因为它表示预期为“)”,发现名称为“ Where”。
这是我的xml外观:
<product pid="323">
<name>gizmo</name>
<price>22.99</price>
<description>great</description>
<store sid="s521">
<name>Econo-Wiz</name>
<phone>555-6543</phone>
<markup>10%</markup>
</store>
</product> ```
And this is my xquery:
```for $p in distinct-values(document("products.xml")//product)
Where every $m in (document("products.xml")//product[name=$p/name]/markup)
satisfies $m="25%"
return {$p/name, $p/price}```
The error was highlighted in this sentence: Where every $m in (document("products.xml")//product[name=$p/name]/markup)
I would like to seek advise in regards as to how should i change up my xquery as i am new to it. Thank you.
我认为您无需使其变得如此复杂。
假设文档存储在$products
中,类似的内容应该可以为您提供所需的信息:
for $prod in $products//product
where $prod[store/markup[.="25%"]]
return ($prod/name, $prod/price)
您也可以完全省去xquery,而只需使用xpath:
//product[store/markup[.="25%"]]/(name,price)