Learning XQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $books := | |
<bookstore> | |
<book category="COOKING"> | |
<title lang="en">Everyday Italian</title> | |
<author>Giada De Laurentiis</author> | |
<year>2005</year> | |
<price>30.00</price> | |
</book> | |
... other books from W3Schools example ... | |
</bookstore> | |
return | |
xdmp:document-insert("books.xml", $books) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
("a", "b", "c, "d") | |
("a", (), "b", "c", "d") | |
("a", ( "b", "c"), "d") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 (: a sequence of 1 xs:integer literal :) | |
"Hello World" (: a sequence of 1 xs:string literal :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: returns a sequence of perfect squares :) | |
for $i in (1 to 10) | |
return | |
$i * $i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: IF statement inside FLWOR statements :) | |
for $x in (1 to 10) | |
return | |
if($x ne 2) then | |
$x * $x | |
else | |
"the number of years I have loved XQuery" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: Some of the locations in FWLOR that could be considered sequences :) | |
for $x in SEQUENCE | |
let $y := SEQUENCE | |
return | |
SEQUENCE | |
(: Sequences inside IF/ELSEs :) | |
if( BooleanExpression ) then | |
SEQUENCE | |
else | |
SEQUENCE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: Two statements expressed as a sequence :) | |
( | |
for $book in fn:doc("books.xml")//book | |
return | |
fn:concat( $book/title, ": ", $book/author), | |
if(fn:exists(//book[fn:contains(./title, "SQL")]) then | |
"Yuck" | |
else | |
"Hooray!" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment