(Q13) For each book whose price is greater than the average price, return the title of the book and the amount by which the
book's price exceeds the average price.
<result>
LET $a := avg(//book/price)
FOR $b IN /book
WHERE $b/price > $a
RETURN
<expensive_book>
$b/title ,
<price_difference>
$b/price - $a
</price_difference>
</expensive_book>
</result>
XSLT equivalent to (Q13)
<result xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="avgPrice" select="sum(//book/price) div count(//book/price)"/>
<xsl:for-each select="/bib/book[price > $avgPrice]">
<expensive_book>
<xsl:copy-of select="title"/>
<price_difference>
<xsl:value-of select="price - $avgPrice"/>
</price_difference>
</expensive_book>
</xsl:for-each>
</result>
|