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 - HTML Format
XQuery - HTML Format
也可以很容易地将XML文件变成一个超文本页。 探讨以下例子,以了解锡克文是如何做到的。
Example
我们将使用同样的书籍。 下面的例子使用XQuery从书本中提取数据,并制作一个载有所有书本名称及其各自价格的超文本表格。
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>
下面是按上述XML文件实施的Xquery表述。
books.xqy
let $books := (doc("books.xml")/books/book) return <table><tr><th>Title</th><th>Price</th></tr> { for $x in $books order by $x/price return <tr><td>{data($x/title)}</td><td>{data($x/price)}</td></tr> } </table> </results>
Result
<table> <tr> <th>Title</th> <th>Price</th> </tr> <tr> <td>Learn XPath in 24 hours</td> <td>16.50</td> </tr> <tr> <td>Learn Java in 24 Hours</td> <td>30.00</td> </tr> <tr> <td>Learn XQuery in 24 hours</td> <td>50.00</td> </tr> <tr> <td>Learn .Net in 24 hours</td> <td>70.50</td> </tr> </table>
Verify Result
为核实结果,取代books.xqy。 (见
XQuery Expressions
在这里,我们使用了以下崇高语句:
(a) 评估所有权要素的价值的职能,以及
{} 运营商将数据(a)视为功能。 如果没有使用{}操作员,那么数据()将作为正常文本处理。