[xquery-talk] position() and atomic values

Peter Coppens Peter.Coppens at datadirect.com
Tue Jul 5 18:37:45 PDT 2005

Although position() can refer to atomic items, the '/' operator can not.
So, the item(s) '/' operates on (the left hand side) has(have) to be a
node(s). That is also why the error correctly refers to '/'. The
position() call as such is not the problem.

You could write what I think you intended as 

let $myStrings := ("string1", "string2", "string3")
   for $string at $pos in $myStrings
     <string position="{$pos}">{$string}</string>

One example where position() applies to atomic values would be

("string1", "string2", "string3")[position() = 2]



> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Pierrick Brihaye
> Sent: Tuesday, July 05, 2005 11:11 PM
> To: talk at xquery.com
> Subject: [xquery-talk] position() and atomic values
> Hi,
> Given the following XQuery :
> let $myStrings := ("string1", "string2", "string3")
> return	
>    for $string in $myStrings
>    return
>      <string position="{$string/position()}">{$string}</string>
> Saxon returns :
> Error on line 5 of file:/C:/.../saxonb8-4/in.txt:
> XPTY0019: Required item type of first operand of '/' is 
> node(); supplied 
> value has item type xs:string
> Failed to compile query
> Quoted from http://www.w3.org/TR/xquery/ :
> > [Definition: The context position is the position of the 
> context item within the sequence of items currently being 
> processed.] It changes whenever the context item changes. Its 
> value is always an integer greater than zero. The context 
> position is returned by the expression fn:position(). When an 
> expression E1/E2 or E1[E2] is evaluated, the context position 
> in the inner focus for an evaluation of E2 is the position of 
> the context item in the sequence obtained by evaluating E1. 
> The position of the first item in a sequence is always 1 
> (one). The context position is always less than or equal to 
> the context size.
> and :
> > [Definition: The context item is the item currently being 
> processed. An item is either an atomic value or a node.]
> My understanding is that position() may concern nodes as well 
> as atomic 
> values. Am I wrong ?
> Cheers,
> p.b.
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk

More information about the talk mailing list