XPath的“输入"操作员 [英] XPath "in" operator
问题描述
XPath 1.0中是否有一个运算符可以充当SQL中的"in"运算符?
Is there is an operator in XPath 1.0 that acts as "in" operator in SQL?
select * from tbl_students where id in (1,2,3)
推荐答案
尽管XPath 1.0不提供用于编写序列的语法,但XPath 1.0的=运算符可以这样工作.因此,如果您有以下格式的XML文档
The = operator of XPath 1.0 works that way, though XPath 1.0 doesn't provide syntax for writing sequences. So if you have an XML document of the form
<doc>
<value>1</value>
<value>2</value>
<value>3</value>
</doc>
,那么类似//doc[value = 2]
的表达式将返回该doc
元素.
then an expression like //doc[value = 2]
will return that doc
element.
在XPath 2.0中,语法(1, 2, 3)
将创建一个由三个整数组成的序列,并且您可以编写类似$i = (1, 2, 3)
的条件.但是,文字序列不是XPath 1.0的功能-在XPath表达式的一侧获取多个值的唯一方法是使用与多个节点匹配的路径表达式.
In XPath 2.0, the syntax (1, 2, 3)
will create a sequence of three integers, and you can write conditions like $i = (1, 2, 3)
. But literal sequences are not a feature of XPath 1.0 -- the only way to get multiple values on one side of an XPath expression is to use a path expression that matches multiple nodes.
这篇关于XPath的“输入"操作员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!