[xquery-talk] position() and last()

Michael Rys mrys at microsoft.com
Tue Aug 31 22:02:44 PDT 2004


Let me clarify: XQuery's FOR does not set the context item (obviously,
the XPath expressions do).

Best regards
Michael

> -----Original Message-----
> From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On
Behalf
> Of Michael Rys
> Sent: Tuesday, August 31, 2004 8:38 PM
> To: R. Mark Volkmann; talk at xquery.com
> Subject: RE: [xquery-talk] position() and last()
> 
> XQuery does not set the context item.
> 
> Position() and last() make the most sense in the context of XPath
> expressions.
> 
> You would need to write something like:
> 
> let $last := count($items)
> return
>   for $i at $position in $items
>   return
>     ($i, if($position = $last) then () else ",")
> 
> 
> HTH
> Michael
> 
> > -----Original Message-----
> > From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On
> Behalf
> > Of R. Mark Volkmann
> > Sent: Tuesday, August 31, 2004 8:15 PM
> > To: talk at xquery.com
> > Subject: [xquery-talk] position() and last()
> >
> > I know how to use these functions in XSLT, but I haven't figured out
> how
> > to
> > use them in XQuery.
> > For example, suppose I want to put a comma between items, but not
> after
> > the
> > last one.
> > I could do something like this.
> >
> > for $i in $items
> > return (
> >   $i,
> >   if (position() = last()) then () else ","
> > )
> >
> > This doesn't work. What am I doing wrong?
> >
> >
> > _______________________________________________
> > talk at xquery.com
> > http://xquery.com/mailman/listinfo/talk
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk



More information about the talk mailing list