if then else

For each book in the bibliography, list the difference between the book's price and the average price, but this time indicate whether the book is more or less expensive than the average

   let $doc := doc("bib.xml")
   let $average := avg($doc//price)
   for $b in $doc/bib/book
       if ($b/price > $average) then
           { $b/title } is ${$b/price - $average} 
           more expensive than the average.
           { $b/title } is ${$average - $b/price} 
           less expensive than the average.

Previous | Next | Top | Cafe con Leche | Cafe au Lait

Copyright 2002-2005 Elliotte Rusty Harold
Last Modified November 15, 2003