当前位置: 首页 > 网络学院 > XML相关教程 > Xquery > XQuery FLWOR 表达式

Xquery
XQuery 介绍
XQuery 实例
XQuery FLWOR 表达式
XQuery FLWOR + HTML
XQuery 术语
XQuery 语法
XQuery 添加元素和属性
XQuery 选择和过滤
XQuery 函数
XQuery 摘要
XQuery 参考

Xquery 中的 XQuery FLWOR 表达式


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 571 ::
收藏到网摘: n/a

The XML Example Document
XML 案例文档

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”


How to Select Nodes From "books.xml" With FLWOR
怎样使用FLWOR表达式从"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
where $x/price>30
return $x/title

The result will be:
结果如下:

<title lang="en">XQuery Kick Start</title>

<title lang="en">Learning XML</title>

With FLWOR you can sort the result:
你可以使用FLWOR对结果进行分类排序:

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title

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>

<title lang="en">XQuery Kick Start</title>

评论 (0) All

登陆 | 还没注册?