XPath, XQuery, and XSLT Functions

Source: Internet
Author: User
Tags xslt xquery
Document directory
  • General functions
  • Function for testing sequence capacity
  • Equals, union, intersection and except T
  • Aggregate functions
  • Generation sequence Functions
Access Functions
Name Description
FN: node-Name (node) Return the node name of the parameter node.
FN: nilled (node) Returns the Boolean value of whether to reject the parameter node.
FN: Data (item. Item ,...) Accepts the project sequence and returns the sequence of Atomic values.
  • FN: Base-Uri ()
  • FN: Base-Uri (node)
Returns the base-Uri attribute value of the current or specified node.
FN: Document-Uri (node) Returns the value of the document-Uri attribute of the specified node.
Error and tracking 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: The http://example.com/test#toohigh and string "error: price is too high" are returned to the external processing environment ".

FN: trace (value, label) Debug the query.
Functions related to values
Name Description
FN: Number (ARG)

Returns the value of the parameter. The parameter can be a Boolean value, string, or node set.

Example: Number ('123 ')

Result: 100

FN: ABS (Num)

Returns the absolute value of a parameter.

Example: ABS (3.14)

Result: 3.14

Example: ABS (-3.14)

Result: 3.14

FN: ceiling (Num)

Returns the smallest integer smaller than the num parameter.

Example: ceiling (3.14)

Result: 4

FN: floor (Num)

Returns the maximum integer not greater than the num value.

Example: floor (3.14)

Result: 3

FN: round (Num)

Round the num parameter 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 related to strings
Name Description
FN: string (ARG)

Returns the string value of the parameter. Parameters can be numbers, logical values, or node sets.

For example, string (314)

Result: "314"

FN: codepoints-to-string (INT, Int ,...)

Returns a string based on the Code Point sequence.

Example: codepoints-to-string (84,104,233,114,232,115,101)

Result: 'thérè se'

FN: String-to-codepoints (string)

Returns the Code Point Sequence Based on the string.

Example: String-to-codepoints ("Thé rè se ")

Result: 84,104,233,114,232,115,101

FN: codepoint-equal (comp1, comp2) Based on Unicode code, if the value of comp1 is equal to the value of comp2, true is returned. (Http://www.w3.org/2005/02/xpath-functions/collation/codepoint), otherwise false is returned.
  • FN: Compare (comp1, comp2)
  • FN: Compare (comp1, comp2, collation)

If comp1 is smaller than comp2,-1 is returned. If comp1 is equal to comp2, 0 is returned. If comp1 is greater than comp2, 1 is returned. (Based on the rules used ).

Example: Compare ('ghi', 'ghi ')

Result: 0

FN: Concat (string, String ,...)

Returns the concatenation of strings.

Example: Concat ('xpath ', 'ais', 'fun! ')

Result: 'xpath is fun! '

FN: String-join (string, String,...), SEP)

Use the SEP parameter as the separator to return the string after the string parameter is spliced.

Example: String-join ('we', 'all', 'having ', 'fun! '),'')

Result: 'We are having fun! '

Example: String-join ('we', 'all', 'having ', 'fun! '))

Result: 'wearehavingfun! '

Example: String-join (), 'sept ')

Result :''

  • FN: substring (string, start, Len)
  • FN: substring (string, start)

Returns a substring of the specified length starting from the start position. The subscript of the first character is 1. If the Len parameter is omitted, the substring from the position start to the end of the string is returned.

