菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

XML 教程

XML HOME XML Introduction XML How to use XML Tree XML Syntax XML Elements XML Attributes XML Namespaces XML Display XML HttpRequest XML Parser XML DOM XML XPath XML XSLT XML XQuery XML XLink XML Validator XML DTD XML Schema XML Server XML Examples XML Quiz XML Certificate

XML AJAX

AJAX Introduction AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples

XML DOM

DOM Introduction DOM Nodes DOM Accessing DOM Node Info DOM Node List DOM Traversing DOM Navigating DOM Get Values DOM Change Nodes DOM Remove Nodes DOM Replace Nodes DOM Create Nodes DOM Add Nodes DOM Clone Nodes DOM Examples

XPath 教程

XPath Introduction XPath Nodes XPath Syntax XPath Axes XPath Operators XPath Examples

XSLT 教程

XSLT Introduction XSL Languages XSLT Transform XSLT <template> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XSLT Apply XSLT on the Client XSLT on the Server XSLT Edit XML XSLT Examples

XQuery 教程

XQuery Introduction XQuery Example XQuery FLWOR XQuery HTML XQuery Terms XQuery Syntax XQuery Add XQuery Select XQuery Functions

XML DTD

DTD Introduction DTD Building Blocks DTD Elements DTD Attributes DTD Elements vs Attr DTD Entities DTD Examples

XSD Schema

XSD Introduction XSD How To XSD <schema> XSD Elements XSD Attributes XSD Restrictions XSD Complex Elements XSD Empty XSD Elements-only XSD Text-only XSD Mixed XSD Indicators XSD <any> XSD <anyAttribute> XSD Substitution XSD Example

XSD Data Types

XSD String XSD Date/Time XSD Numeric XSD Misc XSD Reference

Web Services

XML Services XML WSDL XML SOAP XML RDF XML RSS

参考手册

DOM Node Types DOM Node DOM NodeList DOM NamedNodeMap DOM Document DOM Element DOM Attribute DOM Text DOM CDATA DOM Comment DOM XMLHttpRequest DOM Parser XSLT Elements XSLT/XPath Functions

XQuery FLWOR 表达式


什么是 FLWOR?

FLWOR(发音为“flower”)是“For, Let, Where, Order by, Return”的首字母缩写。

  • For - 选择一个节点序列
  • Let - 将序列绑定到一个变量
  • Where - 过滤节点
  • Order by - 对节点进行排序
  • Return - 返回什么(对每个节点进行一次评估)

XML 示例文档

我们将在下面的示例中使用“books.xml”文档(与上一章的 XML 文件相同)。

在浏览器中查看“books.xml”文件.


如何使用 FLWOR 从“books.xml”中选择节点

看下面的路径表达式

doc("books.xml")/bookstore/book[price>30]/title

上面的表达式将选择 bookstore 元素下 book 元素中,price 元素值大于 30 的所有 title 元素。

以下 FLWOR 表达式将选择与上面的路径表达式完全相同的内容

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

结果将是

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

使用 FLWOR,您可以对结果进行排序

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

for 子句将 bookstore 元素下的所有 book 元素选择到一个名为 $x 的变量中。

where 子句只选择 price 元素值大于 30 的 book 元素。

order by 子句定义排序顺序。将按 title 元素排序。

return 子句指定要返回什么。这里返回 title 元素。

上面 XQuery 表达式的结果将是

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

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持