XQuery 不同值与 where 子句问题
我对 XQuery 很陌生,所以如果我遗漏了什么,请原谅。
我正在尝试提取元素的某些子节点不同的数据,以及某个同级节点等于某个预定义字符串的数据
for $product in fn:distinct-values(document('cpwdoc')/root/package/properties/value[@key="product"])
where document('cpwdoc')/root/package/categories/category[@name="Cheap"]
return $product
我正在查询的 XML 如下所示:
<root>
<package>
<title>Some package 1</title>
<categories><category group="Other" name="Cheap"/></categories>
<properties>
<value key="product">BLUE-TOOTHBRUSH</value>
</properties>
</package>
<package>
<title>Some package 2</title>
<categories><category group="Other" name="Expensive"/></categories>
<properties>
<value key="product">BLUE-TOOTHBRUSH</value>
</properties>
</package>
<package>
<title>Some package 3</title>
<categories><category group="Other" name="Expensive"/></categories>
<properties>
<value key="product">TOOTHPASTE</value>
</properties>
</package>
</root>
所以基本上我只想要产品的不同出现,并且仅当类别的名称属性等于“Cheap”时。
我的查询返回 DISTINCT 产品,但 where 子句似乎没有效果,它仍然返回类别为“昂贵”的产品。
谁能告诉我我做错了什么。
I'm very new to XQuery so excuse me if I am somehow missing something.
I am trying to extract data where certain sub-nodes of an element are DISTINCT, as well as where a certain sibling node's is equal to some predefined string
for $product in fn:distinct-values(document('cpwdoc')/root/package/properties/value[@key="product"])
where document('cpwdoc')/root/package/categories/category[@name="Cheap"]
return $product
The XML I am querying looks like this:
<root>
<package>
<title>Some package 1</title>
<categories><category group="Other" name="Cheap"/></categories>
<properties>
<value key="product">BLUE-TOOTHBRUSH</value>
</properties>
</package>
<package>
<title>Some package 2</title>
<categories><category group="Other" name="Expensive"/></categories>
<properties>
<value key="product">BLUE-TOOTHBRUSH</value>
</properties>
</package>
<package>
<title>Some package 3</title>
<categories><category group="Other" name="Expensive"/></categories>
<properties>
<value key="product">TOOTHPASTE</value>
</properties>
</package>
</root>
So basically I want only DISTINCT occurances of the product, and only where the name attribute of the category is equal to "Cheap".
My query returns DISTINCT products, but the where clause seems to have no effect, it still returns products whose category is "Expensive".
Can anyone advise as to what I am doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 where 子句:
扩展为:
这相当于
,因此只要有至少一种廉价产品,您就会退回所有产品。
您想要类似以下内容的内容
,如果您喜欢路径表达式,则与以下内容相同
Your where clause:
is expanded out to:
which is equivalent to
and so you are returning all products as long as there is at least one cheap product.
You want something like the following
which if you like path expressions is the same as