(: parse tests :) E1/E2 ;E1[E2] ;E2 ;E1 ;E2 ;E2 ;E1 ;E2 ;. ;E1/E2 ;E1[E2] ;E1 ;E2 ;fn:position() ;E1/E2 ;E1[E2] ;E2 ;E1 ;last() ;E1/E2 ;E1[E2] ;E2 ;E1 ;5 + 1.2 ;($x div $y) + xs:decimal($z) ;fn:error(fn:concat("Unexpected value ", fn:string($v))) ;$N[@x castable as xs:date] [xs:date(@x) gt xs:date("2000-01-01")] ;$N[if (@x castable as xs:date) then xs:date(@x) gt xs:date("2000-01-01") else false()] ;"12.5" ;12 ;12.5 ;125E2 ;xs:integer("12") ;xs:date("2001-08-25") ;9 cast as hatsize ;(2 + 4) * 5 ;(2 + 4) ;2 + 4 * 5 ;three-argument-function(1, 2, 3) ;two-argument-function((1, 2), 3) ;two-argument-function(1, ()) ;one-argument-function((1, 2, 3)) ;one-argument-function(( )) ;zero-argument-function( ) ;(: Houston, we have a problem :) ;E1/E2 ;E1 ;child::div1/child::para ;fn:root(self::node()) ;child::para ;attribute::abc:href ;child::* ;attribute::* ;child::chapter[2] ;descendant::toy[attribute::color = "red"] ;child::employee[secretary] ;(1 to 100)[. mod 5 eq 0] ;child::para ;child::* ;child::text() ;child::node() ;attribute::name ;attribute::* ;descendant::para ;descendant-or-self::para ;self::para ;child::chapter/descendant::para ;child::*/child::para ;/ ;/descendant::para ;/descendant::list/child::member ;child::para[fn:position() = 1] ;child::para[fn:position() = fn:last()] ;child::para[fn:position() = fn:last()-1] ;child::para[fn:position() > 1] ;/descendant::figure[fn:position() = 42] ;/child::doc/child::chapter[fn:position() = 5]/child::section[fn:position() = 2] ;child::para[attribute::type="warning"] ;child::para[attribute::type='warning'][fn:position() = 5] ;child::para[fn:position() = 5][attribute::type="warning"] ;child::chapter[child::title='Introduction'] ;child::chapter[child::title] ;child::*[self::chapter or self::appendix] ;child::*[self::chapter or self::appendix][fn:position() = fn:last()] ;section/para ;child::section/child::para ;para[@type="warning"] ;child::para[attribute::type="warning"] ;//para ;/descendant-or-self::node()/child::para ;//para ;div1//para ;div1/descendant-or-self::node()/child::para ;//para[1] ;/descendant::para[1] ;. ;.//para ;.. ;parent::node() ;../title ;parent::node()/child::title ;* ;text() ;@name ;@* ;para[1] ;para[fn:last()] ;*/para ;/doc/chapter[5]/section[2] ;chapter//para ;//para ;//list/member ;. ;.//para ;.. ;../@lang ;para[@type="warning"] ;para[@type="warning"][5] ;para[5][@type="warning"] ;chapter[title="Introduction"] ;chapter[title] ;employee[@secretary and @assistant] ;book/(chapter|appendix)/section ;book/fn:id(publisher)/name ;fn:id(book/publisher)/name ;(10, 1, 2, 3, 4) ;(10, (1, 2), (), (3, 4)) ;(salary, bonus) ;($price, $price) ;(10, 1 to 4) ;$seq1 union $seq1 ;$seq2 union $seq3 ;$seq1 intersect $seq1 ;$seq2 intersect $seq3 ;$seq1 except $seq2 ;$seq2 except $seq3 ;a-b ;a - b ;-1.5 ;-1 ;-3 div 2 -3 idiv 2 ;$emp/hiredate - $emp/birthdate ;$unit-price - $unit-discount ;-($bellcost + $whistlecost) ;$book1/author eq "Kennedy" ;5 eq 5 ;hatsize(5) eq shoesize(5) ;$book1/author = "Kennedy" ;//book[isbn="1558604820"] is //book[call="QA76.9 C3845"] ;5 is 5 ;//purchase[parcel="28-451"] << //sale[parcel="33-870"] ;1 eq 1 and 2 eq 2 ;1 eq 1 or 2 eq 3 ;1 eq 2 and 3 idiv 0 = 1 ;1 eq 1 or 3 idiv 0 = 1 ;1 eq 1 and 3 idiv 0 = 1 ; Harold and the Purple Crayon Crockett Johnson ;

Here is a query.

$i//title

Here is the result of the query.

