XQuery - 如何对一组值使用 eq (=)
我想知道如何查询一种特定语言,这是一个相关的 XML 片段:
(...)
<Guide guideID = '5' gname = 'Dexter Schneider'>
<Lang lname = "{'Spanish' , 'German' , 'English'}"/>
</Guide>
(...)
我尝试过:
element Result {
//Guide[Lang/@lname = 'German']
}
但我只得到“德语”是“lname”中唯一语言的结果。我怀疑这要么是因为 XML 文档不正确(XQuisitor 没有发出有关语法的警告),要么是因为“=”符号只能将一个字符串与另一个字符串进行比较。有人能解释一下这一点,并向我展示正确的查询是什么样子吗?谢谢!
I would like to know how you could query for one specific language, this is a related XML-snippet:
(...)
<Guide guideID = '5' gname = 'Dexter Schneider'>
<Lang lname = "{'Spanish' , 'German' , 'English'}"/>
</Guide>
(...)
I tried with:
element Result {
//Guide[Lang/@lname = 'German']
}
but I only get the results where "German" is the only language in "lname". I suspect this is either because of a bad XML-document (no warnings from XQuisitor about the syntax), or because the "="-sign can only compare one exact string with another. Could anyone shed some light on this, and show me how a proper query would look like? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的具体情况,您可以使用
//Guide[contains(Lang/@lname, 'German')]
。更一般地说,属性的值是字符串而不是数组。
对于您的用例,您可以使用序列,但首先必须构建序列。
例如,如果您有这样的 XML:
您可以使用以下 XPath 2.0 语法(符合 xquery):
tokenize
函数创建一个序列,=
测试您的内容想。In your specific case, you can use
//Guide[contains(Lang/@lname, 'German')]
.More generaly, the value of your attribute is a string and not an array.
For your use case, you can use sequences but you first have to build the sequence.
For example, if you have an XML like that :
You can use the following XPath 2.0 syntax (xquery compliant) :
The
tokenize
function creates a sequence and the=
tests what you want.根据您的 XQuery 引擎,此 XPath 应该可以工作:
Depending on your XQuery engine, this XPath should work: