/* The query computes in real time the value of a portfolio. The portfolio is described in the query using some in-lined XML ([[ .. ]]). Based on the portfolio, a URL is computed to access a W4F Web service that will return the current stock price. Then the query enriches the portfolio with the price information. Finally, the quey computes the grand total. */ FUNCTION YAHOO_FINANCE( $portfolio ) { document( CONCAT( "http://db.cis.upenn.edu/cgi-bin/YFS.pl?", JOIN("+", $portfolio/ASSET/@NAME, "NOK"), "&d=t" ) ) } LET $portfolio := [[ ]], $yahooFinance := YAHOO_FINANCE($portfolio) RETURN ( FOR $asset IN $portfolio/ASSET LET $price := $yahooFinance/Stock[ ./@Ticker = $asset/@NAME ]/LastPrice RETURN SORTBY ( ./@NAME ) ), CONCAT("$", SUM( FOR $asset IN $portfolio/ASSET LET $price := $yahooFinance/Stock[ ./@Ticker = $asset/@NAME ]/LastPrice RETURN $asset/@QTY * $price ) )