zoukankan      html  css  js  c++  java
  • <转>XPath 2.0, XQuery 1.0 和 XSLT 2.0 函数参考

    <原文路径:http://c.lstc.edu.cn:8090/kj/Manfeel/w3pop/xpath_functions.asp.htm>

    下面的参考目录库详细包括了XPath 2.0, XQuery 1.0 和 XSLT 2.0.所要求的函数


    Functions Reference
    函数参考目录

    The default prefix for the function namespace is fn:, and the URI is:
    http://www.w3.org/2005/02/xpath-functions.
    函数命名空间的默认前缀是“fn”,URI是:http://www.w3.org/2005/02/xpath-functions.

    Accessor Functions

    Name
    名称
    Description
    描述
    fn:node-name(node) Returns the node-name of the argument node
    返回自变量节点的节点(node)名称
    fn:nilled(node) Returns a Boolean value indicating whether the argument node is nilled
    返回一个逻辑值,用来指明自变量(argument)节点是否被拒绝
    fn:data(item.item,...) Takes a sequence of items and returns a sequence of atomic values
    获取项目的一个序列并返回一个原子值(atomic value)序列
    fn:base-uri()
    fn:base-uri(node)
    Returns the value of the base-uri property of the current or specified node
    返回当前节点或指定节点内基于uri属性的值
    fn:document-uri(node) Returns the value of the document-uri property for the specified node
    返回指定节点中uri文档属性的值

    Error and Trace Functions

    Name
    名称
    Description
    描述
    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

    fn:trace(value,label) Used to debug queries
    用来调试查询(queries)

    Functions on Numeric Values

    Name
    名称
    Description
    描述
    fn:number(arg) Returns the numeric value of the argument. The argument could be a boolean, string, or node-set

    Example: number('100')
    Result: 100
    返回自变量数值。这个自变量可以是一个逻辑值(boolean)、字符串(string)或者是节点设置
    举例: number('100')
    结果: 100

    fn:abs(num) Returns the absolute value of the argument
    返回自变量的绝对值

    Example举例: abs(3.14)
    Result结果: 3.14

    Example举例: abs(-3.14)
    Result结果: 3.14

    fn:ceiling(num) Returns the smallest integer that is greater than the number argument

    Example: ceiling(3.14)
    Result: 4

    fn:floor(num) Returns the largest integer that is not greater than the number argument
    返回大于自变量数值的最小整数

    Example举例: floor(3.14)
    Result结果: 3

    fn:round(num) Rounds the number argument to the nearest integer
    返回小于自变量数值的最大整数

    Example举例: round(3.14)
    Result结果: 3

    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

    Functions on Strings

    Name
    名称
    Description
    描述
    fn:string(arg) Returns the string value of the argument. The argument could be a number, boolean, or node-set
    返回自变量的字符串值。这个自变量可以是一个数字、逻辑值或节点设置。

    Example举例: string(314)
    Result结果: "314"

    fn:codepoints-to-string(int,int,...) Returns a string from a sequence of code points
    从一组代码点(code points)中返回一个字符串

    Example举例: codepoints-to-string(84, 104, 233, 114, 232, 115, 101)
    Result结果: 'Thérèse'

    fn:string-to-codepoints(string) Returns a sequence of code points from a string
    从字符串中返回一组连续的代码点(code points)

    Example举例: string-to-codepoints("Thérèse")
    Result结果: 84, 104, 233, 114, 232, 115, 101

    fn:codepoint-equal(comp1,comp2) Returns true if the value of comp1 is equal to the value of comp2, according to the Unicode code point collation (http://www.w3.org/2005/02/xpath-functions/collation/codepoint), otherwise it returns false
    根据统一字符编码点整理,如果comp1值与comp2值等同,则返回true。(http://www.w3.org/2005/02/xpath-functions/collation/codepoint)反之则为false
    fn:compare(comp1,comp2)
    fn:compare(comp1,comp2,collation)
    Returns -1 if comp1 is less than comp2, 0 if comp1 is equal to comp2, or 1 if comp1 is greater than comp2 (according to the rules of the collation that is used)
    如果comp1少于comp2则返回-1,如果comp1等同于comp2或comp1
    大于comp2(根据整理规则)则返回0。 

    Example举例: compare('ghi', 'ghi')
    Result结果: 0

    fn:concat(string,string,...) Returns the concatenation of the strings
    返回字符串的串联

    Example举例: concat('XPath ','is ','FUN!')
    Result结果: 'XPath is FUN!'

    fn:string-join((string,string,...),sep) Returns a string created by concatenating the string arguments and using the sep argument as the separator
    返回一个字符串,此字符串是通过连接字符串自变量和使用解析器形式的sep自变量来创建的。

    Example举例: string-join(('We', 'are', 'having', 'fun!'), ' ')
    Result结果: ' We are having fun! '

    Example举例: string-join(('We', 'are', 'having', 'fun!'))
    Result结果: 'Wearehavingfun!'

    Example举例:string-join((), 'sep')
    Result结果: ''

    fn:substring(string,start,len)
    fn:substring(string,start)
    Returns the substring from the start position to the specified length. Index of the first character is 1. If length is omitted it returns the substring from the start position to the end
    输出一个从开始位置算起,指定长度的子字符串。第一字符索引是1.如果长度被忽略,那么就输出一个从开始位置起一直到末尾的子链。

    Example举例: substring('Beatles',1,4)
    Result结果: 'Beat'

    Example举例: substring('Beatles',2)
    Result结果: 'eatles'

    fn:string-length(string)
    fn:string-length()
    Returns the length of the specified string. If there is no string argument it returns the length of the string value of the current node
    输出指定字符串的长度。如果没有字符串自变量则返回当前节点的字符串值的长度。

    Example举例: string-length('Beatles')
    Result结果: 7

    fn:normalize-space(string)
    fn:normalize-space()
    Removes leading and trailing spaces from the specified string, and replaces all internal sequences of white space with one and returns the result. If there is no string argument it does the same on the current node
    从指定字符串中删除前端的空间与末尾的空间,用一个空格替代所有的内部空白序列。如果没有字符串自变量则在当前节点中进行上述操作。

    Example举例: normalize-space(' The   XML ')
    Result结果: 'The XML'

    fn:normalize-unicode()  
    fn:upper-case(string) Converts the string argument to upper-case
    把字符串自变量转换到upper-case 

    Example举例: upper-case('The XML')
    Result结果: 'THE XML'

    fn:lower-case(string) Converts the string argument to lower-case
    把字符串转自变量换到lower-case 

    Example举例: lower-case('The XML')
    Result结果: 'the xml'
    fn:translate(string1,string2,string3) Converts string1 by replacing the characters in string2 with the characters in string3
    通过用字符串3中的字符串替换字符串2中的字符,转换字符串1

    Example举例: translate('12:30','30','45')
    Result结果: '12:45'

    Example举例: translate('12:30','03','54')
    Result结果: '12:45'

    Example举例: translate('12:30','0123','abcd')
    Result结果: 'bc:da'

    fn:escape-uri(stringURI,esc-res) Example举例: escape-uri("http://example.com/test#car", true())
    Result结果: "http%3A%2F%2Fexample.com%2Ftest#car"

    Example举例: escape-uri("http://example.com/test#car", false())
    Result结果: "http://example.com/test#car"

    Example举例: escape-uri ("http://example.com/~bébé", false())
    Result结果: "http://example.com/~b%C3%A9b%C3%A9"

    fn:contains(string1,string2) Returns true if string1 contains string2, otherwise it returns false
    如果string 1含有string 2则输出true;反之为false

    Example举例: contains('XML','XM')
    Result结果: true

    fn:starts-with(string1,string2) Returns true if string1 starts with string2, otherwise it returns false
    如果string 1以string 2开头则输出true;反之则为false

    Example举例: starts-with('XML','X')
    Result结果: true

    fn:ends-with(string1,string2) Returns true if string1 ends with string2, otherwise it returns false
    如果string 1以string 2为结尾则输出true;反之为false

    Example举例: ends-with('XML','X')
    Result结果: false

    fn:substring-before(string1,string2) Returns the start of string1 before string2 occurs in it
    在string2触发之前输出 string1的始端

    Example举例: substring-before('12/10','/')
    Result结果: '12'

    fn:substring-after(string1,string2) Returns the remainder of string1 after string2 occurs in it
    在string2触发之前输出string1的余数

    Example举例: substring-after('12/10','/')
    Result结果: '10'

    fn:matches(string,pattern) Returns true if the string argument matches the pattern, otherwise, it returns false
    如果字符串自变量与模式相匹配则输出true,反之为false

    Example举例: matches("Merano", "ran")
    Result结果: true

    fn:replace(string,pattern,replace) Returns a string that is created by replacing the given pattern with the replace argument
    输出一个字符串(用替换自变量替换特定模式)

    Example举例: replace("Bella Italia", "l", "*")
    Result结果: 'Be**a Ita*ia'

    Example举例: replace("Bella Italia", "l", "")
    Result结果: 'Bea Itaia'
    fn:tokenize(string,pattern) Example举例: tokenize("XPath is fun", "\s+")
    Result结果: ("XPath", "is", "fun")

    Functions for anyURI

    Name
    名称
    Description
    描述
    fn:resolve-uri(relative,base)  

    Functions on Boolean Values

    Name
    名称
    Description
    描述
    fn:boolean(arg) Returns a boolean value for a number, string, or node-set
    输出一个数字、字符串及节点设置的逻辑函数
    fn:not(arg) The argument is first reduced to a boolean value by applying the boolean() function. Returns true if the boolean value is false, and false if the boolean value is true
    自变量是第一个成为适用于boolean()函数的逻辑值。如果逻辑值是false则输出true,反之亦然。

    Example举例: not(true())
    Result结果: false

    fn:true() Returns the boolean value true
    输出逻辑值为true

    Example举例: true()
    Result结果: true

    fn:false() Returns the boolean value false
    输出逻辑值为false

    Example举例: false()
    Result结果: false

    Functions on Durations, Dates and Times

    Component Extraction Functions on Durations, Dates and Times
    持续时间、日期、时间函数组件

    Name
    名称
    Description
    描述
    fn:dateTime(date,time) Converts the arguments to a date and a time
    把自变量转换成日期和时间
    fn:years-from-duration(datetimedur) Returns an integer that represents the years component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示年份的整形
    fn:months-from-duration(datetimedur) Returns an integer that represents the months component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示月份的整形
    fn:days-from-duration(datetimedur) Returns an integer that represents the days component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示天数的整形
    fn:hours-from-duration(datetimedur) Returns an integer that represents the hours component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示时数的整形
    fn:minutes-from-duration(datetimedur) Returns an integer that represents the minutes component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示分数的整形
    fn:seconds-from-duration(datetimedur) Returns a decimal that represents the seconds component in the canonical lexical representation of the value of the argument
    输出一个在自变量值标准词汇表示中表示秒数的小数
    fn:year-from-dateTime(datetime) Returns an integer that represents the year component in the localized value of the argument
    输出一个在自变量本地值中表示年份的整形

    Example举例: year-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
    Result结果: 2005

    fn:month-from-dateTime(datetime) Returns an integer that represents the month component in the localized value of the argument
    输出一个在自变量本地值中表示月份的整形

    Example举例: month-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
    Result结果: 01

    fn:day-from-dateTime(datetime) Returns an integer that represents the day component in the localized value of the argument
    输出一个在自变量本地值中表示的整形

    Example举例: day-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
    Result结果: 10

    fn:hours-from-dateTime(datetime) Returns an integer that represents the hours component in the localized value of the argument
    输出一个在自变量本地值中表示时数的整形

    Example举例: hours-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
    Result结果: 12

    fn:minutes-from-dateTime(datetime) Returns an integer that represents the minutes component in the localized value of the argument
    输出一个在自变量本地值中表示分数的整形

    Example举例: minutes-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
    Result结果: 30

    fn:seconds-from-dateTime(datetime) Returns a decimal that represents the seconds component in the localized value of the argument
    输出一个在自变量本地值中表示秒数的小数

    Example举例: seconds-from-dateTime(xs:dateTime("2005-01-10T12:30:00-04:10"))
    Result结果: 0

    fn:timezone-from-dateTime(datetime) Returns the time zone component of the argument if any
    输出任何自变量时区组件如果它们存在
    fn:year-from-date(date) Returns an integer that represents the year in the localized value of the argument
    输出一个在自变量本地值中表示年份的整形

    Example举例: year-from-date(xs:date("2005-04-23"))
    Result结果: 2005

    fn:month-from-date(date) Returns an integer that represents the month in the localized value of the argument
    输出一个在自变量本地值中表示月份的整形

    Example举例: month-from-date(xs:date("2005-04-23"))
    Result结果: 4

    fn:day-from-date(date) Returns an integer that represents the day in the localized value of the argument
    输出一个在自变量本地值中表示天数的整形

    Example举例: day-from-date(xs:date("2005-04-23"))
    Result结果: 23

    fn:timezone-from-date(date) Returns the time zone component of the argument if any
    输出自变量的时区组件如果它们存在
    fn:hours-from-time(time) Returns an integer that represents the hours component in the localized value of the argument
    输出一个在自变量本地值中表示时数的整形0

    Example举例: hours-from-time(xs:time("10:22:00"))
    Result结果: 10

    fn:minutes-from-time(time) Returns an integer that represents the minutes component in the localized value of the argument
    输出一个在自变量本地值中表示分数的整形

    Example举例: minutes-from-time(xs:time("10:22:00"))
    Result结果: 22
    fn:seconds-from-time(time) Returns an integer that represents the seconds component in the localized value of the argument
    输出一个在自变量本地值中表示秒数的整形

    Example举例: seconds-from-time(xs:time("10:22:00"))
    Result结果: 0

    fn:timezone-from-time(time) Returns the time zone component of the argument if any
    输出自变量时区组件如果它们存在
    fn:adjust-dateTime-to-timezone(datetime,timezone) If the timezone argument is empty, it returns a dateTime without a timezone. Otherwise, it returns a dateTime with a timezone
    如果时区(timezone)自变量为空,那么就输出一个无时区的dateTime。相反就输出一个含有时区(timezone)的dateTime
    fn:adjust-date-to-timezone(date,timezone) If the timezone argument is empty, it returns a date without a timezone. Otherwise, it returns a date with a timezone
    如果时区(timezone)自变量为空,则输出无时区的日期;相反则输出一个含有时区(timezone)的日期
    fn:adjust-time-to-timezone(time,timezone) If the timezone argument is empty, it returns a time without a timezone. Otherwise, it returns a time with a timezone
    如果时区(timezone)自变量为空,那么输出一个无时区的时间,相反,则输出一个含有时区的时间。

    Functions Related to QNames

    Name
    名称
    Description
    描述
    fn:QName()  
    fn:local-name-from-QName()  
    fn:namespace-uri-from-QName()  
    fn:namespace-uri-for-prefix()  
    fn:in-scope-prefixes()  
    fn:resolve-QName()  

    Functions on Nodes

    Name
    名称
    Description
    描述
    fn:name()
    fn:name(nodeset)
    Returns the name of the current node or the first node in the specified node set
    输出当前节点或指定节点设置中首个节点的名称
    fn:local-name()
    fn:local-name(nodeset)
    Returns the name of the current node or the first node in the specified node set - without the namespace prefix
    输出当前节点或指定节点设置中首个节点的名称(无须命名空间前缀)
    fn:namespace-uri()
    fn:namespace-uri(nodeset)
    Returns the namespace URI of the current node or the first node in the specified node set
    输出当前节点或指定节点设置中首个节点的命名空间URI
    fn:lang(lang) Returns true if the language of the current node matches the language of the specified language
    如果当前节点语言与指定语言的语言相匹配则输出true

    Example举例: Lang("en") is true for
    <p xml:lang="en">...</p>

    Example举例: Lang("de") is false for
    <p xml:lang="en">...</p>

    fn:root()
    fn:root(node)
    Returns the root of the tree to which the current node or the specified belongs. This will usually be a document node
    输出树的根目录到当前节点或指定节点所属区域。这通常是文件节点。

    Functions on Sequences

    General Functions on Sequences
    序列函数

    Name
    名称
    Description
    描述
    fn:index-of((item,item,...),searchitem) Returns the positions within the sequence of items that are equal to the searchitem argument
    输出与searchitem自变量匹对的项序列的位置

    Example举例: index-of ((15, 40, 25, 40, 10), 40)
    Result结果: (2, 4)

    Example举例: index-of (("a", "dog", "and", "a", "duck"), "a")
    Result结果: (1, 4)

    Example举例: index-of ((15, 40, 25, 40, 10), 18)
    Result结果: ()

    fn:remove((item,item,...),position) Returns a new sequence constructed from the value of the item arguments - with the item specified by the position argument removed
    输出一个源于一个项目(item)自变量值的全新序列,从项自变量值中输出一个新序列结构(通过移除的位置自变量所指定的项) 

    Example举例: remove(("ab", "cd", "ef"), 0)
    Result结果: ("ab", "cd", "ef")

    Example举例: remove(("ab", "cd", "ef"), 1)
    Result结果: ("cd", "ef")

    Example举例: remove(("ab", "cd", "ef"), 4)
    Result结果: ("ab", "cd", "ef")

    fn:empty(item,item,...) Returns true if the value of the arguments IS an empty sequence, otherwise it returns false
    如果自变量值是空序列则输出true;反之为FALSE

    Example举例: empty(remove(("ab", "cd"), 1))
    Result结果: false

    fn:exists(item,item,...) Returns true if the value of the arguments IS NOT an empty sequence, otherwise it returns false
    如果自变量值不是空序列则输出true;反之为false

    Example举例: exists(remove(("ab"), 1))
    Result结果: false

    fn:distinct-values((item,item,...),collation) Returns only distinct (different) values
    只输出明显(不同)值

    Example举例: distinct-values((1, 2, 3, 1, 2))
    Result结果: (1, 2, 3)

    fn:insert-before((item,item,...),pos,inserts) Returns a new sequence constructed from the value of the item arguments - with the value of the inserts argument inserted in the position specified by the pos argument
    从项自变量值中输出一个新序列结构(插入自变量会插入pos自变量指定的区域)

    Example举例: insert-before(("ab", "cd"), 0, "gh")
    Result结果: ("gh", "ab", "cd")

    Example举例: insert-before(("ab", "cd"), 1, "gh")
    Result结果: ("gh", "ab", "cd")

    Example举例: insert-before(("ab", "cd"), 2, "gh")
    Result结果: ("ab", "gh", "cd")

    Example举例: insert-before(("ab", "cd"), 5, "gh")
    Result结果: ("ab", "cd", "gh")

    fn:reverse((item,item,...)) Returns the reversed order of the items specified
    输出指定项的倒序

    Example举例: reverse(("ab", "cd", "ef"))
    Result结果: ("ef", "cd", "ab")

    Example举例: reverse(("ab"))
    Result结果: ("ab")

    fn:subsequence((item,item,...),start,len) Returns a sequence of items from the position specified by the start argument and continuing for the number of items specified by the len argument. The first item is located at position 1
    从指定位置(由开始自变量和LEN自变量指定项数指定)输出项序列。首项是处于position 1.

    Example举例: subsequence(($item1, $item2, $item3,...), 3)
    Result结果: ($item3, ...)

    Example举例: subsequence(($item1, $item2, $item3, ...), 2, 2)
    Result结果: ($item2, $item3)

    fn:unordered((item,item,...)) Returns the items in an implementation dependent order
    按顺序输出一个执行程序中的项

    Functions That Test the Cardinality of Sequences
    基数序列测试函数

    Name
    名称
    Description
    描述
    fn:zero-or-one(item,item,...) Returns the argument if it contains zero or one items, otherwise it raises an error
    如果含有0或1项则输出自变量;反之则产生错误
    fn:one-or-more(item,item,...) Returns the argument if it contains one or more items, otherwise it raises an error
    如果含有1个或更多项则输出自变量;反之则产生错误
    fn:exactly-one(item,item,...) Returns the argument if it contains exactly one item, otherwise it raises an error
    如果含有精确项则输出自变量;反之产生错误

    Equals, Union, Intersection and Except
    等于、与、或、非

    Name
    名称
    Description
    描述
    fn:deep-equal(param1,param2,collation) Returns true if param1 and param2 are deep-equal to each other, otherwise it returns false
    如果param1和param2是同一级的则输出true反之输出false

    Aggregate Functions
    集合函数

    Name
    名称
    Description
    描述
    fn:count((item,item,...)) Returns the count of nodes
    输出节点计数
    fn:avg((arg,arg,...)) Returns the average of the argument values
    输出自变量值的平均值

    Example举例: avg((1,2,3))
    Result结果: 2

    fn:max((arg,arg,...)) Returns the argument that is greater than the others
    输出最大自变量

    Example举例: max((1,2,3))
    Result结果: 3

    Example举例: max(('a', 'k'))
    Result结果: 'k'

    fn:min((arg,arg,...)) Returns the argument that is less than the others
     输出最小自变量

    Example举例: min((1,2,3))
    Result结果: 1

    Example举例: min(('a', 'k'))
    Result结果: 'a'

    fn:sum(arg,arg,...) Returns the sum of the numeric value of each node in the specified node-set
    输出指定节点设置中的每个节点的数值总和

    Functions that Generate Sequences
    序列输出函数

    Name
    名称
    Description
    描述
    fn:id((string,string,...),node) Returns a sequence of element nodes that have an ID value equal to the value of one or more of the values specified in the string argument
    输出元素节点序列(含有与字符串自变量指定的一个或更多值相等的ID值)
    fn:idref((string,string,...),node) Returns a sequence of element or attribute nodes that have an IDREF value equal to the value of one or more of the values specified in the string argument
    输出元素或属性节点的序列(含有与字符串自变量指定的一个或更多值相等的IDREF值)
    fn:doc(URI)  
    fn:doc-available(URI) Returns true if the doc() function returns a document node, otherwise it returns false
    如果doc()函数返回一个文件节点则输出true;反之为false
    fn:collection()
    fn:collection(string)
     

    Context Functions

    Name
    名称
    Description
    描述
    fn:position() Returns the index position of the node that is currently being processed
    输出当前正在处理的节点索引位置

    Example举例: //book[position()<=3]
    Result结果: Selects the first three book elements

    fn:last() Returns the number of items in the processed node list
     输出处理节点列表中的数字项

    Example举例: //book[last()]
    Result结果: Selects the last book element

    fn:current-dateTime() Returns the current dateTime (with timezone)
    输出当前dateTime(通过时区timezone)
    fn:current-date() Returns the current date (with timezone)
    输出当前日期(通过时区timezone)
    fn:current-time() Returns the current time (with timezone)
    输出当前时间(通过时区timezone)
    fn:implicit-timezone() Returns the value of the implicit timezone
    输出固有(implicit)时区值
    fn:default-collation() Returns the value of the default collation
    输出默认校对值
    fn:static-base-uri() Returns the value of the base-uri
    输出base-uri值
  • 相关阅读:
    oracle数据表数据同步公用方法
    OSI参考模型详解
    DOM事件对象
    DOM事件流
    DOM之节点操作
    DOM之设置,获取,删除自定义的属性值
    JS修改元素的属性
    DOM获取元素以及绑定事件
    Web API
    JS中的简单数据类型和复杂数据类型
  • 原文地址:https://www.cnblogs.com/luoxiao/p/879234.html
Copyright © 2011-2022 走看看