我对 XQuery 很陌生,所以如果我遗漏了什么,请原谅。
我正在尝试提取元素的某些子节点是 DISTINCT 的数据,以及某个兄弟节点等于某个预定义字符串的数据
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>
所以基本上我只想要产品的 DISTINCT 出现,并且只希望类别的名称属性等于“便宜”。
我的查询返回 DISTINCT 产品,但 where 子句似乎没有效果,它仍然返回类别为“昂贵”的产品。
任何人都可以建议我做错了什么。