当前位置: 首页 > 网络学院 > XML相关教程 > Xquery > XQuery 语法

Xquery
XQuery 介绍
XQuery 实例
XQuery FLWOR 表达式
XQuery FLWOR + HTML
XQuery 术语
XQuery 语法
XQuery 添加元素和属性
XQuery 选择和过滤
XQuery 函数
XQuery 摘要
XQuery 参考

Xquery 中的 XQuery 语法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 656 ::
收藏到网摘: n/a

XQuery is case-sensitive and XQuery elements, attributes, and variables must be valid XML names.
Xquery 区分字母大小写,它的元素、属性、变量必须是有效的XML名称。


XQuery Basic Syntax Rules
XQuery 的基本语法规则

Some basic syntax rules:
一些基本语法规则:

  • XQuery is case-sensitive
    XQuery 区分字母大小写
  • XQuery elements, attributes, and variables must be valid XML names
    它的元素、属性、变量必须是有效的XML名称
  • An XQuery string value can be in single or double quotes
    一个 XQuery 字符串值可以写在单引号里或双引号里
  • An XQuery variable is defined with a $ followed by a name, e.g. $bookstore
    一个 XQuery 变量定义是在“$”的符号后面跟上名称等,例如:$bookstore
  • XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)
    XQuery 注释使用 “(: ”和“ :)” 进行分界,例如 (: XQuery Comment :)

XQuery Conditional Expressions
XQuery 的条件表达式

"If-Then-Else" expressions are allowed in XQuery.
XQuery 允许使用 "If-Then-Else" 条件表达式。

Look at the following example:
先看看下面的案例:

for $x in doc("books.xml")/bookstore/book
return if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>

Notes on the "if-then-else" syntax: parentheses around the if expression are required. else is required, but it can be just else ().
使用“if-then-else"条件语句时应注意的语法点:if 表达式允许出现圆括号;另外,如果使用了“if”,就必须使用“else”,也可以是else()。

The result of the example above will be:
上述案例输出的结果如下:

<adult>Everyday Italian</adult>
<child>Harry Potter</child>
<adult>Learning XML</adult>
<adult>XQuery Kick Start</adult>

 


XQuery Comparisons
XQuery 比较

In XQuery there are two ways of comparing values.
XQuery 有两种比较值的方法。

1. General comparisons: =, !=, <, <=, >, >=
常规比较符号:= 、 != 、 < 、 <= 、 > 、 >=

2. Value comparisons: eq, ne, lt, le, gt, ge
值的比较:eq 、 ne 、 lt 、 le 、 gt 、 ge

The difference between the two comparison methods are shown below.
下面列举了两种比较方法的不同之处。

Look at the following XQuery expressions:
先看看下面的XQuery表达式:

$bookstore//book/@q > 10
The expression above returns true if any q attributes
have values greater than 10.
如果所有上述q的属性值大于10,那么,表达式将返回“true”(真)
$bookstore//book/@q gt 10
The expression above returns true if there is only one
q attribute returned by the expression, and its value
is greater than 10. If more than one q is returned,
an error occurs.
如果表达式返回的q属性中,只有一个q值大于10,那么,上述表达式才返回“true”(真);否则,将产生错误。

评论 (0) All

登陆 | 还没注册?