<s>
XQuery	B-Language
(	O
XML	B-Protocol
Query	B-Language
)	O
is	O
a	O
query	B-Language
and	O
functional	B-Language
programming	I-Language
language	I-Language
that	O
queries	O
and	O
transforms	O
collections	O
of	O
structured	O
and	O
unstructured	B-Application
data	I-Application
,	O
usually	O
in	O
the	O
form	O
of	O
XML	B-Protocol
,	O
text	O
and	O
with	O
vendor-specific	O
extensions	O
for	O
other	O
data	O
formats	O
(	O
JSON	B-General_Concept
,	O
binary	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
The	O
language	O
is	O
developed	O
by	O
the	O
XML	B-Protocol
Query	B-Language
working	O
group	O
of	O
the	O
W3C	O
.	O
</s>
<s>
The	O
work	O
is	O
closely	O
coordinated	O
with	O
the	O
development	O
of	O
XSLT	B-Application
by	O
the	O
XSL	O
Working	O
Group	O
;	O
the	O
two	O
groups	O
share	O
responsibility	O
for	O
XPath	B-Language
,	O
which	O
is	O
a	O
subset	O
of	O
XQuery	B-Language
.	O
</s>
<s>
XQuery	B-Language
1.0	O
became	O
a	O
W3C	O
Recommendation	O
on	O
January	O
23	O
,	O
2007	O
.	O
</s>
<s>
XQuery	B-Language
3.0	O
became	O
a	O
W3C	O
Recommendation	O
on	O
April	O
8	O
,	O
2014	O
.	O
</s>
<s>
XQuery	B-Language
3.1	O
became	O
a	O
W3C	O
Recommendation	O
on	O
March	O
21	O
,	O
2017	O
.	O
</s>
<s>
XQuery	B-Language
is	O
a	O
functional	B-Language
,	O
side	O
effect-free	O
,	O
expression-oriented	O
programming	O
language	O
with	O
a	O
simple	O
type	O
system	O
,	O
summed	O
up	O
by	O
Kilpeläinen	O
:	O
</s>
<s>
XQuery	B-Language
provides	O
the	O
means	O
to	O
extract	O
and	O
manipulate	O
data	O
from	O
XML	B-Protocol
documents	I-Protocol
or	O
any	O
data	O
source	O
that	O
can	O
be	O
viewed	O
as	O
XML	B-Protocol
,	O
such	O
as	O
relational	B-Application
databases	I-Application
or	O
office	O
documents	O
.	O
</s>
<s>
XQuery	B-Language
contains	O
a	O
superset	O
of	O
XPath	B-Language
expression	O
syntax	O
to	O
address	O
specific	O
parts	O
of	O
an	O
XML	B-Protocol
document	I-Protocol
.	O
</s>
<s>
It	O
supplements	O
this	O
with	O
a	O
SQL-like	O
"	O
FLWOR	B-Language
expression	O
"	O
for	O
performing	O
joins	O
.	O
</s>
<s>
A	O
FLWOR	B-Language
expression	O
is	O
constructed	O
from	O
the	O
five	O
clauses	O
after	O
which	O
it	O
is	O
named	O
:	O
FOR	O
,	O
LET	O
,	O
WHERE	O
,	O
ORDER	O
BY	O
,	O
RETURN	O
.	O
</s>
<s>
The	O
language	O
also	O
provides	O
syntax	O
allowing	O
new	O
XML	B-Protocol
documents	I-Protocol
to	O
be	O
constructed	O
.	O
</s>
<s>
Where	O
the	O
element	O
and	O
attribute	O
names	O
are	O
known	O
in	O
advance	O
,	O
an	O
XML-like	O
syntax	O
can	O
be	O
used	O
;	O
in	O
other	O
cases	O
,	O
expressions	O
referred	O
to	O
as	O
dynamic	O
node	O
constructors	O
are	O
available	O
.	O
</s>
<s>
The	O
language	O
is	O
based	O
on	O
the	O
XQuery	B-Application
and	I-Application
XPath	I-Application
Data	I-Application
Model	I-Application
(	O
XDM	B-Application
)	O
which	O
uses	O
a	O
tree-structured	O
model	O
of	O
the	O
information	O
content	O
of	O
an	O
XML	B-Protocol
document	I-Protocol
,	O
containing	O
seven	O
kinds	O
of	O
nodes	O
:	O
document	O
nodes	O
,	O
elements	O
,	O
attributes	O
,	O
text	O
nodes	O
,	O
comments	O
,	O
processing	O
instructions	O
,	O
and	O
namespaces	O
.	O
</s>
<s>
XDM	B-Application
also	O
models	O
all	O
values	O
as	O
sequences	O
(	O
a	O
singleton	O
value	O
is	O
considered	O
to	O
be	O
a	O
sequence	O
of	O
length	O
one	O
)	O
.	O
</s>
<s>
The	O
items	O
in	O
a	O
sequence	O
can	O
either	O
be	O
XML	B-Protocol
nodes	O
or	O
atomic	O
values	O
.	O
</s>
<s>
Atomic	O
values	O
may	O
be	O
integers	O
,	O
strings	O
,	O
booleans	O
,	O
and	O
so	O
on	O
:	O
the	O
full	O
list	O
of	O
types	O
is	O
based	O
on	O
the	O
primitive	O
types	O
defined	O
in	O
XML	B-Protocol
Schema	O
.	O
</s>
<s>
Features	O
for	O
updating	O
XML	B-Protocol
documents	I-Protocol
or	O
databases	O
,	O
and	O
full	B-Application
text	I-Application
search	I-Application
capability	O
,	O
are	O
not	O
part	O
of	O
the	O
core	O
language	O
,	O
but	O
are	O
defined	O
in	O
add-on	O
extension	O
standards	O
:	O
XQuery	B-Language
Update	I-Language
Facility	O
1.0	O
supports	O
update	O
feature	O
and	O
XQuery	B-Language
and	O
XPath	B-Language
Full	B-Application
Text	I-Application
1.0	O
supports	O
full	B-Application
text	I-Application
search	I-Application
in	O
XML	B-Protocol
documents	I-Protocol
.	O
</s>
<s>
XQuery	B-Language
3.0	O
adds	O
support	O
for	O
full	O
functional	B-Language
programming	I-Language
,	O
in	O
that	O
functions	O
are	O
values	O
that	O
can	O
be	O
manipulated	O
(	O
stored	O
in	O
variables	O
,	O
passed	O
to	O
higher-order	O
functions	O
,	O
and	O
dynamically	O
called	O
)	O
.	O
</s>
<s>
All	O
XQuery	B-Language
constructs	O
for	O
performing	O
computations	O
are	O
expressions	O
.	O
</s>
<s>
To	O
write	O
a	O
full	O
query	B-Language
saying	O
'	O
Hello	O
World	O
 '	O
,	O
one	O
writes	O
the	O
expression	O
:	O
</s>
<s>
This	O
style	O
is	O
common	O
in	O
functional	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
Below	O
are	O
a	O
few	O
examples	O
of	O
how	O
XQuery	B-Language
can	O
be	O
used	O
:	O
</s>
<s>
Generating	O
summary	O
reports	O
on	O
data	O
stored	O
in	O
an	O
XML	B-Protocol
database	O
.	O
</s>
<s>
Selecting	O
and	O
transforming	O
XML	B-Protocol
data	O
to	O
XHTML	O
to	O
be	O
published	O
on	O
the	O
Web	O
.	O
</s>
<s>
Splitting	O
up	O
an	O
XML	B-Protocol
document	I-Protocol
that	O
represents	O
multiple	O
transactions	O
into	O
multiple	O
XML	B-Protocol
documents	I-Protocol
.	O
</s>
<s>
Although	O
XQuery	B-Language
was	O
initially	O
conceived	O
as	O
a	O
query	B-Language
language	I-Language
for	O
large	O
collections	O
of	O
XML	B-Protocol
documents	I-Protocol
,	O
it	O
is	O
also	O
capable	O
of	O
transforming	O
individual	O
documents	O
.	O
</s>
<s>
As	O
such	O
,	O
its	O
capabilities	O
overlap	O
with	O
XSLT	B-Application
,	O
which	O
was	O
designed	O
expressly	O
to	O
allow	O
input	O
XML	B-Protocol
documents	I-Protocol
to	O
be	O
transformed	O
into	O
HTML	O
or	O
other	O
formats	O
.	O
</s>
<s>
The	O
XSLT	B-Application
2.0	I-Application
and	O
XQuery	B-Language
standards	O
were	O
developed	O
by	O
separate	O
working	O
groups	O
within	O
W3C	O
,	O
working	O
together	O
to	O
ensure	O
a	O
common	O
approach	O
where	O
appropriate	O
.	O
</s>
<s>
They	O
share	O
the	O
same	O
data	O
model	O
(	O
XDM	B-Application
)	O
,	O
type	O
system	O
,	O
and	O
function	O
library	O
,	O
and	O
both	O
include	O
XPath	B-Language
2.0	O
as	O
a	O
sublanguage	O
.	O
</s>
<s>
XSLT	B-Application
was	O
primarily	O
conceived	O
as	O
a	O
stylesheet	O
language	O
whose	O
primary	O
goal	O
was	O
to	O
render	O
XML	B-Protocol
for	O
the	O
human	O
reader	O
on	O
screen	O
,	O
on	O
the	O
web	O
(	O
as	O
web	B-Application
template	I-Application
language	I-Application
)	O
,	O
or	O
on	O
paper	O
.	O
</s>
<s>
XQuery	B-Language
was	O
primarily	O
conceived	O
as	O
a	O
database	B-Language
query	I-Language
language	I-Language
in	O
the	O
tradition	O
of	O
SQL	B-Language
.	O
</s>
<s>
Because	O
the	O
two	O
languages	O
originate	O
in	O
different	O
communities	O
,	O
XSLT	B-Application
is	O
stronger	O
in	O
its	O
handling	O
of	O
narrative	O
documents	O
with	O
more	O
flexible	O
structure	O
,	O
while	O
XQuery	B-Language
is	O
stronger	O
in	O
its	O
data	O
handling	O
(	O
for	O
example	O
,	O
when	O
performing	O
relational	O
joins	O
)	O
.	O
</s>
<s>
XSLT	B-Application
1.0	O
appeared	O
as	O
a	O
Recommendation	O
in	O
1999	O
,	O
whereas	O
XQuery	B-Language
1.0	O
only	O
became	O
a	O
Recommendation	O
in	O
early	O
2007	O
;	O
as	O
a	O
result	O
,	O
XSLT	B-Application
is	O
still	O
much	O
more	O
widely	O
used	O
.	O
</s>
<s>
Both	O
languages	O
have	O
similar	O
expressive	O
power	O
,	O
though	O
XSLT	B-Application
2.0	I-Application
has	O
many	O
features	O
that	O
are	O
missing	O
from	O
XQuery	B-Language
1.0	O
,	O
such	O
as	O
grouping	O
,	O
number	O
and	O
date	O
formatting	O
,	O
and	O
greater	O
control	O
over	O
XML	B-Protocol
namespaces	O
.	O
</s>
<s>
Many	O
of	O
these	O
features	O
were	O
planned	O
for	O
XQuery	B-Language
3.0	O
.	O
</s>
<s>
Any	O
comparison	O
must	O
take	O
into	O
account	O
the	O
version	O
of	O
XSLT	B-Application
.	O
</s>
<s>
XSLT	B-Application
1.0	O
and	O
XSLT	B-Application
2.0	I-Application
are	O
very	O
different	O
languages	O
.	O
</s>
<s>
XSLT	B-Application
2.0	I-Application
,	O
in	O
particular	O
,	O
has	O
been	O
heavily	O
influenced	O
by	O
XQuery	B-Language
in	O
its	O
move	O
to	O
strong	O
typing	O
and	O
schema-awareness	O
.	O
</s>
<s>
Usability	O
studies	O
have	O
shown	O
that	O
XQuery	B-Language
is	O
easier	O
to	O
learn	O
than	O
XSLT	B-Application
,	O
especially	O
for	O
users	O
with	O
previous	O
experience	O
of	O
database	O
languages	O
such	O
as	O
SQL	B-Language
.	O
</s>
<s>
This	O
can	O
be	O
attributed	O
to	O
the	O
fact	O
that	O
XQuery	B-Language
is	O
a	O
smaller	O
language	O
with	O
fewer	O
concepts	O
to	O
learn	O
,	O
and	O
to	O
the	O
fact	O
that	O
programs	O
are	O
more	O
concise	O
.	O
</s>
<s>
It	O
is	O
also	O
true	O
that	O
XQuery	B-Language
is	O
more	O
orthogonal	O
,	O
in	O
that	O
any	O
expression	O
can	O
be	O
used	O
in	O
any	O
syntactic	O
context	O
.	O
</s>
<s>
By	O
contrast	O
,	O
XSLT	B-Application
is	O
a	O
two-language	O
system	O
in	O
which	O
XPath	B-Language
expressions	O
can	O
be	O
nested	O
in	O
XSLT	B-Application
instructions	O
but	O
not	O
vice	O
versa	O
.	O
</s>
<s>
in	O
XSLT	B-Application
by	O
use	O
of	O
a	O
coding	O
pattern	O
that	O
involves	O
an	O
identity	O
template	O
that	O
copies	O
all	O
nodes	O
unchanged	O
,	O
modified	O
by	O
specific	O
templates	O
that	O
modify	O
selected	O
nodes	O
.	O
</s>
<s>
XQuery	B-Language
has	O
no	O
equivalent	O
to	O
this	O
coding	O
pattern	O
,	O
though	O
in	O
future	O
versions	O
it	O
will	O
be	O
possible	O
to	O
tackle	O
such	O
problems	O
using	O
the	O
update	O
facilities	O
in	O
the	O
language	O
that	O
are	O
under	O
development	O
.	O
</s>
<s>
XQuery	B-Language
1.0	O
lacked	O
any	O
kind	O
of	O
mechanism	O
for	O
dynamic	O
binding	O
or	O
polymorphism	O
;	O
this	O
has	O
been	O
remedied	O
with	O
the	O
introduction	O
of	O
functions	O
as	O
first-class	O
values	O
in	O
XQuery	B-Language
3.0	O
.	O
</s>
<s>
XSLT	B-Application
offers	O
two	O
complementary	O
mechanisms	O
in	O
this	O
area	O
:	O
the	O
dynamic	O
matching	O
of	O
template	O
rules	O
,	O
and	O
the	O
ability	O
to	O
override	O
rules	O
using	O
xsl:import	O
,	O
that	O
make	O
it	O
possible	O
to	O
write	O
applications	O
with	O
multiple	O
customization	O
layers	O
.	O
</s>
<s>
The	O
absence	O
of	O
these	O
facilities	O
from	O
XQuery	B-Language
1.0	O
was	O
a	O
deliberate	O
design	O
decision	O
:	O
it	O
has	O
the	O
consequence	O
that	O
XQuery	B-Language
is	O
very	O
amenable	O
to	O
static	O
analysis	O
,	O
which	O
is	O
essential	O
to	O
achieve	O
the	O
level	O
of	O
optimization	O
needed	O
in	O
database	B-Language
query	I-Language
languages	I-Language
.	O
</s>
<s>
This	O
also	O
makes	O
it	O
easier	O
to	O
detect	O
errors	O
in	O
XQuery	B-Language
code	O
at	O
compile	O
time	O
.	O
</s>
<s>
The	O
fact	O
that	O
XSLT	B-Application
2.0	I-Application
uses	O
XML	B-Protocol
syntax	O
makes	O
it	O
rather	O
verbose	O
in	O
comparison	O
to	O
XQuery	B-Language
1.0	O
.	O
</s>
<s>
However	O
,	O
many	O
large	O
applications	O
take	O
advantage	O
of	O
this	O
capability	O
by	O
using	O
XSLT	B-Application
to	O
read	O
,	O
write	O
,	O
or	O
modify	O
stylesheets	O
dynamically	O
as	O
part	O
of	O
a	O
processing	O
pipeline	O
.	O
</s>
<s>
The	O
use	O
of	O
XML	B-Protocol
syntax	O
also	O
enables	O
the	O
use	O
of	O
XML-based	O
tools	O
for	O
managing	O
XSLT	B-Application
code	O
.	O
</s>
<s>
By	O
contrast	O
,	O
XQuery	B-Language
syntax	O
is	O
more	O
suitable	O
for	O
embedding	O
in	O
traditional	O
programming	O
languages	O
such	O
as	O
Java	B-Language
(	O
see	O
XQuery	B-Language
API	I-Language
for	I-Language
Java	I-Language
)	O
or	O
C#	B-Application
.	O
</s>
<s>
If	O
necessary	O
,	O
XQuery	B-Language
code	O
can	O
also	O
be	O
expressed	O
in	O
an	O
XML	B-Protocol
syntax	O
called	O
XQueryX	O
.	O
</s>
<s>
The	O
XQueryX	O
representation	O
of	O
XQuery	B-Language
code	O
is	O
rather	O
verbose	O
and	O
not	O
convenient	O
for	O
humans	O
,	O
but	O
can	O
easily	O
be	O
processed	O
with	O
XML	B-Protocol
tools	O
,	O
for	O
example	O
transformed	O
with	O
XSLT	B-Application
stylesheets	O
.	O
</s>
<s>
Two	O
major	O
extensions	O
to	O
the	O
XQuery	B-Language
were	O
developed	O
by	O
the	O
W3C	O
:	O
</s>
<s>
Both	O
reached	O
Recommendation	O
status	O
as	O
extensions	O
to	O
XQuery	B-Language
1.0	O
,	O
but	O
work	O
on	O
taking	O
them	O
forward	O
to	O
work	O
with	O
XQuery	B-Language
3.0	O
was	O
abandoned	O
for	O
lack	O
of	O
resources	O
.	O
</s>
<s>
Work	O
on	O
XQuery	B-Language
3.0	O
was	O
published	O
as	O
a	O
Recommendation	O
on	O
8	O
April	O
2014	O
,	O
and	O
XQuery	B-Language
3.1	O
is	O
a	O
Recommendation	O
as	O
at	O
February	O
2017	O
.	O
</s>
<s>
A	O
scripting	O
(	O
procedural	O
)	O
extension	O
for	O
XQuery	B-Language
was	O
designed	O
,	O
but	O
never	O
completed	O
.	O
</s>
<s>
The	O
EXPath	O
Community	O
Group	O
develops	O
extensions	O
to	O
XQuery	B-Language
and	O
other	O
related	O
standards	O
(	O
XPath	B-Language
,	O
XSLT	B-Application
,	O
XProc	B-Language
,	O
and	O
XForms	B-Application
)	O
.	O
</s>
<s>
JSONiq	B-General_Concept
is	O
an	O
extension	O
of	O
XQuery	B-Language
that	O
adds	O
support	O
to	O
extract	O
and	O
transform	O
data	O
from	O
JSON	B-General_Concept
documents	O
.	O
</s>
<s>
JSONiq	B-General_Concept
is	O
a	O
superset	O
of	O
XQuery	B-Language
3.0	O
.	O
</s>
<s>
The	O
EXQuery	O
project	O
develops	O
standards	O
around	O
creating	O
portable	O
XQuery	B-Language
applications	O
.	O
</s>
