Nonstop Database, HiRDB Version 9 SQL Reference

[Contents][Index][Back][Next]

1.15.8 XQuery functions

This section describes the XQuery functions provided by HiRDB.

Arguments are described in the format of each XQuery function. They are passed as parameters to that XQuery function according to the XQuery function invocation rules. For details about the rules of XQuery function invocation, see 1.15.6(15)(g) XQuery function invocation.

XQuery functions include functions defined in XQuery and functions defined in HiRDB.

Functions defined in XQuery use the XML namespace that is bound to the prefix xs (http://www.w3.org/2001/XMLSchema) or the XML namespace that is bound to the prefix fn (http://www.w3.org/2006/xpath-functions).

Functions defined in HiRDB use the XML namespace that is bound to the prefix hi-fn (http://www.hitachi.co.jp/Prod/comp/soft1/hirdb/xquery-functions). When functions defined in HiRDB are called, unless the default XML namespace for XQuery function names is declared as http://www.hitachi.co.jp/Prod/comp/soft1/hirdb/xquery-functions, the prefix must be specified.

For details about the constructor function, see 1.15.2(3)(b) Constructor function.

The following table lists the XQuery functions available in HiRDB.

Table 1-98 XQuery functions provided in HiRDB

Classification Function Purpose XQuery function category
Constructor function xs:string Generate a value of type xs:string. XQuery
xs:decimal Generate a value of type xs:decimal. XQuery
xs:int Generate a value of type xs:int. XQuery
xs:double Generate a value of type xs:double. XQuery
xs:dateTime Generate a value of type xs:dateTime. XQuery
xs:date Generate a value of type xs:date. XQuery
xs:time Generate a value of type xs:time. XQuery
xs:hexBinary Generate a value of type xs:hexBinary. XQuery
xs:boolean Generate a value of type xs:boolean. XQuery
xs:untypedAtomic Generate a value of type xs:untypedAtomic. XQuery
Conversion functions fn:boolean Return the result of evaluating the XQuery sequence as a value of the xs:boolean type. XQuery
fn:data Atomize an XQuery sequence and return an XQuery sequence consisting of atomic values. XQuery
fn:number Return the result of converting the value specified in the argument to xs:double type. XQuery
fn:string Return the character string representation of the value of the XQuery item as an xs:string type value. XQuery
Character string operation functions fn:compare Compare two character strings. XQuery
fn:concat Return the result of concatenating two or more atomic values that have been converted to an xs:string type value. XQuery
fn:contains(function defined in XQuery) Return whether or not the character string specified in argument-2 is part of the character string specified in argument-1. XQuery
hi-fn:contains(function defined in HiRDB) Return whether or not the character string value of the node specified in argument-1 satisfies the full-text search conditions specified in argument-2. HiRDB
fn:ends-with Return whether or not the character string specified in argument-1 ends with the character string specified in argument-2. XQuery
fn:normalize-space Return the result of normalizing whitespace in a character string. XQuery
fn:starts-with Return whether or not the character string specified in argument-1 starts with the character string specified in argument-2. XQuery
fn:string-length Return the length (in number of characters) of the character string. XQuery
fn:substring Return a substring of a character string. XQuery
fn:substring-after Return a substring of the character string specified in argument-1 that begins immediately after the position of the first occurrence of the character string specified in argument-2. XQuery
fn:substring-before Return a substring of the character string specified in argument-1 that ends immediately before the position of the first occurrence of the character string specified in argument-2. XQuery
fn:translate Return the result of replacing the characters specified in argument-2 with the characters specified in argument-3 in the character string specified in argument-1. XQuery
Math functions fn:abs Return the absolute value of a numeric data type value. XQuery
fn:ceiling Return the smallest integer value that is greater than or equal to an argument. XQuery
fn:floor Return the greatest integer value that is less than or equal to an argument. XQuery
fn:round Return the integer value closest to the value of an argument. XQuery
Date extraction functions fn:year-from-dateTime Return only the year part extracted from the time stamp. XQuery
fn:month-from-dateTime Return only the month part extracted from the time stamp. XQuery
fn:day-from-dateTime Return only the day part extracted from the time stamp. XQuery
fn:hours-from-dateTime Return only the hours part extracted from the time stamp. XQuery
fn:minutes-from-dateTime Return only the minutes part extracted from the time stamp. XQuery
fn:seconds-from-dateTime Return only the seconds part extracted from the time stamp. XQuery
fn:year-from-date Return only the year part extracted from the date. XQuery
fn:month-from-date Return only the month part extracted from the date. XQuery
fn:day-from-date Return only the day part extracted from the date. XQuery
fn:hours-from-time Return only the hours part extracted from the time. XQuery
fn:minutes-from-time Return only the minutes part extracted from the time. XQuery
fn:seconds-from-time Return only the seconds part extracted from the time. XQuery
Boolean functions fn:false Return FALSE. XQuery
fn:not Convert an argument to the xs:boolean type and return the negation of its value. XQuery
fn:true Return TRUE. XQuery
XQuery sequence aggregation functions fn:count Return the number of XQuery items in an XQuery sequence. XQuery
fn:distinct-values Return an XQuery sequence consisting of atomic values with duplicates removed. XQuery
fn:max Return the largest value of the atomic values that make up an XQuery sequence. XQuery
fn:min Return the smallest value of the atomic values that make up an XQuery sequence. XQuery
fn:sum Return the sum of the atomic values that make up an XQuery sequence. XQuery
XQuery sequence operation functions fn:deep-equal Determine whether two XQuery sequences are deep-equal. XQuery
fn:index-of Return the positions in the specified XQuery sequence of all occurrences of the XQuery items that match the specified atomic value. XQuery
fn:insert-before Return the XQuery sequence that results from inserting an XQuery item before the specified position in an XQuery sequence. XQuery
fn:remove Return the XQuery sequence that results from removing the XQuery item at the specified position in the XQuery sequence. XQuery
fn:reverse Return the XQuery sequence that results from sorting the XQuery items in an XQuery sequence in reverse order. XQuery
fn:subsequence Return an XQuery subsequence of an XQuery sequence. XQuery
Context item functions fn:last Return the context size. XQuery
fn:position Return the context position. XQuery
Node functions fn:local-name Return the local name of a node. XQuery
fn:name Return the qualified name of a node. XQuery
fn:namespace-uri Return the XML namespace URI of the qualified name of a node. XQuery

Legend:
XQuery: Function defined in XQuery
HiRDB: Function defined in HiRDB
Organization of this subsection
(1) abs
(2) boolean
(3) ceiling
(4) compare
(5) concat
(6) contains (Function defined in XQuery)
(7) contains (function defined in HiRDB)
(8) count
(9) data
(10) day-from-date
(11) day-from-dateTime
(12) deep-equal
(13) distinct-values
(14) ends-with
(15) false
(16) floor
(17) hours-from-dateTime
(18) hours-from-time
(19) index-of
(20) insert-before
(21) last
(22) local-name
(23) max
(24) min
(25) minutes-from-dateTime
(26) minutes-from-time
(27) month-from-date
(28) month-from-dateTime
(29) name
(30) namespace-uri
(31) normalize-space
(32) not
(33) number
(34) position
(35) remove
(36) reverse
(37) round
(38) seconds-from-dateTime
(39) seconds-from-time
(40) starts-with
(41) string
(42) string-length
(43) subsequence
(44) substring
(45) substring-after
(46) substring-before
(47) sum
(48) translate
(49) true
(50) year-from-date
(51) year-from-dateTime

(1) abs

(a) Function

Returns the absolute value of a numeric data type value.

(b) Format
 
fn:abs ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-99 fn:abs function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument num Numeric data type
    (including empty XQuery sequences)
    Input numeric value
  2. The result is an empty XQuery sequence or a value of one of the following numeric data types:

    Table 1-100 XQuery data type of the result of the fn:abs function

    No. XQuery data type of the value of the parameter num XQuery data type of the result
    1 xs:double xs:double
    2 xs:decimal xs:decimal
    3 xs:int xs:int
    An error results if the absolute value falls outside the range of the resulting XQuery data type. For example, if fn:abs(-2147483648) is specified, an error results because the absolute value is 2147483648, which is outside the range for xs:int.
  3. If the value of the parameter num is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter num is a numeric data type value, the absolute value of the value of the parameter num is returned.
  5. If the value of the parameter num is the xs:double type NaN (not a number), NaN is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:abs(10.5) 10.5 (xs:decimal) Returns 10.5, the absolute value of 10.5.
2 fn:abs(-10.5) 10.5 (xs:decimal) Returns 10.5, the absolute value of -10.5.

(2) boolean

(a) Function

Returns the result of evaluating an XQuery sequence as an xs:boolean type value.

(b) Format
 
fn:boolean ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-101 fn:boolean function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more arbitrary XQuery items Input XQuery sequence
  2. The result is an xs:boolean type value.
  3. Returns the result indicated in the following table depending on the XQuery sequence that is specified by the parameter seq.

    Table 1-102 Results of the fn:boolean function

    No. Value of the parameter seq Result (xs:boolean type)
    1 Empty XQuery sequence FALSE
    2 XQuery sequence in which the first XQuery item is a node TRUE
    3 XQuery sequence consisting of one xs:boolean type atomic value Atomic value of the XQuery sequence argument
    4 XQuery sequence consisting of one xs:string type or xs:untypedAtomic type atomic value FALSE if the atomic value of the XQuery sequence argument has length 0, otherwise TRUE.
    5 XQuery sequence consisting of one numeric data type atomic value FALSE if the atomic value of the XQuery sequence argument is 0 or NaN (not a number), otherwise TRUE.
    6 Other than the above Error
(d) Example

Below are examples of function invocations and their results when the XQuery variable book indicates the node representing the elements shown below.

Element represented by the XQuery variable book:

<bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo>

Examples of function invocations and their results:

No. Function invocation Result
(xs:boolean type)
Explanation
1 $book/fn:boolean(author[text() = "Mark Davis"]) FALSE Returns FALSE because the value of the parameter seq is an empty XQuery sequence.
2 fn:boolean($book) TRUE Returns TRUE because the value of the parameter seq is an XQuery sequence consisting of one element node bookinfo.
3 $book/fn:boolean(@book_id = 452469630) TRUE Returns TRUE because the value of the parameter seq is an XQuery sequence consisting of one xs:boolean type value.
4 $book/fn:boolean(title/fn:string(text())) TRUE Returns TRUE because the value of the parameter seq is an XQuery sequence consisting of one xs:string type value of length 1 or greater.
5 $book/fn:boolean(@book_id) TRUE Returns TRUE because the value of the parameter seq is an XQuery sequence consisting of one numeric data value.
6 $book/fn:boolean(author/fn:string(text())) Error Error because the value of the parameter seq is an XQuery sequence consisting of two xs:string type values.

(3) ceiling

(a) Function

Returns the smallest integer value that is greater than or equal to an argument.

(b) Format
 
fn:ceiling ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-103 fn:ceiling function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument num Numeric data type
    (including empty XQuery sequences)
    Input numeric value
  2. The result is an empty XQuery sequence, or a value of one of the numeric data types below.

    Table 1-104 XQuery data type of the result of the fn:ceiling function

    No. XQuery data type of the value of the parameter num XQuery data type of the result
    1 xs:double xs:double
    2 xs:decimal xs:decimal
    3 xs:int xs:int
  3. If the value of the parameter num is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. The following table describes what is returned when the parameter num is xs:double type and it's value is one of the following special values.

    Table 1-105 fn:ceiling function special values result

    No. Value of the parameter num Result value
    1 Positive 0 Positive 0
    2 Negative 0 Negative 0
    3 Greater than -1 and less than 0 Negative 0
    4 Positive infinity Positive infinity
    5 Negative infinity Negative infinity
    6 NaN (not a number) NaN (not a number)
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:ceiling(10.5) 11. (xs:decimal) Returns 11, which is the integer value that is greater than or equal to 10.5.
2 fn:ceiling(-10.5) -10. (xs:decimal) Returns -10, which is the integer value that is greater than or equal to -10.5.

(4) compare

(a) Function

Returns the result of comparing two character strings.

(b) Format
 
fn:compare ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-106 fn:compare function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string to compare
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Character string to compare
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of either parameter str1 or str2 is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If parameters str1 and str2 are xs:string type values, the result shown below based on the relationship between the values of parameters str1 and str2 is returned.

    Table 1-107 Results of the fn:compare function

    No. Relationship between the values of parameters str1 and str2 Result (xs:int type)
    1 Value of parameter str1 is less than the value of parameter str2 (str1 lt str2 is TRUE) -1
    2 Value of parameter str1 is equal to the value of parameter str2 (str1 eq str2 is TRUE) 0
    3 Value of parameter str1 is greater than the value of parameter str2 (str1 gt str2 is TRUE) 1
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result
(xs:int type)
Explanation
1 fn:compare("abcde", "abcdef") -1 Returns -1 because "abcde" is less than "abcdef".
2 fn:compare("abcde", "abcde") 0 Returns 0 because the values of parameters str1 and str2 are both "abcde".
3 fn:compare("abcde", "abade") 1 Returns 1 because "abcde" is greater than "abade".

(5) concat

(a) Function

Returns the result of concatenating two or more atomic values that have been converted to an xs:string type value.

(b) Format
 
fn:concat ( argument, argument [, argument]... )
 
(c) Rules
  1. This function takes any number (two or more) of the parameter shown below.

    Table 1-108 fn:concat function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument val Any atomic type
    (including empty XQuery sequences)
    Atomic value to concatenate
  2. The result is an empty XQuery sequence or an xs:string type value.
  3. If the value of every parameter is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If at least one parameter with atomic value is included, those values are converted to xs:string type values, and an xs:string type value that is the result of concatenating them in the specified order is returned. In this case, the value of any parameter that is an empty XQuery sequence is treated as a character string of length zero.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result
(xs:string type)
Explanation
1 fn:concat("abc","defg") "abcdefg" Returns the character string "abcdefg", which is the concatenation of "abc" and "defg".
2 fn:concat("hijk", (), "lmn") "hijklmn" Returns the character string "hijklmn", which is the concatenation of "hijk", "", and "lmn", because an empty XQuery sequence is treated as a character string of length zero.
3 fn:concat((),(),()) Empty XQuery sequence Returns an empty XQuery sequence because the value of every parameter is an empty XQuery sequence.

(6) contains (Function defined in XQuery)

(a) Function

Returns a value indicating whether the character string specified in argument-2 is part of the character string specified in argument-1.

(b) Format
 
fn:contains ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-109 fn:contains function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string in which to find the substring
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Substring to find within the character string in parameter str1
  2. The result is an xs:boolean type value.
  3. Returns FALSE if the value of parameter str1 is an empty XQuery sequence or a character string of length zero, and the value of parameter str2 is a character string of length 1 or greater.
  4. If the value of parameter str2 is an empty XQuery sequence or a character string of length zero, TRUE is returned regardless of the value of parameter str1.
  5. When the values of parameters str1 and str2 are character strings of length 1 or greater, TRUE is returned if the character string in parameter str2 is found in the character string in parameter str1, and returns FALSE if it is not found.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result
(xs:boolean type)
Explanation
1 fn:contains("abcdefg", "cde") TRUE Returns TRUE because "cde" is part of "abcdefg".
2 fn:contains("abcdefg", "cdf") FALSE Returns FALSE because "cdf" is not part of "abcdefg".
3 fn:contains((), "") TRUE Returns TRUE because the value of parameter str2 is a character string of length zero.
4 fn:contains((), "a") FALSE Returns FALSE because the value of parameter str1 is an empty XQuery sequence, and the value of parameter str2 is a character string of length 1 or greater.
5 fn:contains("abcdefg", ()) TRUE Returns TRUE because the value of parameter str2 is an empty XQuery sequence.

(7) contains (function defined in HiRDB)

(a) Function

Returns a value indicating whether the character string value of the node specified in argument-1 satisfies the full-text search conditions specified in argument-2.

(b) Format
 
hi-fn:contains ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-110 hi-fn:contains function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq XQuery sequence with zero or more nodes Nodes to search
    2 argument-2 str xs:string type Full-text search conditions character string
  2. The result is an xs:boolean type value.
  3. This function can be used only in the XMLEXISTS predicate.
  4. When this function is used, an XML type full-text search index must be defined on the column specified in the XML query context item. In addition, version 08-04 or later of the HiRDB XML Extension must be used.
  5. A substructure path that conforms to the usage conditions of the XML type full-text search index must be specified in parameter seq. An error results if they do not conform, or if the index alone cannot be used to evaluate the criteria. For details about the usage conditions for the XML type full-text search index, see the HiRDB Version 9 Installation and Design Guide.
  6. The full-text search conditions are specified as an XQuery character string literal in parameter str. The search conditions shown below can be specified as text search conditions. An error results if the value of the parameter str is a character string of length zero, or if it does not follow the format of the text search conditions. For details about how to specify text search conditions, see the manual HiRDB Version 9 XML Extension.

    Table 1-111 Search conditions that can be specified as text search conditions

    No. Search conditions Summary Example
    1 Simple character string conditions Search for character strings that match a search string that contains special characters, or any of the following wildcards:
    • *
      Equivalent to any character string of zero or more characters.
    • ?
      Equivalent to any one character.
    • |
      Matches the beginning or end of the construction.
    • \
      Turn off the wildcard or special character meaning.
    The character string to search for is enclosed in double quotation marks ("). However, if an XQuery character string literal is to be enclosed in double quotation marks, either enclose it in &quot; or code two consecutive double quotation marks.

    • Character strings that contain any character string of zero or more characters between network and computer
      "network*computer"
    • Character strings that contain any one character between network and computer
      "network?computer"
    • Character strings that start with network
      "|network"
    2 Excluded character search conditions Search while excluding a particular character in the middle or at the ends of the search string from simple character string conditions. A ^ is specified before the character to exclude.
    • From character strings that contain plan followed by any one character, exclude any character strings that contain plant
      "plan^t"
    • From character strings that contain any one character between do and key, exclude any character strings that contain donkey
      "do^nkey"
    • From character strings that contain round preceded by any one character, exclude any character strings that contain around
      "^around"
    3 NOT conditions Search for character strings that do not contain the search string.
    • Character strings that do not contain network
      NOT ("network")
    4 AND/OR conditions Specify multiple search conditions linked with AND or OR.
    • Character strings that contain both network and computer
      "network" AND "computer"
      Character strings that contain either network or computer
      "network" OR "computer"
    5 Proximity conditions Specify the number of characters (distance) between two character strings matching two search conditions.
    • Character strings with no more than 20 characters between new and technology (no particular order)
      PROXIMITY("new", <=20#1, CHARACTERS#2,ANY_ORDER#3,"technology#4")
    6 Synonym expansion conditions Automatically expand the search string to include synonyms based on the definitions in a synonym dictionary. For details about how to create and register a synonym dictionary, see the manual HiRDB Version 9 XML Extension. Character strings that contain a synonym of COMPUTER (including different alphabetical and one- and two-byte representations)
    SYNONYM(USR01#4, "COMPUTER", "AE#5")
    7 Representation expansion conditions Automatically expand the search string to include different representations based on rules.
    • Character strings that include the character string COMPUTER represented in various alphabetical and one- and two-byte representations
      SOUNDEX_EXP("COMPUTER", "AE"#5)
    • Character strings that include any character string representing a derivation of the English word sing
      SOUNDEX_EXP("sing", "S"#6)

    #1
    Means the search is performed with the distance less than or equal to 20.

    #2
    Means that the unit of distance is characters.

    #3
    Means no particular order.

    #4
    Refers to the name of the synonym dictionary.

    #5
    A means different alphabetic representations, E means different one- and two-byte representations.

    #6
    Refers to representations of the derivations of English words.

  7. Returns FALSE if the value of the parameter seq is an empty XQuery sequence.
  8. Returns TRUE if at least one character string value among the character string values of the nodes in the XQuery sequence in parameter seq includes the character string represented by the text search conditions in parameter str. Returns FALSE if none of the character string values contains the character string represented by the text search conditions.
(d) Example

In the examples of function invocations and their results given below, the XML document shown below is represented by values in columns (on which an XML type full-text search index is defined) specified in XML query context items.

XML document represented by the values stored in the columns specified in XML query context items:

<bookinfo book_id="452469630">
  <category>database</category>
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
  <description>Explains the structure of the RDBMS (Relational Database Management System) based on the concept of the relational model.</description>
</bookinfo>

Examples of function invocations and their results:

No. Function invocation Result (xs:boolean type) Explanation
1 /bookinfo/title[
hi-fn:contains(text(),
"SYNONYM(USR01, &quot;DB&quot;)")]
TRUE Suppose "database" and "DB" are registered as synonyms in synonym dictionary USR01. Returns TRUE because in the value of the parameter seq there is a node containing "database", which is a synonym of "DB".
2 /bookinfo/description[
hi-fn:contains(text(),
"SOUNDEX_EXP(&quot;DATABASE&quot;,
&quot;AE&quot;) AND
&quot;Explain&quot;")]
TRUE Returns TRUE because the value of the parameter seq includes a node that contains both "Explain" and "Database", which is an alphabetic variant of "DATABASE".
3 /bookinfo/author[
hi-fn:contains(text(),
"&quot;Smith&quot;")]
FALSE Returns FALSE because there is no node containing "Smith" in the value of the parameter seq.
4 /bookinfo/contents[
hi-fn:contains(text(),
"SYNONYM(USR01,
&quot;DB&quot;)")]
FALSE Returns FALSE because the parameter seq is an empty XQuery sequence.

(8) count

(a) Function

Returns the number of XQuery items in an XQuery sequence.

(b) Format
 
fn:count ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-112 fn:count function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more arbitrary XQuery items Input XQuery sequence
  2. The result is an xs:int type value.
(d) Example

In the examples of function invocations and their results given below, the XQuery variable book indicates the node representing the elements shown below.

Element represented by the XQuery variable book:

<bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo>

Examples of function invocations and their results:

No. Function invocation Result (xs:int type) Explanation
1 fn:count($book) 1 Returns 1 because the value of the parameter seq is an XQuery sequence consisting of one bookinfo element node.
2 fn:count($book/author) 2 Returns 2 because the value of the parameter seq is an XQuery sequence consisting of two author element nodes that are children of the bookinfo element node.
3 fn:count($book/author[.="Mark Davis"]) 0 Returns 0 because the value of the parameter seq is an empty XQuery sequence.

(9) data

(a) Function

Atomizes an XQuery sequence and returns an XQuery sequence consisting of atomic values.

(b) Format
 
fn:data ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-113 fn:data function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more arbitrary XQuery items Input XQuery sequence
  2. The result is an empty XQuery sequence or an XQuery sequence consisting of atomic values.
  3. If the value of the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter seq is not an empty XQuery sequence, the XQuery sequence consisting of the results of applying the following rules to each XQuery item in that XQuery sequence is returned.
    • If the XQuery item is an atomic value, that value will be the result.
    • If the XQuery item is a node, the result will be the value listed in the following table, depending on the kind of node.

      Table 1-114 Results when the XQuery item is a node

      No. Kind of node Result
      1 Document node Value of the typed-value property
      2 Element node Value of the typed-value property
      3 Attribute node Value of the typed-value property
      4 Processing instruction node Empty XQuery sequence
      5 Comment node Empty XQuery sequence
      6 Text node Value of converting the value of the content property to xs:untypedAtomic type
(d) Example

In the examples of function invocations and their results given below, the XQuery variable book indicates the node representing the elements shown below.

Element represented by the XQuery variable book:

<bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo>

Examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:data($book/price) Empty XQuery sequence Returns an empty XQuery sequence because the value of the parameter seq is an empty XQuery sequence.
2 fn:data($book/author) ("Jeff Jones","Bob Adams") Returns the XQuery sequence consisting of the two typed-value property values because the parameter seq is an XQuery sequence consisting of two author element nodes.

(10) day-from-date

(a) Function

Returns only the day part extracted from the date.

(b) Format
 
fn:day-from-date ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-115 fn:day-from-date function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dat xs:date type
    (including empty XQuery sequences)
    Date to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dat is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter dat is an xs:date type value, the value of the day part as an xs:int type is returned.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:day-from-date (xs:date("2006-09-26")) 26 Returns 26, which is the day part of the value of the parameter dat.

(11) day-from-dateTime

(a) Function

Returns only the day part extracted from the time stamp.

(b) Format
 
fn:day-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-116 fn:day-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter dtm is an xs:dateTime type value, the value of the day part as an xs:int type is returned.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:day-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 26 Returns 26, which is the day part of the value of the parameter dtm.

(12) deep-equal

(a) Function

Determines whether two XQuery sequences are deep-equal (have the same structure and the same values).

(b) Format
 
fn:deep-equal ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-117 fn:deep-equal function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq1 XQuery sequence of zero or more arbitrary XQuery items XQuery sequence to compare
    2 argument-2 seq2 XQuery sequence of zero or more arbitrary XQuery items XQuery sequence to compare
  2. The result is an xs:boolean type value.
  3. If parameters seq1 and seq2 are both empty XQuery sequences, the result is TRUE.
  4. If the number of XQuery items in parameter seq1 and the number of XQuery items in parameter seq2 are different, the result is FALSE.
  5. If all of the XQuery items that make up parameter seq1 are in the same position and all are deep-equal to the XQuery items that make up parameter seq2, the result is TRUE, but if there is even one XQuery item for which this not true, it is FALSE.
    Whether two XQuery items are deep-equal is determined by the rules shown below.
    Let item1 and item2 be the two XQuery items.

    Table 1-118 XQuery item deep-equal rules

    No. Category of item1 Category of item2 Rules
    1 Atomic value Atomic value TRUE only if all of the following conditions are met:
    1. The XQuery data types of item1 and item1 can be compared with the eq operator.
    2. (item1 eq item2) is TRUE, or item1 and item2 are both xs:double type with the value NaN (not a number).
    2 Other than the above FALSE
    3 Document node Document node TRUE only if the fn:deep-equal function is TRUE for the XQuery sequence of element and text nodes that are children of item1 and the XQuery sequence of element and text nodes that are children of item2.
    4 Other than the above FALSE
    5 Element node Element node TRUE only if all of the following conditions are met:
    1. The namespaces and node names of the two element nodes match.
    2. item1 and item2 have the same number of attribute nodes, and each attribute node of item1 is deep-equal to the corresponding attribute node of item2.
      In this case, the order of attribute nodes for item1 and the order of attribute nodes for item1 need not be the same.
    3. The fn:deep-equal function is TRUE for the XQuery sequence of element node and text node children of item1 and the XQuery sequence of element node and text node children of item2.
    6 Other than the above FALSE
    7 Attribute node Attribute node TRUE only if all of the following conditions are met:
    1. The namespaces and node names of the two attribute nodes match.
    2. The typed-value of item1 and the typed-value of item2 are deep-equal.
    8 Other than the above FALSE
    9 Processing instruction node Processing instruction node TRUE only if all of the following conditions are met:
    1. The processing instruction targets of the two processing instruction nodes match.
    2. The contents of item1 and the contents of item2 are deep-equal.
    10 Other than the above FALSE
    11 Text node Text node TRUE only if the character string values of the two text nodes are deep-equal.
    12 Other than the above FALSE.
    13 Comment node Comment node TRUE only if the character string values of the two comment nodes are deep-equal.
    14 Other than the above FALSE
(d) Example

In the examples of function invocations and their results given below, the XQuery variable books indicates the node representing the elements shown below.

Element represented by the XQuery variable books:

<booklist>
  <bookinfo book_id="452469630">
    <title>Relational Databases Explained</title>
    <author>Bob Adams</author>
    <author>Jeff Jones</author>
  </bookinfo>
  <bookinfo book_id="45241350">
    <title>Relational Databases Explained Vol. 2</title>
    <author>Bob Adams</author>
    <author>Jeff Jones</author>
  </bookinfo>
</booklist>

Examples of function invocations and their results:

No. Function invocation Result
(xs:boolean type)
Explanation
1 fn:deep-equal(
$books/bookinfo[1]/title, "Relational Databases Explained")
FALSE FALSE because the parameter seq1 is an XQuery sequence of one element node, and parameter seq2 is an XQuery sequence of a single atomic value.
2 fn:deep-equal($books/bookinfo[1], $books/bookinfo[2]) FALSE FALSE because although parameters seq1 and seq2 are both XQuery sequences of one bookinfo element node, their book_id attribute nodes are not deep-equal and their child title elements are not deep-equal.
3 fn:deep-equal($books/bookinfo[1]/author, $books/bookinfo[2]/author) TRUE TRUE because parameters seq1 and seq2 are both XQuery sequences with two author element nodes, and those author element nodes are deep-equal.

(13) distinct-values

(a) Function

Returns an XQuery sequence consisting of atomic values with duplicates removed.

(b) Format
 
fn:distinct-values ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-119 fn:distinct-values function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more values of any atomic type Input XQuery sequence
  2. The result is an empty XQuery sequence or an XQuery sequence consisting of atomic values only.
  3. If the value of the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. To decide whether atomic values are duplicates, the values are compared using the eq operator. If values cannot be compared to each other with the eq operator or their comparison result is FALSE, they are not considered duplicates. If the comparison result is TRUE, they are considered duplicates, and one of them is removed.
  5. If the XQuery sequence that is the value of the parameter seq contains more than one xs:double type NaN (not a number), all but one of them will be removed.
  6. The order of the XQuery items in the resulting XQuery sequence is not guaranteed to match the order of the XQuery items in the XQuery sequence that is the value of the parameter seq.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result Explanation
1 fn:distinct-values(("a", 1, "A", 0, 1)) ("a", 1, "A", 0)
Order may vary.
The duplicate 1 is removed from the XQuery sequence that is the value of the parameter seq.

(14) ends-with

(a) Function

Returns a value indicating whether the character string specified in argument-1 ends with the character string specified in argument-2.

(b) Format
 
fn:ends-with ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-120 fn:ends-with function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string to be checked to see whether it ends with the substring
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Substring to check against the end of the character string in parameter str1
  2. The result is an xs:boolean type value.
  3. Returns FALSE if the value of parameter str1 is an empty XQuery sequence or a character string of length zero and the value of parameter str2 is a character string of length 1 or greater.
  4. If the value of parameter str2 is an empty XQuery sequence or a character string of length zero, TRUE is returned regardless of the value of parameter str1.
  5. Returns TRUE if the values of parameters str1 and str2 are character strings of length 1 or greater and the character string in parameter str1 ends with the character string in parameter str2. Otherwise returns FALSE.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:boolean type) Explanation
1 fn:ends-with("abcdefg", "efg") TRUE Returns TRUE because "abcdefg" ends with "efg".
2 fn:ends-with("abcdefg", "abc") FALSE Returns FALSE because "abcdefg" does not end with "abc".
3 fn:ends-with((), "") TRUE Returns TRUE because the value of parameter str2 is a character string of length zero.
4 fn:ends-with((), "a") FALSE Returns FALSE because the value of parameter str1 is an empty XQuery sequence, and the value of parameter str2 is a character string of length 1 or greater.
5 fn:ends-with("abcdefg", ()) TRUE Returns TRUE because the value of parameter str2 is an empty XQuery sequence.

(15) false

(a) Function

Returns FALSE.

(b) Format
 
fn:false ( )
 
(c) Rules
  1. This function has no parameters.
  2. The result is the xs:boolean type value FALSE.

(16) floor

(a) Function

Returns the largest integer value that is less than or equal to an argument.

(b) Format
 
fn:floor ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-121 fn:floor function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument num Numeric data type
    (including empty XQuery sequences)
    Input numeric value
  2. The result is an empty XQuery sequence, or a value of one of the numeric data types listed below.

    Table 1-122 XQuery data type of the result of the fn:floor function

    No. XQuery data type of the value of the parameter num XQuery data type of the result
    1 xs:double xs:double
    2 xs:decimal xs:decimal
    3 xs:int xs:int
  3. If the value of the parameter num is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. The following table describes what happens when the data type of the parameter num is xs:double type and the value is one of the special values shown below:

    Table 1-123 fn:floor function special value results

    No. Value of the parameter num Result value
    1 Positive 0 Positive 0
    2 Negative 0 Negative 0
    3 Positive infinity Positive infinity
    4 Negative infinity Negative infinity
    5 NaN (not a number) NaN (not a number)
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:floor(10.5) 10. (xs:decimal) Returns 10, which is the largest integer value that is less than or equal to 10.5.
2 fn:floor(-10.5) -11. (xs:decimal) Returns -11, which is the largest integer value that is less than or equal to -10.5.

(17) hours-from-dateTime

(a) Function

Returns only the hours part extracted from the time stamp.

(b) Format
 
fn:hours-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-124 fn:hours-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dtm is an xs:dateTime type value, the hours part is returned as an xs:int type value.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:hours-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 18 Returns 18, which is the value of the hours part of parameter dtm.

(18) hours-from-time

(a) Function

Returns only the hours part extracted from the time.

(b) Format
 
fn:hours-from-time ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-125 fn:hours-from-time function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument tim xs:time type
    (including empty XQuery sequences)
    Time to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter tim is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter tim is an xs:time type value, the hours part is returned as an xs:int type value.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:hours-from-time(xs:time("18:44:58")) 18 Returns 18, which is the hours part of the value of parameter tim.

(19) index-of

(a) Function

Returns the positions in the specified XQuery sequence of all occurrences of the XQuery items that match the specified atomic value.

(b) Format
 
fn:index-of ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-126 fn:index-of function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq XQuery sequence of zero or more values of any atomic type XQuery sequence to be searched
    2 argument-2 val Any atomic type Atomic value to search for
  2. The result is an XQuery sequence consisting of zero or more xs:int type values.
  3. If the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If an XQuery item matching the value of parameter val is present in parameter seq, its position is returned as an xs:int type value. The first position is 1.
  5. To decide whether atomic values match, the values are compared using the eq operator. If values cannot be compared to each other with the eq operator or their comparison result is FALSE, they are not considered matches.
  6. If multiple matching XQuery items are present in the XQuery sequence in parameter seq, an XQuery sequence is returned, consisting of the xs:int type values indicating their positions, arranged in ascending order.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:index-of((10, 20, 30, 40), 35) Empty XQuery sequence Returns an empty XQuery sequence because there is no matching XQuery item in the XQuery sequence in parameter seq.
2 fn:index-of((10, 20, 30, 40), 30) (3) Returns the XQuery sequence consisting of the xs:int type value 3, because the third XQuery item in the XQuery sequence in parameter seq is a match.
3 fn:index-of((10, 20, 30, 40,30,50), 30) (3,5) Returns the XQuery sequence consisting of the xs:int type values 3 and 5, because the third and fifth XQuery items in the XQuery sequence in parameter seq are matches.

(20) insert-before

(a) Function

Returns the XQuery sequence that results from inserting an XQuery item before the specified position in an XQuery sequence.

(b) Format
 
fn:insert-before ( argument-1, argument-2, argument-3 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-127 fn:insert-before function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq1 XQuery sequence of zero or more arbitrary XQuery items XQuery sequence into which you are inserting
    2 argument-2 pos xs:int Insertion position
    3 argument-3 seq2 XQuery sequence of zero or more arbitrary XQuery items XQuery sequence containing the XQuery items to be insert
  2. The result is an XQuery sequence consisting of zero or more XQuery items.
  3. If the value of parameter seq1 is an empty XQuery sequence, and if the value of parameter seq2 is also an empty XQuery sequence, an empty XQuery sequence is returned; otherwise, the XQuery sequence that is the value of parameter seq2 is returned.
  4. If the value of parameter seq2 is an empty XQuery sequence, the XQuery sequence that is the value of parameter seq1 is returned.
  5. The insertion position is specified in parameter pos. Specify 1 to insert at the beginning. If the value of parameter pos is less than 1, the insertion position is treated as 1. If the value of parameter pos is greater than the number of XQuery items in the XQuery sequence that is the value of parameter seq1, the insertion position is treated as (the number of XQuery items in the XQuery sequence that is the value of parameter seq1 + 1).
  6. The resulting XQuery sequence will consist of, in order, the XQuery items up to one before the insertion position in the XQuery sequence that is the value of parameter seq1, the XQuery items in the XQuery sequence that is the value of parameter seq3, and the XQuery items after the insertion position in the XQuery sequence that is the value of parameter seq1.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:insert-before(("a", "b", "c"), 0, "z") ("z", "a", "b", "c") Inserts "z" at the beginning because the value of parameter pos is 0.
2 fn:insert-before(("a", "b", "c"), 1, "z") ("z", "a", "b", "c") Inserts "z" at the beginning because the value of parameter pos is 1.
3 fn:insert-before(("a", "b", "c"), 3, "z") ("a", "b", "z", "c") Inserts "z" before the third XQuery item "c" because the value of parameter pos is 3.
4 fn:insert-before(("a", "b", "c"), 4, "z") ("a", "b", "c", "z") Inserts "z" at the end because the value of parameter pos is 4.

(21) last

(a) Function

Returns the context size.

(b) Format
 
fn:last ( )
 
(c) Rules
  1. This function has no parameters.
  2. The result is an xs:int type value.
  3. Returns the number of context items as evaluated at the time this function was invoked.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result Explanation
1 ("a", "b", "c")[fn:last() ] "c" (xs:string)
Result of fn:last function is 3
fn:last function returns 3 because the number of context items is 3. Therefore, the third context item "c" will be the result.

(22) local-name

(a) Function

Returns the local name of a node.

(b) Format
 
fn:local-name ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-128 fn:local-name function parameter

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument node Any node
    (including empty XQuery sequences)
    Node whose local name is to be obtained
  2. The result is an xs:string type value.
  3. If no argument is specified, the local name of the context item node as evaluated at the time this function was invoked is returned. In other words, the result is the same as specifying fn:local-name(.). An error results if the context item is not a node.
  4. If the value of the parameter node is an empty XQuery sequence, a character string of length zero is returned.
  5. If the value of the parameter node is a node that does not have a name (document node, comment node, text node), a character string of length zero is returned.
  6. If the value of the parameter node is a node that has a name (element node, attribute node, processing instruction node), the local name of that node is returned.
(d) Example

In the examples of function invocations and their results given below, the XQuery variable book indicates the node representing the elements shown below.

Element represented by the XQuery variable book:

<bookinfo:bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo:bookinfo>

Examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 $book/fn:local-name() "bookinfo" Returns the local name of the context item, which is the bookinfo:bookinfo element node, because no argument is specified.
2 $book/fn:local-name(./title) "title" Returns the local name title because the value of the parameter node is the title element node.
3 $book/title/fn:local-name(./text()) "" (a character string of length zero) Returns a character string of length zero because the value of the parameter node is a text node.

(23) max

(a) Function

Returns the largest value of the atomic values that make up an XQuery sequence.

(b) Format
 
fn:max ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-129 fn:max function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more values of any atomic type Input XQuery sequence
  2. The result is an empty XQuery sequence or an atomic type value.
  3. If the value of the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. To compare the magnitudes of atomic values, the values are compared with the ge operator. An error results if the XQuery sequence that is the value of the parameter seq contains a mix of XQuery data types that cannot be compared with the ge operator.
  5. To compare numeric data types, all the values are converted to a common numeric data type and then compared. For this reason, if the XQuery sequence in parameter seq consists of only numeric data type values, the result will be a value of the XQuery data type shown below.

    Table 1-130 XQuery data type of the result of the fn:max function

    No. XQuery data type of the values in the XQuery sequence that is the value of the parameter seq XQuery data type of the result
    xs:double xs:decimal xs:int
    1 Y -- -- xs:double
    2 N Y -- xs:decimal
    3 N N -- xs:int
    Legend:
    Y: Includes.
    N: Does not include.
    --: Does not affect the data type of the result.
  6. If the XQuery sequence that is the value of the parameter seq contains an xs:double type value that is NaN (not a number), the result will be NaN.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:max((3,4.0,5)) 5. (xs:decimal) Returns 5, which is the largest value among 3, 4.0, 5, as an xs:decimal type value.
2 fn:max(()) Empty XQuery sequence Returns an empty XQuery sequence because the value of the parameter seq is an empty XQuery sequence.
3 fn:max((1.0E2, 2.0E-3, 100)) 1.0E2 (xs:double) Returns 1.0E2, which is the largest value among 1.0E2, 2.0E-3, 100, as an xs:double type value.

(24) min

(a) Function

Returns the smallest value of the atomic values that make up an XQuery sequence.

(b) Format
 
fn:min ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-131 fn:min function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence of zero or more values of any atomic type Input XQuery sequence
  2. The result is an empty XQuery sequence or an atomic type value.
  3. If the value of the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. To compare the magnitude of atomic values, the values are compared with the le operator. An error results if the XQuery sequence that is the value of the parameter seq contains a mix of XQuery data types that cannot be compared with the le operator.
  5. To compare numeric data types, all the values are converted to a common numeric data type and then compared. For this reason, if the XQuery sequence in parameter seq consists of only numeric data type values, the result will be a value of the XQuery data type shown below.

    Table 1-132 XQuery data type of the result of the fn:min function

    No. XQuery data type of the values in the XQuery sequence that is the value of the parameter seq XQuery data type of the result
    xs:double xs:decimal xs:int
    1 Y -- -- xs:double
    2 N Y -- xs:decimal
    3 N N -- xs:int
    Legend:
    Y: Includes.
    N: Does not include.
    --: Does not affect the data type of the result.
  6. If the XQuery sequence that is the value of the parameter seq contains an xs:double type value that is NaN (not a number), the result will be NaN.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:min((3,4.0,5)) 3. (xs:decimal) Returns 3, which is the smallest value among 3, 4.0, 5, as an xs:decimal type value.
2 fn:min(()) Empty XQuery sequence Returns an empty XQuery sequence because the value of the parameter seq is an empty XQuery sequence.
3 fn:min((1.0E2, 2.0E3, 100)) 1.0E2 (xs:double) Returns 1.0E2, which is the smallest value among 1.0E2, 2.0E3, 100, as an xs:double type value.

(25) minutes-from-dateTime

(a) Function

Returns only the minutes part extracted from the time stamp.

(b) Format
 
fn:minutes-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-133 fn:minutes-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dtm is an xs:dateTime type value, the value of the minutes part is returned as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:minutes-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 44 Returns 44, which is the minutes part of the value of the parameter dtm.

(26) minutes-from-time

(a) Function

Returns only the minutes part extracted from the time.

(b) Format
 
fn:minutes-from-time ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-134 fn:minutes-from-time function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument tim xs:time type
    (including empty XQuery sequences)
    Time to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter tim is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter tim is an xs:time type value, the value of the minutes part is returned as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:minutes-from-time(xs:time("18:44:58")) 44 Returns 44, which is the minutes part of the value of the parameter tim.

(27) month-from-date

(a) Function

Returns only the month part extracted from the date.

(b) Format
 
fn:month-from-date ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-135 fn:month-from-date function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dat xs:date type
    (including empty XQuery sequences)
    Date to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dat is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dat is an xs:date type value, return the value of the month part as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:month-from-date(xs:date("2006-09-26")) 9 Returns 9, which is the month part of the value of the parameter dat.

(28) month-from-dateTime

(a) Function

Returns only the month part extracted from the time stamp.

(b) Format
 
fn:month-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-136 fn:month-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dtm is an xs:dateTime type value, return the value of the month part as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:month-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 9 Returns 9, which is the month part of the value of the parameter dtm.

(29) name

(a) Function

Returns the qualified name of a node.

(b) Format
 
fn:name ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-137 fn:name function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument node Any node
    (including empty XQuery sequences)
    Node whose qualified name is to be obtained.
  2. The result is an xs:string type value.
  3. If no argument is specified, the qualified name of the context item node as evaluated at the time this function was invoked is returned. In other words, the result is the same as specifying fn:name(.). An error results if the context item is not a node.
  4. If the value of the parameter node is an empty XQuery sequence, a character string of length zero is returned.
  5. If the value of the parameter node is a node that does not have a name (document node, comment node, text node), a character string of length zero is returned.
  6. If the value of the parameter node is a node that has a name (element node, attribute node, processing instruction node), the qualified name of that node is returned.
(d) Example

In the examples of function invocations and their results given below, the XQuery variable book indicates the node representing the elements shown below.

Element represented by the XQuery variable book:

<bookinfo:bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo:bookinfo>

Examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 $book/fn:name() "bookinfo:bookinfo" Returns the qualified name of the context item, which is the bookinfo:bookinfo element node, because no argument is specified.
2 $book/fn:name(./title) "title" Returns the qualified name title because the value of the parameter node is the title element node.
3 $book/title
/fn:name(./text())
"" (a character string of length zero) Returns a character string of length zero because the value of the parameter node is a text node.

(30) namespace-uri

(a) Function

Returns the XML namespace URI of the qualified name of a node.

(b) Format
 
fn:namespace-uri ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-138 fn:namespace-uri function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument node Any node
    (including empty XQuery sequences)
    Node for which the XML namespace URI is to be obtained from the qualified name
  2. The result is an xs:string type value.
  3. If no argument is specified, the XML namespace URI obtained from evaluating the context item node's qualified name at the time this function was invoked is returned. In other words, the result is the same as specifying fn:namespace-uri(.). An error results if the context item is not a node.
  4. If the value of the parameter node is an empty XQuery sequence, a character string of length zero is returned.
  5. If the value of the parameter node is a node other than an element node or an attribute node, a character string of length zero is returned.
  6. If the value of the parameter node is an element node or attribute node whose expand qualified name does not have an XML namespace URI, a character string of length zero is returned.
  7. If the value of the parameter node is an element node or attribute node whose expand qualified name has an XML namespace URI, the XML namespace URI of the node's qualified name is returned.
(d) Example

In the examples of function invocations and their results given below, the XQuery variable book indicates the node representing the elements shown below. The example assumes that the XML namespace URI corresponding to the prefix bookinfo is http://www.hirdb-example.com/bookinfo, and the default XML namespace URI corresponding to the element and attribute names is http://www.hirdb-example.com/default.

Element represented by the XQuery variable book:

<bookinfo:bookinfo book_id="452469630">
  <title>Relational Databases Explained</title>
  <author>Jeff Jones</author>
  <author>Bob Adams</author>
</bookinfo:bookinfo>

Examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 $book/fn:namespace-uri() " http://www.hirdb-example.com/bookinfo" Returns the XML namespace URI of the context item's qualified name, which is the bookinfo:bookinfo element node because no argument is specified.
2 $book/fn:namespace-uri(./title) " http://www. hirdb-example.com/default" Returns the XML namespace URI of that qualified name because the value of the parameter node is the title element node.
3 $book/title
/fn:namespace-uri(./text())
"" (a character string of length zero) Returns a character string of length zero because the value of the parameter node is a text node.

(31) normalize-space

(a) Function

Returns the result of normalizing whitespace in a character string.

Normalizing whitespace in a character string means removing leading and trailing whitespace (one-byte space (X'20'), TAB (X'09'), NL (X'0A'), and CR (X'0D')), and replacing contiguous whitespace with a single one-byte space.

(b) Format
 
fn:normalize-space ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-139 fn:normalize-space function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument str xs:string type
    (including empty XQuery sequences)
    Input character string
  2. The result is an xs:string type value.
  3. If no argument is specified, the result of normalizing whitespace in the character string representation of the value of the context item as evaluated at the time this function was invoked is returned. In other words, the result is the same as specifying fn:normalize-space(fn:string(.)).
  4. If the value of the parameter str is an empty XQuery sequence, a character string of length zero is returned.
  5. If the value of the parameter str is an xs:string type value, a result of normalizing the whitespace of that value is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 fn:normalize-space(()) "" (a character string of length zero) Returns a character string of length zero because the value of the parameter str is an empty XQuery sequence.
2 fn:normalize-space(" a b c d ") "a b c d" Returns the result of normalizing whitespace of "a b c d ".

(32) not

(a) Function

Converts the value specified in an argument to the xs:boolean type and returns the negation of its value.

(b) Format
 
fn:not ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-140 fn:not function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence with zero or more XQuery items Input XQuery sequence
  2. The result is an xs:boolean type value.
  3. Returns a result using the following procedure:
    • Applies the fn:boolean function to the value of the parameter seq to calculate its Boolean value.
    • If the calculated Boolean value is TRUE, return FALSE. If the calculated Boolean value is FALSE, return TRUE.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result
(xs:boolean type)
Explanation
1 fn:not(fn:true()) FALSE Returns FALSE because the value of the parameter seq is TRUE.
2 fn:not(0) TRUE Returns TRUE because 0 evaluates to the Boolean value FALSE.
3 fn:not("ABC") FALSE Returns FALSE because "ABC" evaluates to the Boolean value TRUE.

(33) number

(a) Function

Returns the result of converting the value specified in the argument to the xs:double type.

(b) Format
 
fn:number ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-141 fn:number function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument item Any XQuery item
    (including empty XQuery sequences)
    Input XQuery item
  2. The result is an xs:double type value.
  3. If no argument is specified, the context item is atomized at the time this function is invoked, the value is converted to xs:double type and returned. In other words, the result is the same as specifying fn:number(.).
  4. If the parameter item is an empty XQuery sequence, NaN (not a number) is returned.
  5. If the value of the parameter item is an XQuery item, the atomized value of that XQuery item converted to xs:double type is returned. If conversion is not possible, NaN (not a number) is returned. For details about when conversion is possible, see 1.15.2(3)(c) Convertible XQuery data types.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:double type) Explanation
1 fn:number(()) NaN (not a number) Returns NaN because the value of the parameter item is an empty XQuery sequence.
2 fn:number("abcde") NaN (not a number) Returns NaN because "abcde" cannot be converted to xs:double type.
3 fn:number(fn:false()) 0.0E0 Returns 0.0E0 because the xs:boolean type TRUE converts to the xs:double type value 0.0E0.
4 fn:number(" 15000000 ") 1.5E7 Returns 1.5E7 because " 15000000 " converts to the xs:double type value 1.5E7.
5 fn:number("INF") Positive infinity Returns positive infinity because "INF" converts to the xs:double type value positive infinity.

(34) position

(a) Function

Returns the context position.

(b) Format
 
fn:position ( )
 
(c) Rules
  1. This function has no parameters.
  2. The result is an xs:int type value.
  3. Returns the context position of a context item as evaluated at the time this function was invoked.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result Explanation
1 ("a", "b", "c")[fn:position() ge 2] ("b", "c")
The results of the fn:position function on the context items "a", "b", "c" are 1, 2, 3 respectively.
The result is the XQuery sequence consisting of "b", "c", which are the context items whose context position is greater than or equal to 2.

(35) remove

(a) Function

Returns the result of removing the XQuery item at the specified position in the XQuery sequence.

(b) Format
 
fn:remove ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-142 fn:remove function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq XQuery sequence containing zero or more XQuery items Input XQuery sequence
    2 argument-2 pos xs:int Position of the context item to be removed
  2. The result is an XQuery sequence consisting of zero or more XQuery items.
  3. If the value of the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. The position of the XQuery item to be remove is specified in parameter pos. If the value of the parameter pos is less than 1, or greater than the number of XQuery items in the XQuery sequence that is the value of the parameter seq, the XQuery sequence that is the value of the parameter seq is returned unchanged.
  5. The resulting XQuery sequence consists of the XQuery items up to one before the XQuery item to be delete from the XQuery sequence that is the value of the parameter seq, followed by the XQuery items after the XQuery item to be delete from the XQuery sequence that is the value of the parameter seq.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:remove(("a", "b", "c"), 0) ("a", "b", "c") Returns the value of parameter seq unchanged, because the value of parameter pos is less than 1.
2 fn:remove(("a", "b", "c"), 1) ("b", "c") Returns the XQuery sequence with the first XQuery item removed.
3 fn:remove(("a", "b", "c"), 4) ("a", "b", "c") Returns the value of parameter seq unchanged, because the value of parameter pos (4) is greater than the number of XQuery items in the XQuery sequence that is the value of the parameter seq.

(36) reverse

(a) Function

Returns the XQuery sequence that results from sorting the XQuery items in an XQuery sequence in reverse order.

(b) Format
 
fn:reverse ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-143 fn:reverse function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence consisting of zero or more arbitrary XQuery items Input XQuery sequence
  2. The result is an XQuery sequence consisting of zero or more XQuery items.
  3. If the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:reverse((10, 20, 30, 40)) (40,30,20,10) Returns an XQuery sequence in which the XQuery items in the XQuery sequence in parameter seq have been sorted in reverse order.
2 fn:reverse(("abcde")) ("abcde") Returns the XQuery sequence in parameter seq unchanged, because there is only one XQuery item in the XQuery sequence in parameter seq.
3 fn:reverse(()) Empty XQuery sequence Returns an empty XQuery sequence because the XQuery sequence in parameter seq is an empty XQuery sequence.

(37) round

(a) Function

Returns the integer value closest to the value of an argument.

(b) Format
 
fn:round ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-144 fn:round function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument num Numeric data type
    (including empty XQuery sequences)
    Input numeric value
  2. The result is an empty XQuery sequence, or a value of one of the numeric data types shown below.

    Table 1-145 XQuery data type of the result of the fn:round function

    No. XQuery data type of the value of the parameter num XQuery data type of the result
    1 xs:double xs:double
    2 xs:decimal xs:decimal
    3 xs:int xs:int
  3. If the value of the parameter num is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If there are two qualifying values, the larger one is returned.
  5. The following table describes what is returned when the value of the parameter num is xs:double type and one of the special value is specified.

    Table 1-146 fn:round function special value results

    No. Value of the parameter num Result value
    1 Positive 0 Positive 0
    2 Negative 0 Negative 0
    3 At least -0.5 but less than 0 Negative 0
    4 Positive infinity Positive infinity
    5 Negative infinity Negative infinity
    6 NaN (not a number) NaN (not a number)
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:round(2.5) 3. (xs:decimal) Returns 3, the larger of 2 and 3, which are the integers closest to 2.5.
2 fn:round(2.4999) 2. (xs:decimal) Returns 2, the integer closest to 2.4999.
3 fn:round(-2.5) -2. (xs:decimal) Returns -2, the larger of -2 and -3, which are the integers closest to -2.5.
4 fn:round(-4.5E-1) Negative 0 (xs:double) Returns -0, because -4.5E-1 is less than 0 but greater than -0.5.

(38) seconds-from-dateTime

(a) Function

Returns only the seconds part extracted from the time stamp.

(b) Format
 
fn:seconds-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-147 fn:seconds-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:decimal type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dtm is an xs:dateTime type value, the value of the seconds part, including fractional seconds, is returned as an xs:decimal type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result
(xs:decimal type)
Explanation
1 fn:seconds-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 58.153 Returns 58.153, which is the seconds part of the value of the parameter dtm.

(39) seconds-from-time

(a) Function

Returns only the seconds part extracted from the time.

(b) Format
 
fn:seconds-from-time ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-148 fn:seconds-from-time function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument tim xs:time type
    (including empty XQuery sequences)
    Time to extract from
  2. The result is an empty XQuery sequence or an xs:decimal type value.
  3. If the value of the parameter tim is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of the parameter tim is an xs:time type value, the value of the seconds part as an xs:decimal type is returned.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result
(xs:decimal type)
Explanation
1 fn:seconds-from-time(xs:time("18:44:58")) 58 Returns 58, which is the seconds part of the value of the parameter tim.

(40) starts-with

(a) Function

Returns a value indicating whether the character string specified in argument-1 starts with the character string specified in argument-2.

(b) Format
 
fn:starts-with ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-149 fn:starts-with function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string to be checked to determine if it starts with the substring
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Substring to check against the start of the character string in parameter str1
  2. The result is an xs:boolean type value.
  3. Returns FALSE if the value of parameter str1 is an empty XQuery sequence or a character string of length zero and the value of parameter str2 is a character string of length 1 or greater.
  4. If the value of parameter str2 is an empty XQuery sequence or a character string of length zero, TRUE is returned regardless of the value of parameter str1.
  5. Returns TRUE if the values of parameters str1 and str2 are character strings of length 1 or greater and the character string in parameter str1 starts with the character string in parameter str2. Otherwise returns FALSE.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:boolean type) Explanation
1 fn:starts-with("abcdefg", "abc") TRUE Returns TRUE because "abcdefg" starts with "abc".
2 fn:starts-with("abcdefg", "cde") FALSE Returns FALSE because "abcdefg" does not start with "cde".
3 fn:starts-with((), "") TRUE Returns TRUE because the value of parameter str2 is a character string of length zero.
4 fn:starts-with((), "a") FALSE Returns FALSE because the value of parameter str1 is an empty XQuery sequence, and the value of parameter str2 is a character string of length 1 or greater.
5 fn:starts-with("abcdefg", ()) TRUE Returns TRUE because the value of parameter str2 is an empty XQuery sequence.

(41) string

(a) Function

Returns the character string representation of the value of an XQuery item as an xs:string type value.

(b) Format
 
fn:string ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table.

    Table 1-150 fn:string function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument item Any XQuery item
    (including empty XQuery sequences)
    Input XQuery item
  2. The result is an xs:string type value.
  3. If no argument is specified, the character string representation of the value of the context item as evaluated at the time this function was invoked is returned. In other words, the result is the same as specifying fn:string( ).
  4. If the parameter item is an empty XQuery sequence, a character string of length zero.
  5. If the parameter item is a node, the result will be a value listed in the following table, depending on the type of node.

    Table 1-151 Results when the parameter item is a node

    No. Kind of node Value returned by the fn:string function
    1 Document node Value of the string-value property
    2 Element node Value of the string-value property
    3 Attribute node Value of the string-value property
    4 Processing instruction node Value of the content property
    5 Comment node Value of the content property
    6 Text node Value of the content property
  6. If the value of the parameter item is an atomic value, the atomic value converted to xs:string type is returned. For details about the rules for converting to xs:string type, see 1.15.2(3)(c) Convertible XQuery data types.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result
(xs:string type)
Explanation
1 fn:string(()) "" (a character string of length zero) Returns a character string of length zero because the value of the parameter item is an empty XQuery sequence.
2 fn:string("abcde") "abcde" Returns the character string "abcde" unchanged.
3 fn:string(1.234E4) "12340" Returns the result of converting the xs:decimal type value 1.234E4 to the xs:string type value "12340".
4 fn:string(0.1234E10) "1.234E9" Returns the result of converting the xs:decimal type value 0.1234E10 to the xs:string type value "1.234E9".
5 fn:string(fn:true()) "true" Returns the result of converting the xs:boolean type value TRUE to the xs:string type value "true".

(42) string-length

(a) Function

Returns the length (in number of characters) of a character string.

(b) Format
 
fn:string-length ( [argument] )
 
(c) Rules
  1. This function takes zero or one of the parameter listed in the following table:

    Table 1-152 fn:string-length function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument str xs:string type
    (including empty XQuery sequences)
    Input character string
  2. The result is an xs:int type value.
  3. If no argument is specified, the length of the character string representation of the context item as evaluated at the time this function was invoked is returned. In other words, the result is the same as specifying fn:string-length(fn:string(.)).
  4. Returns 0 if the value of the parameter str is an empty XQuery sequence.
  5. If the value of the parameter str is an xs:string type value, the number of characters in its value is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:int type) Explanation
1 fn:string-length(()) 0 Returns 0, because the value of parameter str is an empty XQuery sequence.
2 fn:string-length("abcde") 5 Returns 5, which is the length of "abcde".
3 fn:string-length("[Figure]") 5 Returns 5, which is the length of "[Figure]".

(43) subsequence

(a) Function

Returns an XQuery subsequence of an XQuery sequence.

(b) Format
 
fn:subsequence ( argument-1, argument-2[, argument-3] )
 
(c) Rules
  1. The following table lists the parameters of this function. Note that the parameter len is optional.

    Table 1-153 fn:subsequence function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 seq XQuery sequence consisting of zero or more XQuery items XQuery sequence from which to extract the XQuery subsequence
    2 argument-2 pos xs:double type Starting position from which to extract the XQuery subsequence
    3 argument-3 len xs:double type Number of XQuery items to extract
  2. The result is an XQuery sequence consisting of zero or more XQuery items.
  3. If the parameter seq is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. The starting position from which to extract the XQuery subsequence is specified in the parameter pos. Parameter pos is evaluated using the fn:round function, and the integer value of the result is the starting position. The first position is 1.
    If the result of using the fn:round function to evaluate the parameter pos is not a positive value, extraction starts from the first position.
    If the result of using the fn:round function to evaluate the parameter pos is greater than the number of XQuery items in the parameter seq, an empty XQuery sequence is returned.
  5. The number of XQuery items in the XQuery subsequence to extract is specified in the parameter len. Parameter len is evaluated using the fn:round function, and the integer value of the result is the number of XQuery items to extract into the XQuery subsequence.
    If the result of using the fn:round function to evaluate the parameter len is not a positive value, an empty XQuery sequence is returned.
    If the result of using the fn:round function to evaluate the parameter len is greater than the number XQuery items from the starting position to the end of the XQuery sequence in parameter seq, or if the parameter len is omitted, all XQuery items from the starting position to the end of the XQuery sequence in parameter seq are extracted.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result Explanation
1 fn:subsequence(
("a","b","c","d","e","f","g"), 5)
("e","f","g") Returns the XQuery sequence consisting of XQuery items from the fifth position until the end of the XQuery sequence in parameter seq.
2 fn:subsequence(
("a","b","c","d","e","f","g"),
2, 2.5)
("b","c","d") Returns the XQuery sequence consisting of three XQuery items starting from the second position of the XQuery sequence in parameter seq because the result of evaluating the fn:round function on 2.5 is 3.
3 fn:subsequence((), 10) Empty XQuery sequence Returns an empty XQuery sequence because parameter seq is an empty XQuery sequence.
4 fn:subsequence (("a","b","c","d","e","f","g"),
-10, 10)
("a","b","c","d",
"e","f","g")
Extraction starts from the first position because parameter pos is negative. Extraction continues to the end because the value of parameter len is greater than the number of XQuery items from the starting position until the end of parameter seq.

(44) substring

(a) Function

Returns a substring of a character string.

(b) Format
 
fn:substring ( argument-1, argument-2[, argument-3] )
 
(c) Rules
  1. The following table lists the parameters of this function. Note that the parameter len is optional.

    Table 1-154 fn:substring function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str xs:string type
    (including empty XQuery sequences)
    Character string from which to extract a substring
    2 argument-2 pos xs:double type Starting position of the substring to be extracted
    3 argument-3 len xs:double type Length (in number of characters) of the substring to be extracted
  2. The result is an xs:string type value.
  3. If the value of the parameter str is an empty XQuery sequence, a character string of length zero is returned.
  4. If the value of the parameter str is an xs:string type value of length zero, a character string of length zero is returned.
  5. The starting position of the substring to extract is specified in the parameter pos. The integer value of the result of evaluating the fn:round function on the parameter pos will be the starting position. The first position is 1.
    If the integer value of the result of evaluating the fn:round function on the parameter pos is not a positive value, extraction starts from the first position.
    If the integer value of the result of evaluating the fn:round function on the parameter pos is greater than the length of the value of the parameter str, a character string of length zero is returned.
  6. The length (in number of characters) of the part of the character string to be extracted is specified in the parameter len. The integer value of the result of evaluating the fn:round function on the parameter len will be the length of the substring to extract.
    If the integer value of the result of evaluating the fn:round function on the parameter len is not a positive value, a character string of length zero is returned.
    If the integer value of the result of evaluating the fn:round function on the parameter len is greater than the length of the string from the starting position to the end of the value of the parameter str, or if parameter len is omitted, extraction continues to the end of the character string that is the value of the parameter str.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 fn:substring ("abcdefg", 5) "efg" Returns the substring from the fifth character until the end of "abcdefg".
2 fn:substring("abcdefg", 2, 2.5) "bcd" Returns the three-character substring starting from the second character of "abcdefg", because the result of using the fn:round function to evaluate 2.5 is 3.
3 fn:substring((), 10) "" (a character string of length zero) Returns a character string of length zero because the value of the parameter str is an empty XQuery sequence.
4 fn:substring ("abcdefg",-10, 10) "abcdefg" Extraction starts from the first position because the value of parameter pos is negative. Extraction continues to the end because the value of parameter len is greater than the length from the starting position to the end of "abcdefg".

(45) substring-after

(a) Function

Returns a substring of the character string specified in argument-1 that begins immediately after the position of the first occurrence of the character string specified in argument-2.

(b) Format
 
fn:substring-after ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-155 fn:substring-after function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string in which to find the substring
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Substring to find in the character string in parameter str1
  2. The result is an xs:string type value.
  3. If the value of parameter str1 is an empty XQuery sequence or a character string of length zero, a character string of length zero is returned regardless of the value of parameter str2.
  4. If the value of parameter str1 is a character string of length 1 or greater, and the value of parameter str2 is an empty XQuery sequence or a character string of length zero, return the value of parameter str1.
  5. When the values of parameters str1 and str2 are character strings of length 1 or greater, and if the character string in parameter str2 is found in the character string in parameter str1, the substring that starts immediately after the position of the first such occurrence and extends to the end of the string is returned. Otherwise, a character string of length zero is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 fn:substring-after("abcdefg", "efg") "" (a character string of length zero) Returns the substring after the position of the first occurrence of "eft" in "abcdefg".
2 fn:substring-after("abcdefgcde", "cde") "fgcde" Returns the substring after the position of the first occurrence of "cde" in "abcdefgcde".
3 fn:substring-after((), "abc") "" (a character string of length zero) Returns a character string of length zero because the value of parameter str1 is an empty XQuery sequence.
4 fn:substring-after("abcdefg", ()) "abcdefg" Returns "abcdefg" unchanged, because the value of parameter str2 is an empty XQuery sequence.

(46) substring-before

(a) Function

Returns a substring of the character string specified in argument-1 that ends immediately before the position of the first occurrence of the character string specified in argument-2.

(b) Format
 
fn:substring-before ( argument-1, argument-2 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-156 fn:substring-before function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str1 xs:string type
    (including empty XQuery sequences)
    Character string in which to find the substring
    2 argument-2 str2 xs:string type
    (including empty XQuery sequences)
    Substring to find in the character string in parameter str1
  2. The result is an xs:string type value.
  3. If the value of parameter str1 is an empty XQuery sequence or a character string of length zero, a character string of length zero is returned regardless of the value of parameter str2.
  4. If the value of parameter str1 is a character string of length 1 or greater, and the value of parameter str2 is an empty XQuery sequence or a character string of length zero, the value of parameter str1 is returned.
  5. When the values of parameters str1 and str2 are character strings of length 1 or greater, and if the character string in parameter str2 is found in the character string in parameter str1, the substring that starts at the beginning of the string and ends immediately before the position of the first such occurrence is returned. Otherwise, a character string of length zero is returned.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 fn:substring-before("abcdefg", "abc") "" (a character string of length zero) Returns the substring before the position where "abc" occurs in "abcdefg".
2 fn:substring-before("abcdefgdef", "def") "abc" Returns the substring before the position where "def" occurs in "abcdefgdef".
3 fn:substring-before((), "abc") "" (a character string of length zero) Returns a character string of length zero because the value of parameter str1 is an empty XQuery sequence.
4 fn:substring-before("abcdefg", ()) "abcdefg" Returns "abcdefg" unchanged, because the value of parameter str2 is an empty XQuery sequence.

(47) sum

(a) Function

Returns the sum of the atomic values that make up an XQuery sequence.

(b) Format
 
fn:sum ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-157 fn:sum function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument seq XQuery sequence with zero or more numeric data type values Input XQuery sequence
  2. The result is an empty XQuery sequence or a numeric data type value.
  3. If the value of the parameter seq is an empty XQuery sequence, the xs:int type value 0 is returned.
  4. Thee following table indicates the XQuery data type of the result for each XQuery sequence that is the value of the parameter seq.

    Table 1-158 XQuery data type of the result of the fn:sum function

    No. XQuery data type of the value of the XQuery sequence that is the value of the parameter seq XQuery data type of the result
    xs:double xs:decimal xs:int
    1 N N N xs:int
    2 Y -- -- xs:double
    3 N Y -- xs:decimal
    4 N Y xs:int

    Legend:
    Y: Includes.
    N: Does not include.
    --: Does not affect the data type of the result.

  5. If the XQuery sequence that is the value of the parameter seq includes NaN (not a number), result will be NaN.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (XQuery data type in parentheses) Explanation
1 fn:sum((3,4,5)) 12 (xs:int) Returns 12, which is the value of the sum of 3, 4, and 5.
2 fn:sum(()) 0 (xs:int) Returns 0, because the parameter seq is an empty XQuery sequence.
3 fn:sum((1.0E2, 2.0E3)) 2.1E3 (xs:double) Returns 2.1E3, which is the value of the sum of 1.0E2 and 2.0E3.

(48) translate

(a) Function

Returns the result of replacing the characters specified in argument-2 with the characters specified in argument-3 in the character string specified in argument-1.

(b) Format
 
fn:translate ( argument-1, argument-2, argument-3 )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-159 fn:translate function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument-1 str xs:string type
    (including empty XQuery sequences)
    Input character string
    2 argument-2 from xs:string type Character string consisting of characters to be replaced
    3 argument-3 to xs:string type Character string consisting of replacement characters
  2. The result is an xs:string type value.
  3. If the value of the parameter str is an empty XQuery sequence, a character string of length zero is returned.
  4. If the value of the parameter str is an xs:string type value, the characters in that string are evaluated against the characters in the string that is the value of the parameter from. Any matching characters are replaced with the character in the corresponding position in the character string that is the value of the parameter to, and the result is returned. If the character to be replaced is the nth character in the character string that is the value of the parameter from, the nth character in the character string that is the value of the parameter to will replace it. If the character to be replaced is the mth character in the character string that is the value of the parameter from, and the length of the character string that is the value of the parameter to is less than m, the character to be replaced is removed.
  5. If the same letter appears multiple times in the character string that is the value of the parameter from, it is replaced by the first replacement character specified.
(d) Example

The following table provides examples of function invocations and their results:

No. Function invocation Result (xs:string type) Explanation
1 fn:translate("abcdef", "ace", "ACE") "AbCdEf" Returns the character string in which each of a, c, e in "abcdef" is replaced with A, C, E, respectively.
2 fn:translate("abcdefg", "aceg", "ACE") "AbCdEf" Returns the character string in which each of a, c, e in "abcdefg" is replaced with A, C, E, respectively, and g is removed.
3 fn:translate("abcdef", "acea", "ACEB") "AbCdEf" Returns the character string in which each of a, c, e in "abcdef" is replaced with A, C, E, respectively.

(49) true

(a) Function

Returns TRUE.

(b) Format
 
fn:true ( )
 
(c) Rules
  1. This function has no parameters.
  2. The result is the xs:boolean type value TRUE.

(50) year-from-date

(a) Function

Returns only the year part extracted from the date.

(b) Format
 
fn:year-from-date ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-160 fn:year-from-date function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dat xs:date type
    (including empty XQuery sequences)
    Date to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dat is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dat is an xs:date type value, the value of the year part is returned as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:year-from-date(xs:date("2006-09-26")) 2006 Returns 2006, the year part of the value of parameter dat.

(51) year-from-dateTime

(a) Function

Returns only the year part extracted from the time stamp.

(b) Format
 
fn:year-from-dateTime ( argument )
 
(c) Rules
  1. The following table lists the parameters of this function.

    Table 1-161 fn:year-from-dateTime function parameters

    No. Corresponding argument Parameter XQuery data type Explanation
    1 argument dtm xs:dateTime type
    (including empty XQuery sequences)
    Time stamp to extract from
  2. The result is an empty XQuery sequence or an xs:int type value.
  3. If the value of the parameter dtm is an empty XQuery sequence, an empty XQuery sequence is returned.
  4. If the value of parameter dtm is an xs:dateTime type value, the value of the year part is returned as an xs:int type.
(d) Example

The following table provides an example of a function invocation and its result:

No. Function invocation Result (xs:int type) Explanation
1 fn:year-from-dateTime(xs:dateTime("2006-09-26T18:44:58.153")) 2006 Returns 2006, which is the year part of the value of the parameter dtm.