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.

Jens

On 18 Nov 2013, at 11:31, Michael Westbay <westbaystars@japanesebaseball.com> 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 :=
<items>
    <item>
        <target>
            <id>uuid-538a6e13-f88b-462c-a965-f523c3e02bbf</id>
            <start>3</start>
            <offset>4</offset>
        </target>
    </item>
    <item>
        <target>
            <id>uuid-538a6e13-f88b-462c-a965-f523c3e02bbf</id>
            <start>8</start>
            <offset>15</offset>
        </target>
    </item>
</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
http://www.japanesebaseball.com/
------------------------------------------------------------------------------
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!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk_______________________________________________
Exist-open mailing list
Exist-open@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/exist-open