[xquery-talk] Re: position() and atomic values

Michael Kay mhk at mhk.me.uk
Wed Jul 6 14:57:58 PDT 2005

> Now, what about the following error :
> Error
>   XPDY0002: The context position is currently undefined
> Query processing failed: Run-time errors were reported
> returned by :
> let $myStrings := ("string1", "string2", "string3") 
> for $string in $myStrings
> order by position()
> return $string
> Well, this example is a bit silly but I try to find examples 
> where position() is
> not used in a predicate.

It's very hard to come up with plausible examples for using position()
outside a predicate in XQuery (as distinct from XSLT/XPath, where usages
like <xsl:if test="position() = last()"> are common.)

One can do things like

$table/tr/td/(if (position() lt 5) then . else <td/>) 

but it's pretty contrived.

position(), like ., plays little role in FLWOR expressions because unlike
xsl:for-each in XSLT, a "for" expression does not change the focus. Only "/"
and "[]" change the focus in XQuery.

Michael Kay

More information about the talk mailing list