Example: substring ('Beatles)

Result: 'beat'

Example: substring ('Beatles ', 2)

Result: 'eates'

FN: String-length (string) FN: String-length ()

Returns the length of the specified string. If the string parameter is not set, the length of the string value of the current node is returned.

Example: String-length ('Beatles ')

Result: 7

  • FN: normalize-space (string)
  • FN: normalize-space ()

Delete the white spaces at the beginning and end of the specified string, replace all the white spaces in the string with one, and return the result. If the string parameter is not specified, the current node is processed.

Example: normalize-space ('the xml ')

Result: 'The xml'

  • FN: normalize-Unicode ()
  • FN: upper-case (string)

Converts string to uppercase.

Example: upper-case ('the xml ')

Result: 'The xml'

FN: lower-case (string)

Converts string to lowercase.

Example: lower-case ('the xml ')

Result: 'The xml'

FN: translate (string1, string2, string3)

Replace string2 in string1 with string3.

Example: translate ('12: 30', '30', '45 ')

Result: '12: 45'

Example: translate ('12: 30', '03', '54 ')

Result: '12: 45'

Example: translate ('12: 30', '123', '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 % 2 ftest # Car"

Example: escape-Uri ("http://example.com/test#car", false ())

Result: "http://example.com/test#car"

Example: escape-Uri ("http://example.com /~ Bé ", false ())

Result: "http://example.com /~ B % C3 % a9b % C3 % A9"

FN: Contains (string1, string2)

If string1 contains string2, true is returned; otherwise, false is returned.

Example: Contains ('xml', 'xm ')

Result: True.

FN: starts-with (string1, string2)

If string1 starts with string2, true is returned; otherwise, false is returned.

Example: starts-with ('xml', 'x ')

Result: True.

FN: ends-with (string1, string2)

If string1 ends with string2, true is returned; otherwise, false is returned.

Example: ends-with ('xml', 'x ')

Result: false.

FN: substring-before (string1, string2)

Returns the substring before string2 appears in string1.

Example: substring-before ('20140901 ','/')

Result: '12'

FN: substring-after (string1, string2)

Returns the substring after string2 appears in string1.

Example: substring-after ('20140901 ','/')

Result: '10'

FN: matches (string, pattern)

If the string parameter matches the specified mode, true is returned; otherwise, false is returned.

Example: matches ("Merano", "ran ")

Result: True.

FN: Replace (string, pattern, replace)

Replace the specified mode with the replace parameter and return the result.

Example: Replace ("bella Italia", "L ","*")

Result: 'Be ** A ita *'

Example: Replace ("bella Italia", "L ","")

Result: 'bea itaa'

FN: tokenize (string, pattern)

Example: tokenize ("XPath is fun", "/S + ")

Result: ("XPath", "is", "fun ")

Functions for anyuri
Name Description
FN: resolve-Uri (relative, Base)  
Boolean Functions
Name Description
FN: Boolean (ARG) Returns the Boolean Value of a number, string, or node set.
FN: Not (ARG)

First, use the Boolean () function to restore the parameter to a Boolean value. If this Boolean value is false, true is returned; otherwise, true is returned.

Example: Not (true ())

Result: false.

FN: true ()

Returns a Boolean value of true.

Example: true ()

Result: True.

FN: false ()

Returns a Boolean value of false.

Example: false ()

Result: false.

Functions related to duration, date, and time

Date, time, and duration Component Extraction Function

Name Description
FN: datetime (date, time) Convert the parameter to date and time.
FN: years-from-duration (datetimedur) Returns an integer of the Year of the parameter value, expressed in standard vocabulary.
FN: months-from-duration (datetimedur) Returns the integer of the month part of the parameter value, expressed in standard vocabulary.
FN: days-from-duration (datetimedur) Returns an integer of the day part of the parameter value, expressed in standard vocabulary.
FN: hours-from-duration (datetimedur) Return the hour integer of the parameter value, expressed in standard vocabulary.
FN: Minutes-from-duration (datetimedur) Returns the minute integer of the parameter value, expressed in standard vocabulary.
FN: seconds-from-duration (datetimedur) Returns the minute decimal number of the parameter value, expressed in standard vocabulary.
FN: year-from-datetime (datetime)

Returns the year integer of the local value of the parameter.

Example: year-from-datetime (XS: datetime ("2005-01-10t12: 30-04:10 "))

Result: 2005

FN: month-from-datetime (datetime)

Returns the integer of the month part of the local value of the parameter.

Example: month-from-datetime (XS: datetime ("2005-01-10t12: 30-04:10 "))

Result: 01

FN: Day-from-datetime (datetime)

Returns the integer of the Day of the local value of the parameter.

Example: day-from-datetime (XS: datetime "))

Result: 10

FN: hours-from-datetime (datetime)

Returns the hour integer of the local value of the parameter.

Example: hours-from-datetime (XS: datetime (": 30 "))

Result: 12

FN: Minutes-from-datetime (datetime)

Returns the minute integer of the local value of the parameter.

Example: Minutes-from-datetime (XS: datetime "))

Result: 30

FN: seconds-from-datetime (datetime)

Returns the second decimal number of the local value of the parameter.

Example: seconds-from-datetime (XS: datetime "))

Result: 0

FN: timezone-from-datetime (datetime) Returns the time zone of the parameter, if any.
FN: year-from-date (date)

Return the year integer in the local value of the parameter.

Example: year-from-date (XS: date ("2005-04-23 "))

Result: 2005

FN: month-from-date (date)

Returns an integer representing the month in the local value of the parameter.

Example: month-from-date (XS: date ("2005-04-23 "))

Result: 4

FN: Day-from-date (date)

Returns an integer representing the day in the local value of the parameter.

Example: day-from-date (XS: date ("2005-04-23 "))

Result: 23

FN: timezone-from-date (date) Returns the time zone of the parameter, if any.
FN: hours-from-time (time)

Returns the integer that represents the hour in the local value of the parameter.

Example: hours-from-time (XS: Time ("10:22:00 "))

Result: 10

FN: Minutes-from-time (time)

Returns an integer that represents the minute in the local value of the parameter.

Example: Minutes-from-time (XS: Time ("10:22:00 "))

Result: 22

FN: seconds-from-time (time)

Returns the integer that represents the second in the local value of the parameter.

Example: seconds-from-time (XS: Time ("10:22:00 "))

Result: 0

FN: timezone-from-time (time) Returns the time zone of the parameter, if any.
FN: Adjust-datetime-to-timezone (datetime, timezone) If the timezone parameter is null, datetime without the time zone is returned. Otherwise, datetime with the time zone is returned.
FN: Adjust-date-to-timezone (date, timezone) If the timezone parameter is null, a date without a time zone is returned. Otherwise, a date with a time zone is returned.
FN: Adjust-Time-to-timezone (time, timezone) If the timezone parameter is null, time without the time zone is returned. Otherwise, return the time with the time zone.
Qnames-related functions
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 ()  
Node functions
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.
FN: Lang (Lang)

Returns true if the language of the current node matches the specified language.

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 node of the node tree to which the current node or specified node belongs. It is usually a document node.
General functions related to Sequences
Name Description
FN: Index-of (item, item,...), searchitem)

Returns the position in the project sequence that is equal to the searchitem parameter.

Example: Index-of (15, 40, 25, 40, 10), 40)

Result: (2, 4)

Example: Index-of ("A", "dog", "and", "A", "Duck"), "")

Result (1, 4)

Example: Index-of (15, 40, 25, 40, 10), 18)

Result :()

FN: Remove (item, item,...), position)

