Variables and lifetime of variables in XQuery

In XQuery, we can define variables with LET and FOR
clauses. But it seems to me the variable definition is
not very clear, especially the lifetime of a variable.
For example, I want to increment a variable "count"
through a FOR loop:

LET $count : =  0
FOR $book IN  document("bib.xml")/bib/book)
LET $count : =  $count +1
RETURN 
<countOfBooks>
  {$count}
</countOfBooks>

The expected result is:
  <countOfBooks>1</countOfBooks>
  <countOfBooks>2</countOfBooks>
  <countOfBooks>3</countOfBooks>
  <countOfBooks>4</countOfBooks>
  <countOfBooks>5</countOfBooks>
  <countOfBooks>6</countOfBooks>
  <countOfBooks>7</countOfBooks>
  <countOfBooks>8</countOfBooks>

But the returned result is (With QuiP from
SoftwareAG):

  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>
  <countOfBooks>1</countOfBooks>


So the lifetime of variables bound by LET In a FOR
loop is the single loop.  With each new iteration, the
count will be reinitialized. Is that correct?

Fusheng Wang
Department of Computer Science
University of California, Los Angeles
Los Angeles, CA 90095


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

Received on Monday, 7 January 2002 19:04:00 UTC