[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Finding context position when "order by" is in a FLWOR?

David Sewell dsewell at virginia.edu
Fri Sep 8 17:25:31 PDT 2006


  Finding context position when "order by" is in a
	FLWOR?
Suppose I want to number output elements in a simply query containing an
"order by". Alas,

	let $list := ( 'cat', 'dog', 'apple')
	for $word at $pos in $list
	order by $word
	return <word n="{$pos}">{$word}</word>

produces

	<word n="3">apple</word>
	<word n="1">cat</word>
	<word n="2">dog</word>

because the positional variable is bound in the "for" statement.

I can't figure out a direct way to get @n to contain the value of output
order; position() doesn't seem to help. The best approach I come up with
is to wrap the above FLWOR in another one:

	for $item at $lineNo in
	   let $list := ( 'cat', 'dog', 'apple')
	   for $word at $pos in $list
	   order by $word
	   return $word
	return <word n="{$lineNo}">{$item}</word>

which produces the desired output. Is there a better way?

-- 
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: http://x-query.com/mailman/listinfo/talk   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/



Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.