Return the new sequence constructed by the item parameter-delete the item specified by the position parameter at the same time.

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 ,...)

If the parameter value is an empty sequence, true is returned; otherwise, false is returned.

Example: Empty (remove ("AB", "cd"), 1 ))

Result: false.

FN: exists (item, item ,...)

If the parameter value is not an empty sequence, true is returned; otherwise, false is returned.

Example: exists (remove ("AB"), 1 ))

Result: false.

FN: distinct-values (item, item,...), collation)

Returns a unique value.

Example: distinct-values (1, 2, 3, 1, 2 ))

Result: (1, 2, 3)

FN: insert-before (item, item,...), POs, inserts)

Return the new sequence constructed by the item parameter-insert the value of the inserts parameter at the specified position of the POs parameter.

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 reverse order of the specified project.

Example: reverse ("AB", "cd", "Ef "))

Result: ("Ef", "cd", "AB ")

Example: reverse ("AB "))

Result: ("AB ")

FN: subsequence (item, item,...), start, Len)

Return the project sequence at the position specified by the start parameter. The length of the sequence is specified by the Len parameter. The first project is located at 1.

Example: subsequence ($ Item1, $ item2, $ item3,...), 3)

Result: ($ item3 ,...)

Example: subsequence ($ Item1, $ item2, $ item3,...), 2, 2)

Result: ($ item2, $ item3)

FN: unordered (item, item ,...)) Return the project in the order determined by implementation.
Function for testing sequence capacity
Name Description
FN: Zero-or-one (item, item ,...) If the parameter contains zero or one project, a parameter is returned. Otherwise, an error is generated.
FN: one-or-more (item, item ,...) If the parameter contains one or more items, a parameter is returned. Otherwise, an error is generated.
FN: Exactly-one (item, item ,...) If the parameter contains a project, a parameter is returned. Otherwise, an error is generated.
Equals, union, intersection and except T
Name Description
FN: Deep-equal (param1, param2, collation) If param1 and param2 are equal to each other (deep-equal), true is returned; otherwise, false is returned.
Aggregate functions
Name Description
FN: Count (item, item ,...)) Number of returned nodes.
FN: AVG (ARG, ARG ,...)) Returns the average of the parameter values. Example: AVG (1, 2, 3) Result: 2
FN: max (ARG, ARG ,...)) Return parameters greater than other parameters. Example: max (1, 2, 3) Result: 3 Example: max ('A', 'k') Result: 'K'
FN: min (ARG, ARG ,...)) Return parameters smaller than other parameters. Example: min (1, 2, 3) Result: 1 Example: min ('A', 'k') Result: 'A'
FN: sum (ARG, ARG ,...) Returns the sum of the values of each node in the specified node set.
Generation sequence Functions
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
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
FN: DOC (URI)  
FN: Doc-available (URI) If the DOC () function returns the document node, true is returned; otherwise, false is returned.
  • FN: Collection ()
  • FN: Collection (string)
 
Context Functions
Name Description
FN: Position ()

Returns the index position of the node being processed.

Example: // book [position () <= 3]

Result: select the first three book elements.

FN: Last ()

Returns the number of projects in the List of processed nodes.

Example: // book [last ()]

Result: select the last book element.

FN: Current-datetime () Returns the current datetime with the time zone ).
FN: Current-date () Returns the current date (with the time zone ).
FN: current-time () Returns the current time (with a time zone ).
FN: Implicit-timezone () Returns the value of the implicit time zone.
FN: default-collation () Returns the default contrast value.
FN: static-base-Uri () Returns the value of base-Uri.

 

 

Refer:

Http://www.w3school.com.cn/xpath/xpath_functions.asp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.