I thought that these two xquery expressions were equivalent:
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
The difference is the predicate which is first used in the return, and after in the for. Why the output is not the same ?
( https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml )
EDIT:: I use BASEX 9.0.1.
They look the same to me.
For the first query Saxon gives
<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>
For the second query Saxon gives:
<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>
What differences are you seeing, and what XQuery implementation are you using?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.