当前位置: 首页 > 网络学院 > XML相关教程 > Xquery > XQuery FLWOR 表达式
We will use the "books.xml" document in the examples below (same XML file as in the previous chapter).
下述案例中,我们会用到 "books.xml" 文档(上一章使用的XML文件)。
View the "books.xml" file in your browser.
在你的浏览器中浏览“books.xml”。
Look at the following path expression:
先看看下面的路径表达式:
doc("books.xml")/bookstore/book[price>30]/title |
The expression above will select all the title elements under the book elements that are under the bookstore element that have a price element with a value that is higher than 30.
上述表达式将选择 bookstore 元素下的 book 元素下的所有price 元素值大于30的 title 元素。
The following FLWOR expression will select exactly the same as the path expression above:
下述FLWOR表达式和上述路径表达式选择的值相同:
for $x in doc("books.xml")/bookstore/book |
The result will be:
结果如下:
<title lang="en">XQuery Kick Start</title> |
With FLWOR you can sort the result:
你可以使用FLWOR对结果进行分类排序:
for $x in doc("books.xml")/bookstore/book |
FLWOR is an acronym for "For, Let, Where, Order by, Return".
FLWOR是 "For、Let、Where、Order by、Return" 的首字母缩写。
The for clause selects all book elements under the bookstore element into a variable called $x.
For子句把 bookstore 元素中的所有 book 元素发送到名为 $x 的变量内。
The where clause selects only book elements with a price element with a value greater than 30.
Where 子句仅选择price元素值高于30的book元素。
The order by clause defines the sort-order. Will be sort by the title element.
order by 子句定义了“ 分类命令 ”。根据 title 元素进行分类。
The return clause specifies what should be returned. Here it returns the title elements.
Return 子句指定了返回的数据。这里返回的是 title 元素。
The result of the XQuery expression above will be:
上述 XQuery 表达式的结果如下:
<title lang="en">Learning XML</title> |