FLWOR是首字母缩略词,代表"For,Let,Where,Order by,Return".以下列表显示了他们在FLWOR表达式中所占的内容 : 去;
F - 对于 - 选择所有节点的集合.
L - 让 - 将结果放在XQuery变量中.
W - 其中 - 选择条件指定的节点.
O - 按顺序排序 - 按照标准对指定的节点进行排序.
R - 返回 - 返回最终结果.
以下是一个示例XML文档,其中包含有关a的信息.藏书.我们将使用FLWOR表达式来检索价格大于30的书籍的标题.
<?xml version="1.0" encoding="UTF-8"?> <books> <book category="JAVA"> <title>Learn Java in 24 Hours</title> <author>Robert</author> <year>2005</year> <price>30.00</price> </book> <book category="DOTNET"> <title>Learn .Net in 24 hours</title> <author>Peter</author> <year>2011</year> <price>70.50</price> </book> <book category="XML"> <title>Learn XQuery in 24 hours</title> <author>Robert</author> <author>Peter</author> <year>2013</year> <price>50.00</price> </book> <book category="XML"> <title>Learn XPath in 24 hours</title> <author>Jay Ban</author> <year>2010</year> <price>16.50</price> </book> </books>
以下Xquery文档包含要在上述XML文档上执行的查询表达式.
let $books := (doc("books.xml")/books/book) return <results> { for $x in $books where $x/price>30 order by $x/price return $x/title } </results>
<title>Learn XQuery in 24 hours</title> <title>Learn .Net in 24 hours</title>
要验证结果,请替换 books.xqy 的内容(在环境设置章节中给出)使用上面的XQuery表达式并执行XQueryTester java程序.