{ $i//title }
;

Here is a query.

$i//title

Here is the result of the query.

Harold and the Purple Crayon
; ; ; ; ; 3 6 18 ;{1} ;{1, 2, 3} ;{1}{2}{3} ;{1, "2", "3"} ;I saw 8 cats. ;I saw {5 + 3} cats. ;I saw {5 + 3} cats. ; Harold and the Purple Crayon Crockett Johnson ; {$b} {$c} ; {"abc"} ;abc ;  abc   ; z {"abc"} ; z abc ; {"abc"} ; abc ;{" "} ;   ;element book { attribute isbn { "isbn-0060229357" }, element title { "Harold and the Purple Crayon" }, element author { element first { "Crockett" }, element last { "Johnson" } } } ;element {node-name($e)} {$e/@*, 2 * data($e)} ; Adresse indirizzo ; element {$dict/entry[word=name($e)]/variant[lang="Italian"]} {$e/node()} ;attribute size {4 + 3} ;document { doc("bib.xml")//book/author } ; ; ;123 Roosevelt Ave. Flushing, NY 11368 ]]> ;(: This is an XQuery comment :) ; ;for $d in doc("depts.xml")//deptno let $e := doc("emps.xml")//emp[deptno = $d] where count($e) >= 10 order by avg($e/salary) descending return { $d, {count($e)}, {avg($e/salary)} } ;let $s := (, , ) return {$s} ;(, , ) ;for $s in (, , ) return {$s} ;for $x in input() let $y := f($x) for $z in g($x, $y) return h($x, $y, $z) ;let $salary as xs:decimal := "cat" return $salary * 2 ;avg(for $x at $i in input() where $i mod 100 = 0 return $x) ;for $e in input() order by $e/salary return $e/name ;for $b in input()//book[price < 100] order by $b/title return $b ;for $b in input()//book stable order by $b/title collation "eng-us", $b/price descending empty least return $b ; { for $a in distinct-values(input()//author) order by $a return { $a/text() } { for $b in input()//book[author = $a] order by $b/title return $b/title } } ;unordered( for $p in doc("parts.xml")//part[color = "Red"], $s in doc("suppliers.xml")//supplier where $p/suppno = $s/suppno return { $p/partno, $s/suppno } ) ;if ($widget1/unit-cost < $widget2/unit-cost) then $widget1 else $widget2 ;if ($part/@discounted) then $part/wholesale else $part/retail ;every $part in //part satisfies $part/@discounted ;some $emp in //employee satisfies ($emp/bonus > 0.25 * $emp/salary) ;some $x in (1, 2, 3), $y in (2, 3, 4) satisfies $x + $y = 4 ;every $x in (1, 2, 3), $y in (2, 3, 4) satisfies $x + $y = 4 ;some $x in (1, 2, "cat") satisfies $x * 2 = 4 ;every $x in (1, 2, "cat") satisfies $x * 2 = 4 ;some $x as xs:integer in (1, 2, "cat") satisfies $x * 2 = 4 ;5 instance of xs:integer ;{5} instance of xs:integer ;. instance of element() ;typeswitch($customer/billing-address) case $a as element(*, USAddress) return $a/state case $a as element(*, CanadaAddress) return $a/province case $a as element(*, JapanAddress) return $a/prefecture default return "unknown" ;if ($x castable as hatsize) then $x cast as hatsize else if ($x castable as IQ) then $x cast as IQ else $x cast as xs:string ;xs:date("2000-01-01") ;xs:decimal($floatvalue * 0.2E-5) ;xdt:dayTimeDuration("P21D") ;expr1 treat as type1 ;$myaddress treat as element(*, USAddress) ;validate context po:purchaseOrder/items/item {$y} ;validate context type(po:USAddress) {$z} ;declare namespace foo = "http://example.org" Lentils ;(: Error: multiple declarations of namespace 'xx' :) declare namespace xx = "http://example.org/foo" declare namespace xx = "http://example.org/bar" ;{ //foo:bing } ;declare namespace xx = "http://example.org" let $i := Lentils return $i/xx:bing ; Lentils ;define function summary($emps as element(employee)*) as element(dept)* { for $d in distinct-values($emps/deptno) let $e := $emps[deptno = $d] return {$d} {count($e)} {sum($e/salary)} } summary(doc("acme_corp.xml")//employee[location = "Denver"]) ;define function depth($e as node()) as xs:integer { (: A node with no children has depth 1 :) (: Otherwise, add 1 to max depth of children :) if (empty($e/*)) then 1 else max(for $c in $e/* return depth($c)) + 1 } depth(doc("partlist.xml")) ; { for $i in doc("catalog.xml")//item, $p in doc("parts.xml")//part[partno = $i/partno], $s in doc("suppliers.xml")//supplier[suppno = $i/suppno] order by $p/description, $s/suppname return { $p/description, $s/suppname, $i/price } } ;for $s in doc("suppliers.xml")//supplier order by $s/suppname return { $s/suppname, for $i in doc("catalog.xml")//item [suppno = $s/suppno], $p in doc("parts.xml")//part [partno = $i/pno] order by $p/description return $p/description } ; { for $s in doc("suppliers.xml")//supplier order by $s/suppname return { $s/suppname, for $i in doc("catalog.xml")//item [suppno = $s/suppno], $p in doc("parts.xml")//part [partno = $i/partno] order by $p/description return { $p/description, $i/price } } , (: parts that have no supplier :) { for $p in doc("parts.xml")//part where empty(doc("catalog.xml")//item [partno = $p/partno] ) order by $p/description return $p/description } } ;for $pn in distinct-values(doc("catalog.xml")//partno) let $i := doc("catalog.xml")//item[partno = $pn] where count($i) >= 3 order by $pn return {$p} {avg($i/price)} ;avg($i/price) ;for $s in distinct-values(doc("census.xml")//state), $j in distinct-values(doc("census.xml")//job) let $p := doc("census.xml")//person[state = $s and job = $j] order by $s, $j return if (exists($p)) then {$s} {$j} {avg($p/income)} else () ; Nebraska Deep Sea Fisherman ;let $proc := input()//procedure[1] for $i in $proc//action where $i >> ($proc//incision)[1] and $i << ($proc//incision)[2] return $i ;let $proc := input()//procedure[1] for $i in $proc//instrument where precedes(($proc//incision)[1], $i) and precedes($i, ($proc//incision)[2]) return $i ;for $proc in input()//procedure where some $i in $proc//incision satisfies empty($proc//anesthesia[. << $i]) return $proc ;let $intro := input()//h2[text()="Introduction"], $next-h := input()//(h1|h2)[. >> $intro][1] return
{ $intro, if (empty($next-h)) then //node()[. >> $intro] else //node()[. >> $intro and . << $next-h] }
;sections-and-titles(doc("cookbook.xml")) ;swizzle(doc("plans.xml")) ;