Thanks, 西湾さん, this works, but the "direct" methods works in all other XQuery engines I have tested, and every expression should be substitutable with the operation or function that outputs the same expression, as far as I know. The query optimizer probably trips up here.


On 18 Nov 2013, at 11:31, Michael Westbay <> wrote:

Petersen-san wrote:

I think calculations in positional predicates should be possible, but they raise an error (strangely, XPTY0004).

xquery version "3.0";

let $items :=

let $my-item := $items/*[3 - 1]/target/start/number()
    return $my-item

I've found that when the predicate is calculated, one must use position() to compare to the predicate.  Changing the assignment to:

let $my-item := $items/*[position()=3 - 1]/target/start/number()

should thus work.

I don't know if it's in the specification, but it's a general rule of thumb that I use.

Michael Westbay
Writer/System Administrator
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
Exist-open mailing list