XQuery-FLWOR

FLWOR는 "For, Let, Where, Order by, Return"의 약어입니다. 다음 목록은 FLWOR 표현식에서 설명하는 내용을 보여줍니다.

  • F -For-모든 노드의 모음을 선택합니다.

  • L -Let-결과를 XQuery 변수에 넣습니다.

  • W -Where-조건에 지정된 노드를 선택합니다.

  • O -정렬 기준-기준에 따라 지정된 노드를 정렬합니다.

  • R -반환-최종 결과를 반환합니다.

다음은 책 모음에 대한 정보가 포함 된 샘플 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 contains the query expression to be executed 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

To verify the result, replace the contents of books.xqy (given in theEnvironment Setup chapter) with the above XQuery expression and execute the XQueryTester java program.