Professional Documents
Culture Documents
XQuery
XQuery
SITE SEARCH
HOME Introduction to XQuery
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR The best way to explain XQuery is to say that XQuery is to XML what SQL is to
XQuery HTML database tables. Web based charting
XQuery Terms for ASP.NET
XQuery Syntax XQuery is designed to query XML data - not just XML files, but anything that can
WEB HOSTING
appear as XML, including databases.
XQuery Advanced $15 Domain Name
XQuery Add Registration
XQuery Select Save $20 / year!
XQuery Functions
UK Domain Names
XQuery Summary What You Should Already Know
UK Web Hosting
XQuery Reference Alojamiento Web
Before you continue you should have a basic understanding of the following:
XQuery Reference Buy UK Domain Names
Register Domain Names
Selected Reading ● HTML / XHTML
Web Statistics ● XML / XML Namespaces Cheap Domain Names
Web Glossary ● XPath Cheap Web Hosting
Web Hosting Best Web Hosting
Web Quality If you want to study these subjects first, find the tutorials on our Home page.
Bulk Domain Names
W3Schools Forum UK Web Hosting
Helping W3Schools PHP MySQL Hosting
What is XQuery? Web Hosting UK
Top 10 Web Hosting
● XQuery is the language for querying XML data Web Hosting Providers
● XQuery for XML is like SQL for databases
● XQuery is built on XPath expressions ASP.NET Web Hosting
● XQuery is supported by all the major database engines (IBM, Oracle, Microsoft, etc.) 3 Months Free!
● XQuery is a W3C Recommendation
Programming Forums
Windows Web Hosting
WEB BUILDING
XML Website Tools
XQuery is About Querying XML
Website Templates
Flash Templates
XQuery is a language for finding and extracting elements and attributes from XML documents.
Website Builder
Internet Business
Here is an example of a question that XQuery could solve:
Opportunity
Custom Programming
"Select all CD records with a price less than $10 from the CD collection stored in the XML
document called cd_catalog.xml" BEST Flash Templates
Web Design Forum
Programming Forum
http://www.w3schools.com/xquery/xquery_intro.asp (1 of 3) [3/14/2007 1:10:11 PM]
XQuery Introduction
XQuery is compatible with several W3C standards, such as XML, Namespaces, XSLT, XPath,
and XML Schema.
To read more about the XQuery activity at W3C, please read our W3C Tutorial.
Your browser does not support inline frames or is currently configured not to display inline
frames.
If you want to be a Web Master, you will have to host your web site with an ISP (Internet
Service Provider).
MaximumASP offers seven different configurations of dedicated servers to meet your Windows
and .NET hosting needs. Hosted on our multi-tiered Enterprise Class network, these servers
provide the performance, security and reliability you need to host your high end web sites and
applications.
Visit MaximumASP
Your browser does not support inline frames or is currently configured not to display inline frames.
SITE SEARCH
HOME XQuery Example
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR Let's try to learn some basic XQuery syntax by looking at an example.
XQuery HTML Web based charting
XQuery Terms for ASP.NET
XQuery Syntax
WEB HOSTING
XQuery Advanced The XML Example Document $15 Domain Name
XQuery Add Registration
XQuery Select We will use the following XML document in the examples below. Save $20 / year!
XQuery Functions
UK Domain Names
XQuery Summary
"books.xml": UK Web Hosting
XQuery Reference Alojamiento Web
XQuery Reference <?xml version="1.0" encoding="ISO-8859-1"?> Buy UK Domain Names
Register Domain Names
Selected Reading
Web Statistics <bookstore> Cheap Domain Names
Web Glossary Cheap Web Hosting
Web Hosting <book category="COOKING"> Best Web Hosting
Web Quality <title lang="en">Everyday Italian</title>
Bulk Domain Names
<author>Giada De Laurentiis</author>
W3Schools Forum UK Web Hosting
<year>2005</year>
Helping W3Schools
<price>30.00</price> PHP MySQL Hosting
</book>
Web Hosting UK
Top 10 Web Hosting
<book category="CHILDREN">
<title lang="en">Harry Potter</title> Web Hosting Providers
<author>J K. Rowling</author> ASP.NET Web Hosting
<year>2005</year> 3 Months Free!
<price>29.99</price>
</book> Programming Forums
Windows Web Hosting
Functions
doc("books.xml")
Path Expressions
The following path expression is used to select all the title elements in the "books.xml" file:
doc("books.xml")/bookstore/book/title
(/bookstore selects the bookstore element, /book selects all the book elements under the
bookstore element, and /title selects all the title elements under each book element)
Predicates
XQuery uses predicates to limit the extracted data from XML documents.
The following predicate is used to select all the book elements under the bookstore element
that have a price element with a value that is less than 30:
doc("books.xml")/bookstore/book[price<30]
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Your browser does not support inline frames or is currently configured not to display inline
frames.
If you want to be a Web Master, you will have to host your web site with an ISP (Internet
Service Provider).
MaximumASP offers seven different configurations of dedicated servers to meet your Windows
and .NET hosting needs. Hosted on our multi-tiered Enterprise Class network, these servers
provide the performance, security and reliability you need to host your high end web sites and
applications.
Visit MaximumASP
W3Schools provides material for training only. We do not warrant the correctness of its
contents. The risk from using it lies entirely with the user. While using this site, you agree to
have read and accepted our terms of use and privacy policy.
SITE SEARCH
HOME XQuery FLWOR Expressions
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR
The XML Example Document
XQuery HTML Domain Name
XQuery Terms Registration & More!
We will use the "books.xml" document in the examples below (same XML file as in the previous
XQuery Syntax
chapter). WEB HOSTING
XQuery Advanced $15 Domain Name
XQuery Add View the "books.xml" file in your browser. Registration
XQuery Select Save $20 / year!
XQuery Functions
UK Domain Names
XQuery Summary
UK Web Hosting
XQuery Reference How to Select Nodes From "books.xml" With FLWOR Alojamiento Web
XQuery Reference Buy UK Domain Names
Look at the following path expression: Register Domain Names
Selected Reading
Web Statistics Cheap Domain Names
Web Glossary doc("books.xml")/bookstore/book[price>30]/title Cheap Web Hosting
Web Hosting Best Web Hosting
Web Quality
The expression above will select all the title elements under the book elements that are under Bulk Domain Names
W3Schools Forum the bookstore element that have a price element with a value that is higher than 30.
UK Web Hosting
Helping W3Schools PHP MySQL Hosting
The following FLWOR expression will select exactly the same as the path expression above:
Web Hosting UK
Top 10 Web Hosting
for $x in doc("books.xml")/bookstore/book
where $x/price>30 Web Hosting Providers
return $x/title
ASP.NET Web Hosting
3 Months Free!
The result will be: Programming Forums
Windows Web Hosting
<title lang="en">XQuery Kick Start</title> WEB BUILDING
<title lang="en">Learning XML</title> XML Website Tools
Website Templates
With FLWOR you can sort the result: Flash Templates
Website Builder
Internet Business
for $x in doc("books.xml")/bookstore/book
Opportunity
where $x/price>30
order by $x/title Custom Programming
return $x/title
BEST Flash Templates
Web Design Forum
FLWOR is an acronym for "For, Let, Where, Order by, Return". Programming Forum
http://www.w3schools.com/xquery/xquery_flwor.asp (1 of 3) [3/14/2007 1:10:45 PM]
XQuery FLWOR Expressions
Your browser does not support inline frames or is currently configured not to display inline
frames.
What do you want your Web site to do? Ektron CMS400.NET lets you do everything you
need to do on the Web and do everything you want to do.
Ektron CMS400.NET gives you all the features you would expect from an
enterprise CMS, but also high-demand functionality like real-time Web
site analytics, community building, blogging, personalization, and online
calendars. Ektron CMS400.NET bridges your Web site gaps.
SITE SEARCH
HOME XQuery FLWOR + HTML
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR
The XML Example Document
XQuery HTML Ecommerce
XQuery Terms Components
We will use the "books.xml" document in the examples below (same XML file as in the previous
XQuery Syntax for ASP.NET
chapters).
XQuery Advanced WEB HOSTING
XQuery Add View the "books.xml" file in your browser. $15 Domain Name
XQuery Select Registration
XQuery Functions Save $20 / year!
XQuery Summary
UK Domain Names
XQuery Reference Present the Result In an HTML List UK Web Hosting
XQuery Reference Alojamiento Web
Your browser does not support inline frames or is currently configured not to display inline
frames.
Free XML video demonstrations will help you learn XML and
become a W3C XML development master in just minutes!
W3Schools provides material for training only. We do not warrant the correctness of its
contents. The risk from using it lies entirely with the user. While using this site, you agree to
have read and accepted our terms of use and privacy policy.
SITE SEARCH
HOME XQuery Terms
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR In XQuery, there are seven kinds of nodes: element, attribute, text, namespace,
XQuery HTML processing-instruction, comment, and document (root) nodes. Domain Name
XQuery Terms Registration & More!
XQuery Syntax
WEB HOSTING
XQuery Advanced $15 Domain Name
XQuery Add XQuery Terminology Registration
XQuery Select Save $20 / year!
XQuery Functions Nodes UK Domain Names
XQuery Summary
UK Web Hosting
XQuery Reference In XQuery, there are seven kinds of nodes: element, attribute, text, namespace, processing- Alojamiento Web
XQuery Reference instruction, comment, and document (root) nodes. XML documents are treated as trees of
Buy UK Domain Names
nodes. The root of the tree is called the document node (or root node).
Register Domain Names
Selected Reading
Web Statistics Look at the following XML document: Cheap Domain Names
Web Glossary Cheap Web Hosting
Web Hosting Best Web Hosting
<?xml version="1.0" encoding="ISO-8859-1"?>
Web Quality
Bulk Domain Names
W3Schools Forum <bookstore> UK Web Hosting
Helping W3Schools PHP MySQL Hosting
<book> Web Hosting UK
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author> Top 10 Web Hosting
<year>2005</year> Web Hosting Providers
<price>29.99</price>
ASP.NET Web Hosting
</book>
3 Months Free!
Atomic values are nodes with no children or parent. FREE Trial or Demo
Web Content Manager
Example of atomic values: Forms,Web Alerts,RSS
HTML Exam
J K. Rowling SHOPPING
UK Wholesalers
"en" UK Wholesale
ONLINE DEGREE
Advance Your Career
Items with Drexel University
Bachelor's & Master's
Items are atomic values or nodes. Tech Degrees ONLINE
Relationship of Nodes
Parent
In the following example; the book element is the parent of the title, author, year, and price:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Children
In the following example; the title, author, year, and price elements are all children of the
book element:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Siblings
In the following example; the title, author, year, and price elements are all siblings:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Ancestors
In the following example; the ancestors of the title element are the book element and the
bookstore element:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Descendants
In the following example; descendants of the bookstore element are the book, title, author,
year, and price elements:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Your browser does not support inline frames or is currently configured not to display inline
frames.
Your browser does not support inline frames or is currently configured not to display inline frames.
SITE SEARCH
HOME XQuery Syntax
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR XQuery is case-sensitive and XQuery elements, attributes, and variables must be
XQuery HTML valid XML names. Active Server Pages
XQuery Terms Resource Web Site
XQuery Syntax
WEB HOSTING
XQuery Advanced $15 Domain Name
XQuery Add XQuery Basic Syntax Rules Registration
XQuery Select Save $20 / year!
XQuery Functions Some basic syntax rules: UK Domain Names
XQuery Summary
UK Web Hosting
● XQuery is case-sensitive Alojamiento Web
XQuery Reference
● XQuery elements, attributes, and variables must be valid XML names
XQuery Reference Buy UK Domain Names
● An XQuery string value can be in single or double quotes
● An XQuery variable is defined with a $ followed by a name, e.g. $bookstore Register Domain Names
Selected Reading
● XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)
Web Statistics Cheap Domain Names
Web Glossary Cheap Web Hosting
Web Hosting Best Web Hosting
Web Quality
XQuery Conditional Expressions Bulk Domain Names
W3Schools Forum UK Web Hosting
Helping W3Schools "If-Then-Else" expressions are allowed in XQuery. PHP MySQL Hosting
Web Hosting UK
Look at the following example:
Top 10 Web Hosting
Web Hosting Providers
for $x in doc("books.xml")/bookstore/book
return if ($x/@category="CHILDREN") ASP.NET Web Hosting
then <child>{data($x/title)}</child> 3 Months Free!
else <adult>{data($x/title)}</adult> Programming Forums
Windows Web Hosting
Notes on the "if-then-else" syntax: parentheses around the if expression are required. else WEB BUILDING
is required, but it can be just else (). XML Website Tools
Website Templates
The result of the example above will be: Flash Templates
Website Builder
<adult>Everyday Italian</adult> Internet Business
<child>Harry Potter</child> Opportunity
<adult>Learning XML</adult> Custom Programming
<adult>XQuery Kick Start</adult>
BEST Flash Templates
Web Design Forum
Programming Forum
http://www.w3schools.com/xquery/xquery_syntax.asp (1 of 3) [3/14/2007 1:11:15 PM]
XQuery Syntax
$bookstore//book/@q > 10
$bookstore//book/@q gt 10
Your browser does not support inline frames or is currently configured not to display inline
frames.
What do you want your Web site to do? Ektron CMS400.NET lets you do everything you
need to do on the Web and do everything you want to do.
Ektron CMS400.NET gives you all the features you would expect from an
enterprise CMS, but also high-demand functionality like real-time Web
site analytics, community building, blogging, personalization, and online
calendars. Ektron CMS400.NET bridges your Web site gaps.
SITE SEARCH
HOME XQuery Adding Elements and Attributes
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR
The XML Example Document
XQuery HTML Ecommerce
XQuery Terms Components
We will use the "books.xml" document in the examples below (same XML file as in the previous
XQuery Syntax for ASP.NET
chapters).
XQuery Advanced WEB HOSTING
XQuery Add View the "books.xml" file in your browser. $15 Domain Name
XQuery Select Registration
XQuery Functions Save $20 / year!
XQuery Summary
UK Domain Names
XQuery Reference Adding Elements and Attributes to the Result UK Web Hosting
XQuery Reference Alojamiento Web
As we have seen in a previous chapter, we may include elements and attributes from the input Buy UK Domain Names
Selected Reading
document ("books.xml) in the result: Register Domain Names
Web Statistics
Web Glossary Cheap Domain Names
Web Hosting for $x in doc("books.xml")/bookstore/book/title Cheap Web Hosting
Web Quality order by $x
Best Web Hosting
return $x
W3Schools Forum Bulk Domain Names
UK Web Hosting
Helping W3Schools The XQuery expression above will include both the title element and the lang attribute in the
result, like this: PHP MySQL Hosting
Web Hosting UK
<title lang="en">Everyday Italian</title> Top 10 Web Hosting
<title lang="en">Harry Potter</title>
Web Hosting Providers
<title lang="en">Learning XML</title>
<title lang="en">XQuery Kick Start</title> ASP.NET Web Hosting
3 Months Free!
The XQuery expression above returns the title elements the exact same way as they are Programming Forums
described in the input document. Windows Web Hosting
WEB BUILDING
We now want to add our own elements and attributes to the result! XML Website Tools
Website Templates
Add HTML Elements and Text Flash Templates
Website Builder
Now, we want to add some HTML elements to the result. We will put the result in an HTML list Internet Business
- together with some text: Opportunity
Custom Programming
BEST Flash Templates
<html>
<body>
<h1>Bookstore</h1>
<ul>
<li>Everyday Italian. Category: COOKING</li>
<li>Harry Potter. Category: CHILDREN</li>
<li>Learning XML. Category: WEB</li>
<li>XQuery Kick Start. Category: WEB</li>
</ul>
</body>
</html>
Next, we want to use the category attribute as a class attribute in the HTML list:
<html>
<body>
<h1>Bookstore</h1>
<ul>
{
for $x in doc("books.xml")/bookstore/book
order by $x/title
return <li class="{data($x/@category)}">{data($x/title)}</li>
}
</ul>
</body>
<html>
<body>
<h1>Bookstore</h1>
<ul>
<li class="COOKING">Everyday Italian</li>
<li class="CHILDREN">Harry Potter</li>
<li class="WEB">Learning XML</li>
<li class="WEB">XQuery Kick Start</li>
</ul>
</body>
</html>
Your browser does not support inline frames or is currently configured not to display inline
frames.
NEW! Altova MissionKit 2007– Save ½ off Intelligent tools for XML
developers & software architects
Your browser does not support inline frames or is currently configured not to display inline frames.
SITE SEARCH
HOME XQuery Selecting and Filtering
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR
The XML Example Document
XQuery HTML Ecommerce
XQuery Terms Components
We will use the "books.xml" document in the examples below (same XML file as in the previous
XQuery Syntax for ASP.NET
chapters).
XQuery Advanced WEB HOSTING
XQuery Add View the "books.xml" file in your browser. $15 Domain Name
XQuery Select Registration
XQuery Functions Save $20 / year!
XQuery Summary
UK Domain Names
XQuery Reference Selecting and Filtering Elements UK Web Hosting
XQuery Reference Alojamiento Web
As we have seen in the previous chapters, we are selecting and filtering elements with either a Buy UK Domain Names
Selected Reading
Path expression or with a FLWOR expression. Register Domain Names
Web Statistics
Web Glossary Cheap Domain Names
Web Hosting Look at the following FLWOR expression: Cheap Web Hosting
Web Quality Best Web Hosting
for $x in doc("books.xml")/bookstore/book
W3Schools Forum Bulk Domain Names
where $x/price>30
order by $x/title UK Web Hosting
Helping W3Schools
return $x/title
PHP MySQL Hosting
Web Hosting UK
● for - (optional) binds a variable to each item returned by the in expression Top 10 Web Hosting
● let - (optional)
● where - (optional) specifies a criteria Web Hosting Providers
● order by - (optional) specifies the sort-order of the result ASP.NET Web Hosting
● return - specifies what to return in the result
3 Months Free!
Programming Forums
The for Clause
Windows Web Hosting
WEB BUILDING
The for clause binds a variable to each item returned by the in expression. The for clause
XML Website Tools
results in iteration. There can be multiple for clauses in the same FLWOR expression.
Website Templates
To loop a specific number of times in a for clause, you may use the to keyword: Flash Templates
Website Builder
Internet Business
for $x in (1 to 5) Opportunity
return <test>{$x}</test>
Custom Programming
BEST Flash Templates
Result:
It is also allowed with more than one in expression in the for clause. Use comma to separate
each in expression:
Result:
The let clause allows variable assignments and it avoids repeating the same expression many
times. The let clause does not result in iteration.
let $x := (1 to 5)
return <test>{$x}</test>
Result:
<test>1 2 3 4 5</test>
The where clause is used to specify one or more criteria for the result:
The order by clause is used to specify the sort order of the result. Here we want to order the
result by category and title:
for $x in doc("books.xml")/bookstore/book
order by $x/@category, $x/title
return $x/title
Result:
for $x in doc("books.xml")/bookstore/book
return $x/title
Result:
Your browser does not support inline frames or is currently configured not to display inline
frames.
NEW! Altova MissionKit 2007– Save ½ off Intelligent tools for XML
developers & software architects
Your browser does not support inline frames or is currently configured not to display inline frames.
SITE SEARCH
HOME XQuery Functions
...
XQuery Basic
XQuery HOME About W3Schools
XQuery Intro W3Schools Forum
XQuery Example
XQuery FLWOR XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same functions library.
XQuery HTML Web based charting
XQuery Terms for ASP.NET
XQuery Syntax
WEB HOSTING
XQuery Advanced XQuery Functions $15 Domain Name
XQuery Add Registration
XQuery Select XQuery includes over 100 built-in functions. There are functions for string values, numeric Save $20 / year!
XQuery Functions values, date and time comparison, node and QName manipulation, sequence manipulation, UK Domain Names
XQuery Summary Boolean values, and more. You can also define your own functions in XQuery.
UK Web Hosting
XQuery Reference Alojamiento Web
XQuery Reference Buy UK Domain Names
Register Domain Names
Selected Reading XQuery Built-in Functions
Web Statistics Cheap Domain Names
Web Glossary The URI of the XQuery function namespace is: Cheap Web Hosting
Web Hosting http://www.w3.org/2005/02/xpath-functions Best Web Hosting
Web Quality
Bulk Domain Names
W3Schools Forum The default prefix for the function namespace is fn:.
UK Web Hosting
Helping W3Schools Tip: Functions are often called with the fn: prefix, such as fn:string(). However, since fn: is the PHP MySQL Hosting
default prefix of the namespace, the function names do not need to be prefixed when called. Web Hosting UK
Top 10 Web Hosting
The reference of all the built-in XQuery 1.0 functions is located in our XPath tutorial.
Web Hosting Providers
ASP.NET Web Hosting
3 Months Free!
A call to a function can appear where an expression may appear. Look at the examples below: WEB BUILDING
XML Website Tools
};
<minPrice>{local:minPrice($book/price, $book/discount)}</minPrice>
Your browser does not support inline frames or is currently configured not to display inline
frames.
Download Your Copy of DWebPro, it's "FREE for non commercial use"!
W3Schools provides material for training only. We do not warrant the correctness of its
contents. The risk from using it lies entirely with the user. While using this site, you agree to
have read and accepted our terms of use and privacy policy.