XQuery Tutorial
Selected Reading
- XQuery - Discussion
- XQuery - Useful Resources
- XQuery - Quick Guide
- XQuery - Custom Functions
- XQuery - If Then Else
- XQuery - Regular Expressions
- XQuery - Date Functions
- XQuery - String functions
- XQuery - Sequence Functions
- XQuery - Sequences
- XQuery - XPath
- XQuery - HTML Format
- XQuery - FLWOR
- XQuery - First Application
- XQuery - Environment Setup
- XQuery - Overview
- XQuery - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
XQuery - If Then Else
XQuery - If Then Else
食堂为检查所传递的投入价值是否有效提供了非常有用的假造。 下面是“三轮”建筑的星号。
Syntax
if (condition) then ... else ...
Example
我们将使用以下书本。
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>40.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 expression is to be used on the above XML document.
books.xqy
<result> { if(not(doc("books.xml"))) then ( <error> <message>books.xml does not exist</message> </error> ) else ( for $x in doc("books.xml")/books/book where $x/price>30 return $x/title ) } </result>
Output
<result> <title lang="en">Learn .Net in 24 hours</title> <title lang="en">Learn XQuery in 24 hours</title> </result>
Verify the Result
为核实结果,取代books.xqy。 (见
Advertisements