Harold and the Purple Crayon
%%%
%%%
%%%
%%%
%%%
%%%3618
%%%{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 CrayonCrockettJohnson
%%%{$b}{$c}
%%% {"abc"}
%%%abc
%%% abc
%%% z {"abc"}
%%% z abc
%%% {"abc"}
%%% abc
%%%{" "}
%%%
%%%{7}{"8"}
%%%47
%%%
%%%
%%%(: This is an XQuery comment :)
%%%
%%%123 Roosevelt Ave. Flushing, NY 11368
]]>
%%%element book {
attribute isbn {"isbn-0060229357" },
element title { "Harold and the Purple Crayon"},
element author {
element first { "Crockett" },
element last {"Johnson" }
}
}
%%%element {fn:node-name($e)}
{$e/@*, 2 * fn:data($e)}
%%%
Adresseindirizzo
%%%
element
{fn:data($dict/entry[word=name($e)]/variant[lang="Italian"])}
{$e/@*, $e/*}
%%%attribute size {4 + 3}
%%%attribute
{ if ($sex = "M") then "husband" else "wife" }
{ Hello, 1 to 3, Goodbye }
%%%document
{
{fn:doc("bib.xml")//book/author}
}
%%%text {"Hello"}
%%%let $homebase := "Houston"
return comment {fn:concat($homebase, ", we have a problem.")}
%%%for $d in fn:doc("depts.xml")//deptno
let $e := fn:doc("emps.xml")//emp[deptno = $d]
where fn:count($e) >= 10
order by fn:avg($e/salary) descending
return
{
$d,
{fn:count($e)},
{fn:avg($e/salary)}
}
%%%let $s := (, , )
return {$s}
%%%(,
, )
%%%for $s in (, , )
return {$s}
%%%for $x in $w
let $y := f($x)
for $z in g($x, $y)
return h($x, $y, $z)
%%%let $salary as xs:decimal := "cat"
return $salary * 2
%%%fn:avg(for $x at $i in $inputvalues
where $i mod 100 = 0
return $x)
%%%for $e in $employees order by $e/salary return $e/name
%%%for $b in $books//book[price < 100]
order by $b/title
return $b
%%%for $b in $books//book
stable order by $b/title collation "eng-us",
$b/price descending empty least
return $b
%%%
{
for $a in fn:distinct-values($books)//author
order by $a
return
{ $a/text() }
{
for $b in $books//book[author = $a]
order by $b/title
return $b/title
}
}
%%%fn:unordered(
for $p in fn:doc("parts.xml")//part[color = "Red"],
$s in fn: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")
%%%17 cast as apple
%%%$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
%%%{ //foo:bing }
%%%declare namespace xx = "http://example.org";
let $i := Lentils
return $i/xx:bing
%%% Lentils
%%%Content goes here.
%%%declare function local:summary($emps as element(employee)*)
as element(dept)*
{
for $d in fn:distinct-values($emps/deptno)
let $e := $emps[deptno = $d]
return
{$d} {fn:count($e)} {fn:sum($e/salary)}
};
local:summary(fn:doc("acme_corp.xml")//employee[location = "Denver"])
%%%declare function local:depth($e as node()) as xs:integer
{
(: A node with no children has depth 1 :)
(: Otherwise, add 1 to max depth of children :)
if (fn:empty($e/*)) then 1
else fn:max(for $c in $e/* return local:depth($c)) + 1
};
local:depth(fn:doc("partlist.xml"))
%%%
{
for $i in fn:doc("catalog.xml")//item,
$p in fn:doc("parts.xml")//part[partno = $i/partno],
$s in fn:doc("suppliers.xml")//supplier[suppno = $i/suppno]
order by $p/description, $s/suppname
return
{
$p/description,
$s/suppname,
$i/price
}
}
%%%for $s in fn:doc("suppliers.xml")//supplier
order by $s/suppname
return
{
$s/suppname,
for $i in fn:doc("catalog.xml")//item
[suppno = $s/suppno],
$p in fn:doc("parts.xml")//part
[partno = $i/pno]
order by $p/description
return $p/description
}
%%%
{
for $s in fn:doc("suppliers.xml")//supplier
order by $s/suppname
return
{
$s/suppname,
for $i in fn:doc("catalog.xml")//item
[suppno = $s/suppno],
$p in fn:doc("parts.xml")//part
[partno = $i/partno]
order by $p/description
return
{
$p/description,
$i/price
}
}
,
(: parts that have no supplier :)
{ for $p in fn:doc("parts.xml")//part
where fn:empty(fn:doc("catalog.xml")//item
[partno = $p/partno] )
order by $p/description
return $p/description
}
}
%%%for $pn in fn:distinct-values(fn:doc("catalog.xml")//partno)
let $i := fn:doc("catalog.xml")//item[partno = $pn]
where fn:count($i) >= 3
order by $pn
return
{$p} {fn:avg($i/price)}
%%%fn:avg($i/price)
%%%for $s in fn:distinct-values(fn:doc("census.xml")//state),
$j in fn:distinct-values(fn:doc("census.xml")//job)
let $p := fn:doc("census.xml")//person[state = $s and job = $j]
order by $s, $j
return
if (fn:exists($p)) then
{$s} {$j} {fn:avg($p/income)}
else ()
%%%NebraskaDeep Sea Fisherman
%%%let $proc := //procedure[1]
for $i in $proc//action
where $i >> ($proc//incision)[1]
and $i << ($proc//incision)[2]
return $i
%%%let $proc := //procedure[1]
for $i in $proc//instrument
where local:precedes(($proc//incision)[1], $i)
and local:precedes($i, ($proc//incision)[2])
return $i
%%%for $proc in //procedure
where some $i in $proc//incision satisfies
fn:empty($proc//anesthesia[. << $i])
return $proc
%%%let $intro := //h2[text()="Introduction"],
$next-h := //(h1|h2)[. >> $intro][1]
return
{
$intro,
if (fn:empty($next-h))
then //node()[. >> $intro]
else //node()[. >> $intro and . << $next-h]
}
%%%local:sections-and-titles(fn:doc("cookbook.xml"))
%%%local:swizzle(fn:doc("plans.xml"))
%%%for $p in fn:distinct-values(//product),
$s in fn:distinct-values(//size),
$c in fn:distinct-values(//color)
order by $p, $s, $c
return
if (fn:exists(//order[product eq $p
and size eq $s and color eq $c]))
then
else ()
%%%