I have extracted successfully one value in one variable, and a list of values in another variable (as part of my XQuery expression).
Now, suppose the single-value variable is
x=1
and the list variable is named y with values 2,4,7,11,16
I want to extract the following values -- (2-1), (4-2), (7-4), (11-7), (16-11)
ie, first value of list variable minus single value variable, then differences between successive members of the list variable.
I tried using
for $pos in list-variable/position()
-> if clause for $pos=1 (to subtract and shown list variable- single value variable)
->else show difference b/w consecutive list variables...
but nothing is shown at all as output... What am I doing wrong here?
I. With XQuery 3.0 / Xpath 3.0, use:
This produces the wanted, correct result:
II. XQuery 1.0 solution:
again produces the same correct result:
Performance comparison:
Surprizingly, the XPath (XQuery) 3.0 query is executed almost twice faster than the XQuery 1.0 one -- when run on BaseX.