English 中文(简体)
XQuery - FLWOR
  • 时间:2025-03-14

XQuery - FLWOR


Previous Page Next Page  

FLWOR是一个缩略语,可称为“在什么地方,由回归令”。 The following pst show what they account for in a FLWOR expression -

    选择收集所有节点。

    如果有 选择条件规定的节点。

    - 发布命令,根据标准发布公告。

Example

以下是XML文件样本,其中载有收集书籍的资料。 我们将使用FLWOR的表述,以超过30美元的价格收回这些书籍的标题。

books.xml

<?xml version="1.0" encoding="UTF-8"?>
<books>
   
   <book category="JAVA">
      <title lang="en">Learn Java in 24 Hours</title>
      <author>Robert</author>
      <year>2005</year>
      <price>30.00</price>
   </book>
   
   <book category="DOTNET">
      <title lang="en">Learn .Net in 24 hours</title>
      <author>Peter</author>
      <year>2011</year>
      <price>70.50</price>
   </book>
   
   <book category="XML">
      <title lang="en">Learn XQuery in 24 hours</title>
      <author>Robert</author>
      <author>Peter</author> 
      <year>2013</year>
      <price>50.00</price>
   </book>
   
   <book category="XML">
      <title lang="en">Learn XPath in 24 hours</title>
      <author>Jay Ban</author>
      <year>2010</year>
      <price>16.50</price>
   </book>
   
</books>

The following Xquery document contained the query expression to be committed on the above XML document.

books.xqy

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>

Result

<title lang="en">Learn XQuery in 24 hours</title>
<title lang="en">Learn .Net in 24 hours</title>

Verify Result

为核实结果,取代books.xqy。 (见

Advertisements