Throw Error: XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected For_, expecting Order_ or Return_ or Stable_

huangapple go评论57阅读模式
英文:

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(&#39;/training/prices.xml&#39;)/prices
let $order := fn:doc(&#39;/training/order.xml&#39;)/order
where $prices/priceList/prod[@num=$order/item/@num]
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return 
&lt;item&gt;
{$kk}
&lt;/item&gt;

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(&#39;/training/prices.xml&#39;)/prices
let $order := fn:doc(&#39;/training/order.xml&#39;)/order
where $prices/priceList/prod[@num=$order/item/@num]
return
for $kk in $prices/priceList/prod[@num=$order/item/@num]
return 
&lt;item&gt;
{$kk}
&lt;/item&gt;

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(&#39;/training/prices.xml&#39;)/prices
let $order := fn:doc(&#39;/training/order.xml&#39;)/order
for $item in $order/item
where $prices/priceList/prod[@num = $item/@num]
return
    $item

Or even shorter:

let $prices := fn:doc(&#39;/training/prices.xml&#39;)/prices
let $order := fn:doc(&#39;/training/order.xml&#39;)/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 &quot;3.0&quot;;

huangapple
  • 本文由 发表于 2020年1月6日 19:50:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定