📜  XQuery函数

📅  最后修改于: 2020-12-25 05:03:28             🧑  作者: Mango

XQuery函数

XQuery 1.0,XPath 2.0和XSLT 2.0共享相同的函数库。

一系列不同类型的XQuery函数:

  • 访问器功能
  • 错误和跟踪功能
  • 数值函数
  • 字符串函数
  • AnyURI函数
  • 布尔函数
  • 持续时间/日期/时间功能
  • QName函数
  • 节点功能
  • 序列功能
  • 上下文功能

函数以fn:前缀指定。例如:fn:字符串()。但是fn:是名称空间的默认前缀,因此在函数时不必为前缀fn。

访问器功能

Index Name Description
1) fn:node-name(node) It is used to return the node-name of the argument node.
2) fn:nilled(node) It is used to return a Boolean value indicating whether the argument node is nil.
3) fn:data(item.item,…) It is used to take a sequence of items and return a sequence of atomic values.
4) fn:base-uri()
fn:base-uri(node)
It returns the value of the base-uri property of the current or specified node.
5) fn:document-uri(node) It returns the value of the document-uri property for the specified node.

错误和跟踪功能

Index Name Description
1) fn:error()
fn:error(error)
fn:error(error,description)
fn:error(error,description,error-object)
Example: error(fn:qname(‘http://example.com/test’, ‘err:toohigh’), ‘error: price is too high’)result: returns http://example.com/test#toohigh and the string “error: price is too high” to the external processing environment.
2) fn:trace(value,label) it is used to debug queries.

数值函数

Index Name Description
1) fn:abs(num) It returns the absolute value of the argument.
For example: abs(3.14)
Result: 3.14
2) fn:abs(num) It returns the absolute value of the argument
For example: abs(3.14)
Result: 3.14
Example: abs(-3.14)
Result: 3.14
3) fn:ceiling(num) It returns the smallest integer that is greater than the number argument
For example: ceiling(3.14)
Result: 4
4) fn:floor(num) It returns the largest integer that is not greater than the number argument
For example: floor(3.14)
Result: 3
5) fn:round(num) It is used to round of the number argument to the nearest integer
For example: round(3.14)
Result: 3
6) fn:round-half-to-even() Example: round-half-to-even(0.5)
Result: 0
Example: round-half-to-even(1.5)
Result: 2
Example: round-half-to-even(2.5)
Result: 2

字符串函数

XQuery中使用了很多字符串函数,但是这里我们使用的是选定的函数。

XQuery的常用字符串操作功能列表:

Index Name Description
1) string-length($string as xs:string) as xs:integer It returns the length of the string.
2) concat($input as xs:anyatomictype?) as xs:string It returns the concatenated string as output.
3) string-join($sequence as xs:string*, $delimiter as xs:string) as xs:string It returns the combination of items in a sequence separated by a delimiter.

布尔值函数

Index Name Description
1) fn:boolean(arg) It is used to return a Boolean value for a number, string, or node-set.
2) fn:not(arg) It specifies that the argument is first reduced to a Boolean value by applying the Boolean() function. It returns true if the Boolean value is false, and false if the Boolean value is true.
For example: not(true())
Result: false
3) fn:true() It returns the Boolean value true
Example: true()
Result: true
4) fn:false() It returns the Boolean value false
For example: false()
Result: false

时间和日期功能

XQuery支持很多时间和日期函数,但是在这里,我们提供所选的功能。

XQuery提供的一些常用日期和时间函数的列表:

Index Name Description
1) current-date() It is used to return the current date.
2) current-time() It is used to return the current time.
3) current-datetime() It is used to return both the current date and the current time.