XQuery使用谓词:return和for之间的区别

时间:2018-05-25 17:15:10

标签: xpath xquery basex

我认为这两个xquery表达式是等价的:

for $x
  in doc("hamlet.xml")//LINE[../SPEAKER = "HAMLET"]
  return $x[../preceding-sibling::SPEECH[1]/SPEAKER = "MARCELLUS"]

for $x
  in doc("hamlet.xml")//LINE[../SPEAKER = "HAMLET"][../preceding-sibling::SPEECH[1]/SPEAKER = "MARCELLUS"]
  return $x

不同之处在于首先在返回中使用的谓词,以及在for中之后使用的谓词。为什么输出不一样?

https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml

编辑::我使用BASEX 9.0.1。

1 个答案:

答案 0 :(得分:1)

他们看起来和我一样。

Saxon给出的第一个查询

<LINE>I am very glad to see you. Good even, sir.</LINE>
<LINE>But what, in faith, make you from Wittenberg?</LINE>
<LINE>Did you not speak to it?</LINE>
<LINE>Arm'd, say you?</LINE>
<LINE>From top to toe?</LINE>
<LINE>Then saw you not his face?</LINE>
<LINE>Hold off your hands.</LINE>
<LINE>How say you, then; would heart of man once think it?</LINE>
<LINE>But you'll be secret?</LINE>
<LINE>There's ne'er a villain dwelling in all Denmark</LINE>
<LINE>But he's an arrant knave.</LINE>
<LINE>Nay, but swear't.</LINE>
<LINE>Upon my sword.</LINE>
<LINE>Indeed, upon my sword, indeed.</LINE>

对于Saxon给出的第二个查询:

<LINE>I am very glad to see you. Good even, sir.</LINE>
<LINE>But what, in faith, make you from Wittenberg?</LINE>
<LINE>Did you not speak to it?</LINE>
<LINE>Arm'd, say you?</LINE>
<LINE>From top to toe?</LINE>
<LINE>Then saw you not his face?</LINE>
<LINE>Hold off your hands.</LINE>
<LINE>How say you, then; would heart of man once think it?</LINE>
<LINE>But you'll be secret?</LINE>
<LINE>There's ne'er a villain dwelling in all Denmark</LINE>
<LINE>But he's an arrant knave.</LINE>
<LINE>Nay, but swear't.</LINE>
<LINE>Upon my sword.</LINE>
<LINE>Indeed, upon my sword, indeed.</LINE>

您看到了什么不同,以及您使用的是什么XQuery实现?