CS257
Chris Pollett
Sep 14, 2020
FOR $variable IN expression LET $variable:=expression WHERE filtercriterion ORDER BY sortcriterion RETURN expression
//winecellar.xml <?xml version="1.0" encoding="UTF-8"?> <winecellar> <wine winekey="1"> <name>Jacques Selosse Brut Initial</name> <year>2012</year> <type>Champagne</type> <grape percentage="100">Chardonnay</grape> <price currency="EURO">150</price> <geo> <country>France</country> <region>Champagne</region> </geo> <quantity>12</quantity> </wine> <wine winekey="2"> <name>Meneghetti White</name> <year>2010</year> <type>white wine</type> <grape percentage="80">Chardonnay</grape> <grape percentage="20">Pinot Blanc</grape> <price currency="EURO">18</price> <geo> <country>Croatia</country> <region>Istria</region> </geo> <quantity>20</quantity> </wine> </winecellar> //winereview.xml <?xml version="1.0" encoding="UTF-8"?> <winereviews> <winereview winekey="1"> <author>Chris Pollett</author> <title>Great</title> <description>This wine was great!</description> <rating>5</rating> </winereview> <winereview winekey="2"> <author>Chris Pollett</author> <title>Sucked</title> <description>This wine was horrible!</description> <rating>1</rating> </winereview> </winereviews>
let $maxyear := 2012 return doc("winecellar.xml")/winecellar/wine[year<$maxyear]This illustrates how the let clause allows one to make a local variable assignment, and how we use that assignment to return nodes with a return clause that involves an XPath.
for $wine in doc("winecellar.xml")/winecellar/wine order by $wine/year ascending return $wine
for $wine in doc("winecellar.xml")/winecellar/wine where $wine/price < 20 and $wine/price/@currency="EURO" return <cheap_wine> {$wine/name, $wine/price}</cheap_wine>
for $wine in doc("winecellar.xml")//wine for $winereview in doc("winereview.xml")//winereview where $winereview/@winekey=$wine/@winekey return <wineinfo> {$wine/name, $winereview/rating} </wineinfo>
SELECT XMLQUERY(some_xquery) FROM table_list WHERE XMLEXISTS(some_other_xquery))
Which of the following is true?
(Bart, Name, Bart Baesons) (Bart, Likes, Meneghetti White) (Meneghetti White, Tastes, Citrusy) (Meneghetti White, Pairs, Fish)
(www.kuleuven.be/Bart.Baesens, http://mywineontology.com/#term_name, "Bart Baesons")
<?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/TR/PR-rdf-syntax/" xmlns:myxmlns="http://mywineontology.com/"> <rdf:Description rdf:about="www.kuleuven.be/Bart.Baesens"> <myxmlns:name>Bart Baesens</myxmlns:name> <myxmlns:likes rdf:resource="www.wine.com/MeneghettiWhite"/> </rdf:Description> <rdf:Description rdf:about="www.wine.com/MeneghettiWhite"> <myxmlns:tastes>citrusy</myxmlns:tastes> <myxmlns:pairs rdf:resource="http://wikipedia.org/fish"/> </rdf:Description> </rdf:RDF>
Bart name "Bart Baesons".
Bart Name "Bart Baesons"; Likes "Meneghetti White".
Bart Father "Jane", "Sally".
:Surgeon rdfs:subClassOf :Staff :Surgeon rdfs:subClassOf :Physician :Kildare rdf:type :Surgeonwe can infer:
:Kildare rdf:type :Staff :Kildare rdf:type :Physician
PREFIX: mywineont: <http://mywineontology.com/> SELECT ?wine WHERE {?wine mywineont:tastes "Citrusy"}
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?email WHERE { ?person a foaf:Person . ?person foaf:name ?name . ?person foaf:mbox ?email . }