当前位置:K88软件开发文章中心编程语言XmlXPath01 → 文章内容

XPath、XQuery 以及 XSLT 函数

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-13 11:00:45

XPath、XQuery 以及 XSLT 函数函数参考手册下面的参考手册定义了XPath 2.0,XQuery 1.0和XSLT 2.0中的函数。函数参考手册存取错误和跟踪数值字符串AnyURI逻辑持续时间/日期/时间QName节点序列Context 函数命名空间的默认前缀为 fn: 函数命名空间的 URI为 : http://www.w3.org/2005/xpath-functions存取函数名称说明fn:node-name(node)返回参数节点的节点名称。fn:nilled(node)返回是否拒绝参数节点的布尔值。fn:data(item.item,...)接受项目序列,并返回原子值序列。fn:base-uri()fn:base-uri(node)返回当前节点或指定节点的 base-uri 属性的值。fn:document-uri(node)返回指定节点的 document-uri 属性的值。错误和跟踪函数名称说明fn:error()fn:error(error)fn:error(error,description)fn:error(error,description,error-object)例子:error(fn:QName('http://example.com/test', 'err:toohigh'), 'Error: Price is too high')结果:向外部处理环境返回 http://example.com/test#toohigh 以及字符串 "Error: Price is too high"。fn:trace(value,label)用于对查询进行 debug。有关数值的函数名称说明fn:number(arg)返回参数的数值。参数可以是布尔值、字符串或节点集。例子:number('100')结果:100fn:abs(num)返回参数的绝对值。例子:abs(3.14)结果:3.14例子:abs(-3.14)结果:3.14fn:ceiling(num)返回大于 num 参数的最小整数。例子:ceiling(3.14)结果:4fn:floor(num)返回不大于 num 参数的最大整数。例子:floor(3.14)结果:3fn:round(num)把 num 参数舍入为最接近的整数。例子:round(3.14)结果:3fn:round-half-to-even()例子:round-half-to-even(0.5)结果:0 例子:round-half-to-even(1.5)结果:2例子:round-half-to-even(2.5)结果:2有关字符串的函数名称说明fn:string(arg)返回参数的字符串值。参数可以是数字、逻辑值或节点集。例子:string(314)结果:"314"fn:codepoints-to-string(int,int,...)根据代码点序列返回字符串。例子:codepoints-to-string(84, 104, 233, 114, 232, 115, 101)结果:'Thérèse'fn:string-to-codepoints(string)根据字符串返回代码点序列。例子:string-to-codepoints("Thérèse")结果:84, 104, 233, 114, 232, 115, 101fn:codepoint-equal(comp1,comp2)根据 Unicode 代码点对照,如果 comp1 的值等于 comp2 的值,则返回 true。(http://www.w3.org/2005/02/xpath-functions/collation/codepoint),否则返回 false。fn:compare(comp1,comp2)fn:compare(comp1,comp2,collation)如果 comp1 小于 comp2,则返回 -1。如果 comp1 等于 comp2,则返回 0。如果 comp1 大于 comp2,则返回 1。(根据所用的对照规则)。例子:compare('ghi', 'ghi')结果:0fn:concat(string,string,...)返回字符串的拼接。例子:concat('XPath ','is ','FUN!')结果:'XPath is FUN!'fn:string-join((string,string,...),sep)使用 sep 参数作为分隔符,来返回 string 参数拼接后的字符串。例子:string-join(('We', 'are', 'having', 'fun!'), ' ')结果:' We are having fun! '例子:string-join(('We', 'are', 'having', 'fun!'))结果:'Wearehavingfun!'例子:string-join((), 'sep')结果:''fn:substring(string,start,len)fn:substring(string,start)返回从 start 位置开始的指定长度的子字符串。第一个字符的下标是 1。如果省略 len 参数,则返回从位置 start 到字符串末尾的子字符串。例子:substring('Beatles',1,4)结果:'Beat'例子:substring('Beatles',2)结果:'eatles'fn:string-length(string)fn:string-length()返回指定字符串的长度。如果没有 string 参数,则返回当前节点的字符串值的长度。例子:string-length('Beatles')结果:7fn:normalize-space(string)fn:normalize-space()删除指定字符串的开头和结尾的空白,并把内部的所有空白序列替换为一个,然后返回结果。如果没有 string 参数,则处理当前节点。例子:normalize-space(' The   XML ')结果:'The XML'fn:normalize-unicode()执行 Unicode 规格化。fn:upper-case(string)把 string 参数转换为大写。例子:upper-case('The XML')结果:'THE XML'fn:lower-case(string)把 string 参数转换为小写。例子:lower-case('The XML')结果:'the xml'fn:translate(string1,string2,string3)把 string1 中的 string2 替换为 string3。例子:translate('12:30','30','45')结果:'12:45'例子:translate('12:30','03','54')结果:'12:45'例子:translate('12:30','0123','abcd')结果:'bc:da'fn:escape-uri(stringURI,esc-res)例子:escape-uri("http://example.com/test#car", true())结果:"http%3A%2F%2Fexample.com%2Ftest#car"例子:escape-uri("http://example.com/test#car", false())结果:"http://example.com/test#car"例子:escape-uri ("http://example.com/~bébé", false())结果:"http://example.com/~b%C3%A9b%C3%A9"fn:contains(string1,string2)如果 string1 包含 string2,则返回 true,否则返回 false。例子:contains('XML','XM')结果:truefn:starts-with(string1,string2)如果 string1 以 string2 开始,则返回 true,否则返回 false。例子:starts-with('XML','X')结果:truefn:ends-with(string1,string2)如果 string1 以 string2 结尾,则返回 true,否则返回 false。例子:ends-with('XML','X')结果:falsefn:substring-before(string1,string2)返回 string2 在 string1 中出现之前的子字符串。例子:substring-before('12/10','/')结果:'12'fn:substring-after(string1,string2)返回 string2 在 string1 中出现之后的子字符串。例子:substring-after('12/10','/')结果:'10'fn:matches(string,pattern)如果 string 参数匹配指定的模式,则返回 true,否则返回 false。例子:matches("Merano", "ran")结果:truefn:replace(string,pattern,replace)把指定的模式替换为 replace 参数,并返回结果。例子:replace("Bella Italia", "l", "*")结果:'Be**a Ita*ia'例子:replace("Bella Italia", "l", "")结果:'Bea Itaia'fn:tokenize(string,pattern)例子:tokenize("XPath is fun", "\s+")结果:("XPa

[1] [2] [3]  下一页


XPath、XQuery 以及 XSLT 函数