英文:
Throw Error: XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected For_, expecting Order_ or Return_ or Stable_
问题
在qconsole Marklogic中运行以下代码后,我收到以下错误消息:
XDMP-UNEXPECTED: (err:XPST0003) 意外的标记语法错误,意外的For_,期望Order_或Return_或Stable_
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
where $prices/priceList/prod[@num=$order/item/@num]
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return
<item>
{$kk}
</item>
谢谢。
英文:
Once run the below code in qconsole Marklogic, i am getting below error
> XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error,
> unexpected For_, expecting Order_ or Return_ or Stable_
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
where $prices/priceList/prod[@num=$order/item/@num]
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return
<item>
{$kk}
</item>
Thanks..
答案1
得分: 5
不需要使用XQuery 3来完成这个任务。只需在where
和下一个for
之间添加额外的return
:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
where $prices/priceList/prod[@num=$order/item/@num]
return
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return
<item>
{$kk}
</item>
为了遵循Michael的建议并优化以返回完整的项,我会调整XPath,直接返回订单项。类似于以下方式:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
for $item in $order/item
where $prices/priceList/prod[@num = $item/@num]
return
$item
甚至更简洁的方式:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
return
$order/item[@num = $prices/priceList/prod/@num]
英文:
No need for XQuery 3 for this. Just add an extra return
between the where
and the next for
:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
where $prices/priceList/prod[@num=$order/item/@num]
return
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return
<item>
{$kk}
</item>
To follow Michael's excellent advice, and optimize to return full items, I'd flip around the XPath, and return order items directly. Something like:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
for $item in $order/item
where $prices/priceList/prod[@num = $item/@num]
return
$item
Or even shorter:
let $prices := fn:doc('/training/prices.xml')/prices
let $order := fn:doc('/training/order.xml')/order
return
$order/item[@num = $prices/priceList/prod/@num]
HTH!
答案2
得分: 1
在XQuery 1.0中,在where
子句之后不允许再有进一步的for
子句。在Marklogic中,你可能需要在你的查询字符串前加上3.0版本声明:
xquery version "3.0";
英文:
In XQuery 1.0, no further for
clauses are allowed after a where
clause. In Marklogic, you may need to prefix your query string with a 3.0 version declaration:
xquery version "3.0";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论