Copyright © 2002 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use, and software licensing rules apply.
This document defines basic operators and functions on the datatypes defined in [XML Schema Part 2: Datatypes] for use in XQuery, XPath, XSLT and other related XML standards. It also discusses operators and functions on nodes and node sequences as defined in the [XQuery 1.0 and XPath 2.0 Data Model] for use in XQuery, XPath, XSLT and other related XML standards.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. The latest status of this document series is maintained at the W3C.
This is a Public Working Draft of this document for review by W3C Members and other interested parties. It is a draft document and may be updated, replaced, or made obsolete by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". This is work in progress and does not imply endorsement by the W3C membership.
This document describes constructor functions, operators, and functions that are used in [XPath 2.0], [XQuery 1.0: An XML Query Language], and [XSLT 2.0]. The document is generally unconcerned with the specific syntax with which these constructor functions, operators, and functions will be used, and focuses instead on defining the semantics of them as precisely as feasible.
Among the more important changes from the previous version of this document are a new algorithm for selecting the collation to be used when certain character string operations are performed (see section 6.2 Equality and Comparison of Strings), simplifications of the rules for casting (see section 4 Constructor Functions and section 16 Casting Functions), and a more complete specification of functions that implement regular expression capabilities (see sections 6.3.15 xf:matches, 6.3.16 xf:replace, and 6.3.17 xf:tokenize).
The discussion about whether the syntax for constructor functions and casting can be unified continues. This has potentially wide impact and may reopen the closed issue of casting to and from derived types.
This document has been produced following the procedures set out for the W3C Process. This document was produced through the efforts of a joint task force of the W3C XML Query Working Group and the W3C XML Schema Working Group (both part of the W3C XML Activity) and a second joint task force of the W3C XML Query Working Group and the W3C XSL Working Group (part of the W3C Style Activity). It is designed to be read in conjunction with the following documents: [XQuery 1.0 and XPath 2.0 Data Model], [XPath 2.0], [XQuery 1.0: An XML Query Language] and [XSLT 2.0].
The following are identified as high priority issues. Reviewers are requested to provide feedback on these issues using the address below.
Public comments on this document and its open issues are welcome. Comments should be sent to the W3C XPath/XQuery mailing list, public-qt-comments@w3.org (archived at http://lists.w3.org/Archives/Public/public-qt-comments/).
Patent disclosures relevant to this specification may be found on the XML Query Working Group's patent disclosure page and the XSL Working Group's patent disclosure page.
A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR/.
1 Introduction
          1.1 Terminology
          1.2 Datatypes
          1.3 Syntax
          1.4 Notations
          1.5 Namespace Prefix
      2 Accessors
          2.1 xf:node-kind
          2.2 xf:node-name
          2.3 xf:string
          2.4 xf:data
          2.5 xf:base-uri
          2.6 xf:unique-ID
      3 The xf:error Function
          3.1 Examples
      4 Constructor
      Functions
      5 Functions and Operators on
      Numbers
          5.1 Numeric
      Types
          5.2 Operators
      on Numeric Values
              5.2.1 op:numeric-add
              5.2.2 op:numeric-subtract
              5.2.3 op:numeric-multiply
              5.2.4 op:numeric-divide
              5.2.5 op:numeric-integer-divide
              5.2.6 op:numeric-mod
              5.2.7 op:numeric-unary-plus
              5.2.8 op:numeric-unary-minus
          5.3 Comparisons of Numeric Values
              5.3.1 op:numeric-equal
              5.3.2 op:numeric-less-than
              5.3.3 op:numeric-greater-than
          5.4 Functions on
      Numeric Values
              5.4.1 xf:floor
              5.4.2 xf:ceiling
              5.4.3 xf:round
      6 Functions on Strings
          6.1 String
      Types
          6.2 Equality and Comparison of
      Strings
              6.2.1 xf:compare
          6.3 Functions on
      String Values
              6.3.1 xf:concat
              6.3.2 xf:starts-with
              6.3.3 xf:ends-with
              6.3.4 xf:contains
              6.3.5 xf:substring
              6.3.6 xf:string-length
              6.3.7 xf:substring-before
              6.3.8 xf:substring-after
              6.3.9 xf:normalize-space
              6.3.10 xf:normalize-unicode
              6.3.11 xf:upper-case
              6.3.12 xf:lower-case
              6.3.13 xf:translate
              6.3.14 xf:string-pad
              6.3.15 xf:matches
              6.3.16 xf:replace
              6.3.17 xf:tokenize
              6.3.18 xf:escape-uri
      7 Functions and Operators on
      Booleans
          7.1 Boolean
      Constructor Functions
              7.1.1 xf:true
              7.1.2 xf:false
          7.2 Operators on
      Boolean Values
              7.2.1 op:boolean-equal
              7.2.2 op:boolean-less-than
              7.2.3 op:boolean-greater-than
          7.3 Functions on
      Boolean Values
              7.3.1 xf:not
      8 Functions and Operators on
      Durations, Dates, and Times
          8.1 Duration,
      Date, and Time Types
          8.2 Two
      Totally Ordered Subtypes of Duration
              8.2.1 yearMonthDuration
              8.2.2 dayTimeDuration
          8.3 Comparisons of Duration, Date
      and Time Values
              8.3.1 op:duration-equal
              8.3.2 op:yearMonthDuration-equal
              8.3.3 op:yearMonthDuration-less-than
              8.3.4 op:yearMonthDuration-greater-than
              8.3.5 op:dayTimeDuration-equal
              8.3.6 op:dayTimeDuration-less-than
              8.3.7 op:dayTimeDuration-greater-than
              8.3.8 op:dateTime-equal
              8.3.9 op:dateTime-less-than
              8.3.10 op:dateTime-greater-than
              8.3.11 op:date-equal
              8.3.12 op:date-less-than
              8.3.13 op:date-greater-than
              8.3.14 op:time-equal
              8.3.15 op:time-less-than
              8.3.16 op:time-greater-than
              8.3.17 op:gYearMonth-equal
              8.3.18 op:gYear-equal
              8.3.19 op:gMonthDay-equal
              8.3.20 op:gMonth-equal
              8.3.21 op:gDay-equal
          8.4 Component
      Extraction Functions on Duration, Date and Time
      Values
              8.4.1 xf:get-years-from-yearMonthDuration
              8.4.2 xf:get-months-from-yearMonthDuration
              8.4.3 xf:get-days-from-dayTimeDuration
              8.4.4 xf:get-hours-from-dayTimeDuration
              8.4.5 xf:get-minutes-from-dayTimeDuration
              8.4.6 xf:get-seconds-from-dayTimeDuration
              8.4.7 xf:get-year-from-dateTime
              8.4.8 xf:get-month-from-dateTime
              8.4.9 xf:get-day-from-dateTime
              8.4.10 xf:get-hours-from-dateTime
              8.4.11 xf:get-minutes-from-dateTime
              8.4.12 xf:get-seconds-from-dateTime
              8.4.13 xf:get-timezone-from-dateTime
              8.4.14 xf:get-year-from-date
              8.4.15 xf:get-month-from-date
              8.4.16 xf:get-day-from-date
              8.4.17 xf:get-timezone-from-date
              8.4.18 xf:get-hours-from-time
              8.4.19 xf:get-minutes-from-time
              8.4.20 xf:get-seconds-from-time
              8.4.21 xf:get-timezone-from-time
          8.5 Arithmetic
      Functions on yearMonthDuration and dayTimeDuration
              8.5.1 op:add-yearMonthDurations
              8.5.2 op:subtract-yearMonthDurations
              8.5.3 op:multiply-yearMonthDuration
              8.5.4 op:divide-yearMonthDuration
              8.5.5 op:add-dayTimeDurations
              8.5.6 op:subtract-dayTimeDurations
              8.5.7 op:multiply-dayTimeDuration
              8.5.8 op:divide-dayTimeDuration
          8.6 Timezone Functions on dateTime,
      date, and time
              8.6.1 xf:add-timezone-to-dateTime
              8.6.2 xf:remove-timezone-from-dateTime
              8.6.3 xf:add-timezone-to-date
              8.6.4 xf:add-timezone-to-time
              8.6.5 xf:remove-timezone-from-time
          8.7 Functions and Operators on
      TimePeriod Values
              8.7.1 xf:get-yearMonthDuration-from-dateTimes
              8.7.2 xf:get-dayTimeDuration-from-dateTimes
              8.7.3 op:subtract-dates
              8.7.4 op:subtract-times
              8.7.5 op:add-yearMonthDuration-to-dateTime
              8.7.6 op:add-dayTimeDuration-to-dateTime
              8.7.7 op:subtract-yearMonthDuration-from-dateTime
              8.7.8 op:subtract-dayTimeDuration-from-dateTime
              8.7.9 op:add-yearMonthDuration-to-date
              8.7.10 op:add-dayTimeDuration-to-date
              8.7.11 op:subtract-yearMonthDuration-from-date
              8.7.12 op:subtract-dayTimeDuration-from-date
              8.7.13 op:add-dayTimeDuration-to-time
              8.7.14 op:subtract-dayTimeDuration-from-time
      9 Functions on QNames
          9.1 Constructor
      Functions for QNames
              9.1.1 xf:expanded-QName
          9.2 Functions on
      QNames
              9.2.1 op:QName-equal
              9.2.2 xf:get-local-name-from-QName
              9.2.3 xf:get-namespace-from-QName
      10 Functions and Operators for
      anyURI
          10.1 Constructor
      Functions for anyURI
              10.1.1 xf:resolve-uri
          10.2 Functions on
      anyURI
              10.2.1 op:anyURI-equal
      11 Functions and Operators on base64Binary
      and hexBinary
          11.1 Comparisons
      of base64Binary and hexBinary Values
              11.1.1 op:hex-binary-equal
              11.1.2 op:base64-binary-equal
      12 Functions and Operators on
      NOTATION
          12.1 Functions on
      NOTATION
              12.1.1 op:NOTATION-equal
      13 Functions and Operators on
      Nodes
          13.1 Functions and
      Operators on Nodes
              13.1.1 xf:name
              13.1.2 xf:local-name
              13.1.3 xf:namespace-uri
              13.1.4 xf:number
              13.1.5 xf:lang
              13.1.6 op:node-equal
              13.1.7 xf:deep-equal
              13.1.8 op:node-before
              13.1.9 op:node-after
              13.1.10 xf:copy
              13.1.11 xf:root
          13.2 xf:if-absent() and
      xf:if-empty()
              13.2.1 xf:if-absent
              13.2.2 xf:if-empty
      14 Functions and Operators on
      Sequences
          14.1 Constructor
      Functions on Sequences
              14.1.1 op:to
          14.2 Functions and
      Operators on Sequences
              14.2.1 xf:boolean
              14.2.2 op:concatenate
              14.2.3 xf:item-at
              14.2.4 xf:index-of
              14.2.5 xf:empty
              14.2.6 xf:exists
              14.2.7 xf:distinct-nodes
              14.2.8 xf:distinct-values
              14.2.9 xf:insert
              14.2.10 xf:remove
              14.2.11 xf:subsequence
          14.3 Equals,
      Union, Intersection and Except
              14.3.1 xf:sequence-deep-equal
              14.3.2 xf:sequence-node-equal
              14.3.3 op:union
              14.3.4 op:intersect
              14.3.5 op:except
          14.4 Aggregate
      Functions
              14.4.1 xf:count
              14.4.2 xf:avg
              14.4.3 xf:max
              14.4.4 xf:min
              14.4.5 xf:sum
          14.5 Functions that Generate
      Sequences
              14.5.1 xf:id
              14.5.2 xf:idref
              14.5.3 xf:document
              14.5.4 xf:collection
              14.5.5 xf:input
      15 Context Functions
          15.1 xf:context-item
          15.2 xf:position
          15.3 xf:last
          15.4 op:context-document
          15.5 xf:current-dateTime
              15.5.1 Examples
          15.6 xf:current-date
              15.6.1 Examples
          15.7 xf:current-time
              15.7.1 Examples
      16 Casting Functions
          16.1 Casting from
      primitive types to primitive types
          16.2 Casting from
      derived types to primitive types
          16.3 Casting to derived
      types
          16.4 Casting from strings
          16.5 Casting within a branch of the
      type hierarchy
          16.6 Casting to string
          16.7 Casting to numeric
      types
          16.8 Casting to duration
      and date and time types
          16.9 Casting to boolean
          16.10 Casting to
      base64Binary and hexBinary
          16.11 Casting to anyURI
      and NOTATION
      
A References
          A.1 Normative
          A.2 Non-normative
      B Compatibility with XPath
      1.0 (Non-Normative)
      C Functions and Operators Issues List
      (Non-Normative)
      D ChangeLog since Last Public Version on
      2002-04-30 (Non-Normative)
      E Function and Operator Quick
      Reference (Non-Normative)
          E.1 Functions and
      Operators by Section
          E.2 Functions and
      Operators Alphabetically
      
[XML Schema Part 2: Datatypes] defines a number of primitive and derived datatypes, collectively known as built-in datatypes. This document defines operations on those datatypes for use in XQuery, XPath, XSLT and related XML standards. This document also discusses operators and functions on nodes and node sequences as defined in the [XQuery 1.0 and XPath 2.0 Data Model] for use in XQuery, XPath, XSLT and other related XML standards.
The terminology used to describe the functions and operators on [XML Schema Part 2: Datatypes] is defined in the body of this specification. The terms defined in the following list are used in building those definitions:
A feature of this specification included to ensure that implementations that use this feature remain compatible with [XPath 1.0]
Conforming documents and processors are permitted to but need not behave as described.
Conforming documents and processors are required to behave as described; otherwise, they are non-conformant or in error.
Possibly differing between implementations, but specified by the implementor for each particular implementation.
Possibly differing between implementations, but not specified by this or other W3C specification, and not required to be specified by the implementor for any particular implementation.
The diagram below shows the built-in [XML Schema Part 2: Datatypes]. Solid lines connect a base datatype above to a derived datatype below. Dashed lines connect a datatype created as a list of an item type above.
          Diagram courtesy Asir Vedamuthu, webMethods
The purpose of this document is to catalog the functions and operators required for XPath 2.0, XML Query 1.0, and XSLT 2.0. The exact syntax used to invoke these functions and operators is specified in [XPath 2.0], [XQuery 1.0: An XML Query Language], and [XSLT 2.0].
In general, the above specifications do not support
          function overloading. Consequently, there are no
          overloaded functions in this document except for legacy
          [XPath 1.0] functions such as
          string() which takes a single argument of a
          variety of types and concat() which takes a
          variable number of string arguments. This does not apply
          to operators such as "+" which may be overloaded.
          Functions with optional arguments are allowed. If
          optional arguments are omitted, omissions are assumed to
          begin from the right.
This document defines, among other things, constructor functions and other functions that apply to one or more data types. Each function is defined by specifying its signature, a description of each of its arguments, and its semantics. For many functions, examples are included to illustrate their use.
Each function's signature is presented in a form like this:
xf:function-name(parameter-type $parameter-name, ...) => return-type
            In this notation, function-name is the
          name of the function whose signature is being specified.
          If the function takes no parameters, then the name is
          followed by an empty set of parentheses: ();
          otherwise, the name is followed by a parenthesized list
          of parameter declarations, each declaration specifying
          the static type of the parameter and a non-normative name
          used to reference the parameter when the function's
          semantics are specified. If there are two or more
          parameter declarations, they are separated by a comma.
          The return-type specifies the static type of
          the value returned by the function.
The function name is a QName as defined
          in [XML 1.0 Recommendation (Second
          Edition)] and must adhere to its syntactic
          conventions. Following [XPath 1.0],
          function names are composed of English words separated by
          hyphens,"-". If a function name contains a [XML Schema Part 2: Datatypes]
          datatype name, this may have intercapitalized spelling
          and is used in the function name as such. For example, xf:get-timezone-from-dateTime.
As is customary, the parameter type name indicates that the function accepts arguments of that type, or types derived from it, in that position.
Some functions accept the empty sequence as an argument and some may return the empty sequence. This is indicated in the function signature by following the parameter type name with a question mark:
xf:function-name(parameter-type? $parameter-name)
              => return-type?
            [Issue 133: Syntax for indicating that function accepts empty sequence is incorrect]
The functions and operators discussed in this document
          are contained in two namespaces (see [Namespaces in XML]) and
          referenced using a QName. The namespace prefix used in
          this document—merely for illustrative
          purposes—is xf: for the user functions
          and op: for the operator functions. The
          namespace prefix for these functions can vary, as long as
          the prefix is bound to the currect URI.
The actual namespaces (that is, the URIs of the namespaces) are:
              http://www.w3.org/2002/08/xquery-operators
              for operators
              http://www.w3.org/2002/08/xquery-functions
              for functions.
The functions defined with an xf: prefix
          are callable by the user. Functions defined with the
          op: prefix are described here to underpin
          the definitions of the operators in [XPath 2.0], [XQuery
          1.0: An XML Query Language], and [XSLT 2.0]. These functions are not
          available directly to users, and there is no requirement
          that implementations should actually provide these
          functions. For example, multiplication is generally
          associated with the * operator, but it is
          described as a function in this document. For
          example:
op:multiply(numeric $operand1, numeric $operand2) =>
              numeric
            The [XQuery 1.0 and XPath 2.0 Data Model] describes accessors on different types of nodes and defines their semantics. Some of these accessors are exposed to the user through the functions described below.
| Function | Accessor | Accepts | Returns | 
|---|---|---|---|
xf:node-kind | 
            node-kind | 
            any kind of node | string | 
xf:node-name | 
            name | 
            any kind of node | zero or one QName | 
xf:string | 
            
            string-value | 
            item | string | 
xf:data | 
            
            typed-value | 
            any kind of node | a sequence of atomic values | 
xf:base-uri | 
            base-uri | 
            Element or Document node | zero or one anyURI | 
xf:unique-ID | 
            unique-ID | 
            Element node | zero or one ID | 
xf:node-kind(node $srcval) => string
            This function returns a string value representing the node's kind: either "document", "element", "attribute", "text", "namespace", "processing-instruction", or "comment".
xf:node-name(node $srcval) => QName?
            This function returns an expanded QName for node kinds that can have names. For other node kinds, it returns the empty sequence. Expanded QName is defined in [XQuery 1.0 and XPath 2.0 Data Model], and consists of a namespace URI and a local name.
xf:string()
              => string
            xf:string(item $srcval) => string
            Returns the value of $srcval represented
          as a string. If no argument is supplied,
          $srcval defaults to the context item
          (.).
If $srcval is the empty sequence, the
          zero-length string is returned.
If $srcval is a node, the function
          returns the string value of the node, as obtained using
          the string-value accessor defined in the [XQuery 1.0 and XPath 2.0 Data
          Model].
If $srcval is an atomic value, then the
          function returns the same string as is returned by the
          expression cast as xs:string ($srcval),
          except in the cases listed below:
| Editorial note | |
| The "special rule" for xf:string, in which decimal values without a fractional component are converted to xs:string without a trailing decimal point, has been eliminated. This has not yet been considered by the Working Groups, but is felt to be appropriate for inclusion in this edition of this document. | |
If the type of $srcval is
              xs:anyURI, the URI is converted to a
              string without any escaping of special
              characters.
NOTE: The reason for the special rule for
          xs:anyURI is that, although XML Schema
          strongly discourages the use of spaces within URI values,
          the escaping of spaces can cause problems with legacy
          applications (for example, this applies to spaces within
          fragment identifiers in many HTML browsers), and should
          therefore be under user control.
NOTE: The string representation of double values is not backwards-compatible with the representation of number values in [XPath 1.0]. Ordinary double values are now represented using scientific notation; the representations of positive and negative infinity are now 'INF' and '-INF' rather than 'Infinity' and '-Infinity'. (It should be observed that '+INF' is not supported as a lexical form of infinity in [XML Schema Part 2: Datatypes] and is thus not supported by this specification; if that lexical form is added in a future version of [XML Schema Part 2: Datatypes], then it will be supported by a future version of this specification that aligns with that future version of [XML Schema Part 2: Datatypes].) However, most expressions that would have produced a number in [XPath 1.0] will produce a decimal (or integer) in [XPath 2.0], so unless there is a loss of precision caused by numeric approximation, the result of the expression will in most simple cases be the same after conversion to a string.
[Issue 160: Align the string() function with 'cast as string'.]
xf:data(node $srcval) => atomic value*
            If $srcval is a text node, an element
          node, or an attribute node, xf:data returns
          the typed value of $srcval, as defined by
          the accessor function dm:typed-value defined
          for that kind of node in [XQuery 1.0
          and XPath 2.0 Data Model].
Specifically:
If $srcval is a text node, then its typed
          value is equal to its string value, as an instance of
          xs:anySimpleType.
If $srcval is an attribute node with type
          annotation xs:anySimpleType, then its typed
          value is equal to its string value, as an instance of
          xs:anySimpleType. The typed value of any
          other attribute node is derived from its string value and
          type annotation in a way that is consistent with schema
          validation, as described in [XQuery
          1.0 and XPath 2.0 Data Model].
If $srcval is an element node with type
          annotation xs:anySimpleType, then its typed
          value is equal to its string value, as an instance of
          xs:anySimpleType. The typed value of an
          element nodes with a type annotation other than
          xs:anySimpleType is derived from its string
          value and type annotation in a way that is consistent
          with schema validation, as described in [XQuery 1.0 and XPath 2.0 Data
          Model].
If $srcval is not a text node, an
          attribute node, or an element node, then
          xf:data causes a static type error.
xf:base-uri(node $srcval) => anyURI?
            For document and element nodes this function returns the value of the base-uri property. For other kinds of node it returns the empty sequence.
xf:unique-ID(node $srcval) => ID?
            This function accepts an element node and returns the identifier (ID) which may have been assigned by the user. It corresponds to the normalized value property of the attribute information item in the attributes property that has a type ID, if one exists. If no ID attribute exists the empty sequence is returned.
In this document, as well as in [XQuery 1.0: An XML Query Language], [XPath 2.0],and [XQuery 1.0 and XPath 2.0 Formal
        Semantics], the phrase "an error is raised" is used
        whenever the semantics being described encounter an error
        other than a static type error. The occurrence of that
        phrase implicitly causes the invocation of the
        xf:error function defined in this section.
        Whenever the raising of an error is accompanied by a
        specific error, the phrase "an error is raised
        (name-of-error)" is used, and the value
        name-of-error is passed as an argument to the
        xf:error function invocation. The
        xf:error function may also be invoked from
        XQuery and XPath 2.0 applications.
xf:error()
          xf:error(item $srcval)
          The xf:error function accepts any item
        (e.g., an atomic value or an element) as an argument, and
        may be invoked without any argument. The
        xf:error function never returns a value.
[Issue 181: What are the semantics of xf:error?]
[Issue 182: Every condition that raises an error should specify what error is raised]
Every built-in type that is defined in [XML Schema Part 2: Datatypes], as well
        as each of the two derived types xf:yearMonthDuration
        and xf:dayTimeDuration
        defined in this specification, has an associated
        constructor function. The form of that function for a type
        TYP is:
xs:TYP(item $srcval) => TYP
          For example, the signature of the constructor function
        corresponding to the unsignedInt type is:
xs:unsignedInt(item $srcval) => unsignedInt
          An invocation of that constructor function such as
        xs:unsignedInt(12) returns the
        unsignedInt value 12. Another invocation of
        that constructor function that returns the same
        unsignedInt value is
        xs:unsignedInt("12").
The semantics of the constructor function
        xs:TYP(item) are identical to the semantics of
        cast as xs:TYP (item).
Where the argument to a constructor function is a literal, the literal must be a valid lexical form of its type, as specified in [XML Schema Part 2: Datatypes].
Where the argument to a constructor function is a literal, the result of the function may be evaluated statically; if an error is found during such evaluation, it may be reported as a static error.
This section discusses arithmetic operators on the numeric datatypes defined in [XML Schema Part 2: Datatypes]. It uses an approach that permits lightweight operations whenever possible.
The operators described in this section are defined on the following numeric types. Each type whose name is indented is derived from the type whose name appears nearest above with one less level of indent.
| decimal | |
| integer | |
| float | |
| double | 
They also apply to user-defined types derived by restriction from these types.
The following functions are defined to back up operators defined in [XQuery 1.0: An XML Query Language] and [XPath 2.0] on these numeric types.
| Function | Meaning | Source | 
|---|---|---|
op:numeric-add | 
              Addition | XPath 1.0 | 
op:numeric-subtract | 
              Subtraction | XPath 1.0 | 
op:numeric-multiply | 
              Multiplication | XPath 1.0 | 
op:numeric-divide | 
              Division | XPath 1.0 | 
op:numeric-integer-divide | 
              Integer division | XPath 1.0 | 
op:numeric-mod | 
              Modulus | XPath 1.0 | 
op:numeric-unary-plus | 
              Unary plus | XPath 2.0 Req 1.7 Should | 
op:numeric-unary-minus | 
              Unary minus (negation) | XPath 1.0 | 
The arguments and return types for the arithmetic
          operators are the basic numeric types:
          integer, decimal,
          float, and double, and types
          derived from them. For simplicity, each operator is
          defined to operate on operands of the same datatype and
          to return the same datatype. (The one exception is op:numeric-divide,
          which returns a double if called with two integer
          operands.) If the two operands are not of the same
          datatype, one operand is promoted to be the type of the
          other operand.
The type promotion scheme includes only two rules:
A derived type may be promoted to its base type.
              In particular, integer may be promoted
              to decimal.
decimal may be promoted to
              float, and float may be
              promoted to double.
The result type of operations depends on their argument datatypes and is defined in the following table:
| Operator | Returns | 
|---|---|
              op:operation(integer, integer) | 
              integer (except for op:numeric-divide(integer,
              integer), which returns a double) | 
            
              op:operation(decimal, decimal) | 
              decimal | 
op:operation(float,
              float) | 
              float | 
              op:operation(double, double) | 
              double | 
              op:operation(integer) | 
              integer | 
              op:operation(decimal) | 
              decimal | 
              op:operation(float) | 
              float | 
              op:operation(double) | 
              double | 
These rules define any operation on any pair of arithmetic types. Consider the following example:
op:operation(int, double) => op:operation(double, double)
For this operation, int must be converted
          to double. This can be done, since by the
          rules above: int can be promoted to
          integer, integer can be
          promoted to decimal, decimal
          can be promoted to float, and
          float can be promoted to
          double. As far as possible, the promotions
          should be done in a single step. Specifically, when a
          decimal is promoted to a double, it must not be converted
          to a float and then to double as this will lose
          precision.
As another example, a user may define
          height as a derived type of
          integer with a minimum value of 20 and a
          maximum value of 100. He may then derive
          oddHeight using a pattern to restrict the
          value to odd integers.
op:operation(oddHeight, integer) => op:operation(integer, integer)
oddHeight is first promoted to its base
          type height. height is promoted
          to its base type integer.
[Issue 177: Must overflow and underflow always be reported?]
Overflow and underflow behavior is ·implementation-defined·. See [ISO 10967]. That is, implementations may determine that, when overflow or underflow is detected in any of the above operations, an error is raised ("overflow or underflow error"). However, implementations are not required to catch or report such errors.
Finally, consider some examples involving special IEEE 754 numerics.
If either argument is "NaN", the result is "NaN".
If neither argument is "NaN", but either argument is "INF", the result is "INF".
If neither argument is "NaN" or "INF", but either argument is "-INF", the result is "-INF".
Note: In the case of multiplication and division, "INF" may become "-INF", and vice versa, as appropriate.
The functions op:numeric-add,
          op:numeric-subtract,
          op:numeric-multiply,
          op:numeric-divide,
          op:numeric-integer-divide,
          and op:numeric-mod
          are each defined for pairs of numeric operands, each of
          which has the same type: integer, decimal, float, or
          double. The functions op:numeric-unary-plus
          and op:numeric-unary-minus
          are defined for a single operand whose type is one of
          those same numeric types.
op:numeric-add(numeric $operand1, numeric $operand2) =>
                numeric
              Backs up the "+" operator and returns the arithmetic
            sum of its operands: ($operand1 +
            $operand2).
op:numeric-subtract(numeric $operand1, numeric $operand2) =>
                numeric
              Backs up the "-" operator and returns the arithmetic
            difference of its operands: ($operand1 -
            $operand2).
op:numeric-multiply(numeric $operand1, numeric $operand2) =>
                numeric
              Backs up the "*" operator and returns the arithmetic
            product of its operands: ($operand1 *
            $operand2).
op:numeric-divide(numeric $operand1, numeric $operand2) =>
                numeric
              Backs up the "div" operator and returns the
            arithmetic quotient of its operands: ($operand1
            div $operand2).
Note:
For compatibility with [XPath
              1.0], if the types of both $operand1
              and $operand2 are
              xs:integer, then the return type is
              xs:double.
For xs:decimal and
            xs:integer operands, if the divisor is
            0, then an error is raised ("Division by
            zero"). For xs:float and
            xs:double operands, performs floating
            point division as specified in [IEEE
            754-1985].
op:numeric-integer-divide( | 
                    integer  | 
                    $operand1, | 
                  
integer  | 
                    $operand2)
                    => integer | 
                  
Backs up the "idiv" operator and returns the
            arithmetic quotient of its operands: ($operand1
            idiv $operand2). If the quotient is not evenly
            divided by the divisor, then the quotient is the
            integer value obtained, ignoring any remainder that
            results from the division (that is, no rounding is
            performed).
If the divisor is 0, then an error is
            raised ("Division by zero").
op:numeric-mod(numeric $operand1, numeric $operand2) =>
                numeric
              Backs up the "mod" operator and returns the
            remainder after dividing the first operand by the
            second operand: ($operand1 mod $operand2).
            The result is of the same type as the operands after
            type promotion. The following rules apply:
For xs:decimal and
                xs:integer operands, if the divisor is
                0, then an error is raised ("Division
                by zero").
For xs:float and
                xs:double operands:
If either operand is NaN, the result is NaN.
If the dividend is positive or negative infinity, or the divisor is positive or negative zero (0), or both, the result is NaN.
If not NaN, the sign of the result equals the sign of the dividend.
If the dividend is finite and the divisor is an infinity, the result equals the dividend.
If the dividend is positive or negative zero and the divisor is finite, the result is the same as the dividend.
In the remaining cases, where neither positive or negative infinity, nor positive or negative zero, nor NaN is involved, the float or double remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n-(d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d. This is truncating division, analogous to integer division, not [IEEE 754-1985] rounding division.
We define the following comparison operators on
          numeric values. Comparisons take two arguments of the
          same type. If the arguments are of different types, one
          argument is promoted to the type of the other. Each
          comparison operator returns a boolean value. If either,
          or both, operands are "NaN", false is
          returned.
| Operator | Meaning | Source | 
|---|---|---|
op:numeric-equal | 
              Equality comparison | XPath 1.0 | 
op:numeric-less-than | 
              Less-than comparison | XPath 1.0 | 
op:numeric-greater-than | 
              Greater-than comparison | XPath 1.0 | 
op:numeric-equal(numeric $operand1, numeric $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. For
            xs:float and xs:double
            values, 0 (zero), +0
            (positive zero), and -0 (negative zero)
            all compare equal. NaN does not equal
            itself.
This function backs up the "eq" and "ne" operators on numeric values.
op:numeric-less-than(numeric $operand1, numeric $operand2) =>
                boolean
              Returns true if and only if $operand1
            is less than $operand2. For
            xs:float and xs:double
            values, positive infinity is greater than all other
            non-NaN values; negative infinity is less than all
            other non-NaN values. NaN is not comparable with
            (neither greater than nor less than) any other value
            including itself.
This function backs up the "lt" and "ge" operators on numeric values.
op:numeric-greater-than(numeric $operand1, numeric $operand2) =>
                boolean
              Returns true if and only if $operand1
            is greater than $operand2. For
            xs:float and xs:double
            values, positive infinity is greater than all other
            non-NaN values; negative infinity is less than all
            other non-NaN values. NaN is not comparable with
            (neither greater than nor less than) any other value
            including itself.
This function backs up the "gt" and "le" operators on numeric values.
The following functions are defined on these numeric types. Each function returns an integer except:
If the argument is the empty sequence, the empty sequence is returned.
If the argument is "NaN", "NaN" is returned.
If the argument is positive or negative infinity, positive or negative infinity is returned.
| Function | Meaning | Source | 
|---|---|---|
xf:floor | 
              Returns the largest integer less than or equal to the argument | XPath 1.0 | 
xf:ceiling | 
              Returns the smallest integer greater than or equal to the argument | XPath 1.0 | 
xf:round | 
              Rounds to the nearest integer | XPath 1.0 | 
[Issue 79: How many digits of precision (etc.) are returned from certain functions?]
[Issue 142: Should floor ceiling and round return the same type as their argument? ]
[Issue 179: What is the appropriate return type for xf:floor, xf:celing, and xf:round?]
xf:floor(double? $srcval) =>
                double?
              Returns the largest (closest to positive infinity)
            integer that is not greater than the value of
            $srcval. If the argument is the empty
            sequence, returns the empty sequence.
xf:ceiling(double? $srcval) =>
                double?
              Returns the smallest (closest to negative infinity)
            integer that is not smaller than the value of
            $srcval. If the argument is the empty
            sequence, returns the empty sequence.
xf:round(double? $srcval) =>
                double?
              Returns the number that is closest to the argument.
            If there are two such numbers, then the one that is
            closest to positive infinity is returned. More
            formally, xf:round(x) produces the same
            result as xf:floor(x+0.5). If
            the argument is NaN, then NaN is returned. If the
            argument is positive infinity, then positive infinity
            is returned. If the argument is negative infinity, then
            negative infinity is returned. If the argument is
            positive zero (+0), then positive zero (+0) is
            returned. If the argument is negative zero (-0), then
            negative zero (-0) is returned. If the argument is less
            than zero (0), but greater than or equal to -0.5, then
            negative zero (-0) is returned. If the argument is the
            empty sequence, then the empty sequence is
            returned.
This section discusses functions and operators on the [XML Schema Part 2: Datatypes] string datatype and the datatypes derived from string.
The operators described in this section are defined on the following string types. Each type whose name is indented is derived from the type whose name appears nearest above with one less level of indent.
| string | |||||
| normalizedString | |||||
| token | |||||
| language | |||||
| NMTOKEN | |||||
| Name | |||||
| NCName | |||||
| ID | |||||
| IDREF | |||||
| ENTITY | 
They also apply to user-defined types derived by restriction from these types.
When values whose type is string or some type derived from string are compared (or, equivalently, sorted), the comparisons are inherently performed according to some collation (even if that collation is defined entirely on code point values or on the binary representations of the characters of the string). The [Character Model for the World Wide Web 1.0] observes that some applications may require different comparison and ordering behaviors than other applications. Similarly, some users having particular linguistic expectations may require different behaviors than other users. Consequently, the collation must be taken into account when comparing strings in any context. Several functions in this and the following section make use of a collation.
Collations can indicate that some characters that are rendered differently are, in fact equal for collation purpose (e.g., "uve" and "uwe" are considered equivalent in some European languages). Strings can be compared character-by-character or in a logical manner, as defined by the collation.
Some collations, especially those based on the [Unicode Collation Algorithm] can be "tailored" for various purposes. This document does not discuss such tailoring. Instead, it assumes that the collation argument to the various functions below is a tailored and named collation. A specific collation with a distinguished name, http://www.w3.org/2002/08/query-operators/collation/codepoint, provides the ability to compare strings based on code point values. Every implementation of XQuery must support the collation based on code point values.
NOTE: This document uses the term "code point" as a synonym for "Unicode scalar value". [The Unicode Standard] sometimes spells this term "codepoint". Code points range from #x0000 to #x10FFFF inclusive.
While the [Character Model for the World Wide Web 1.0] recommends that all strings be subjected to early Unicode normalization, it is not possible to guarantee that all strings in all XML documents are, in fact, normalized, or that they are normalized in the same manner. In order to maximize interoperable results of operations on XML documents in general, there may be collations that operate on unnormalized strings, other collations that raise runtime errors when unnormalized strings are encountered, and still other collations that implicitly normalize strings for the purposes of collating them. For alignment with the [Character Model for the World Wide Web 1.0], applications may choose collations that treat unnormalized strings as though they were normalized (that is, that implicitly normalize the strings). Note that collations based on the Unicode collation algorithm produce equivalent results regardless of a string's normalization.
This document assumes that collations are named and that the collation name may be provided as an argument to string comparison functions. Functions that allow specification of a collation do so with an argument whose type is anyURI. This document also defines the manner in which a default collation is determined when the collation argument is not specified in invocations of the functions that allow it to be omitted.
The XQuery/XPath static context includes provision for a default collation that can be used for string comparisons (including ordering operations). However, the static context is not required to have a default collation specified; an implementation might choose to provide a default collation only under certain circumstances, or not at all. The static context default collation, if provided, is determined by ·implementation-defined· means. Such means might include determination from the host operating system environment, determination during XQuery/XPath installation, determination when the XQuery/XPath implementation was created, determination from the locale of some user environment, or even ·implementation-defined· language through which the user can specify that collation.
The decision of what collation to use for a given comparison or ordering operation is determined by the following algorithm:
If the operation specifies an explicit collation
              CollationA (e.g., if the optional collation argument
              is specified in an invocation of the xf:compare()
              function), then:
If CollationA is supported by the implementation, then CollationA is used.
Otherwise, an error is raised ("Unsupported collation").
If no collation is explicitly specified for the operation and the XQuery/XPath static context specifies a collation CollationB, then:
If CollationB is supported by the implementation, then CollationB is used.
Otherwise, an error is raised ("Unsupported collation").
NOTE: There might be several ways in which a collation might be specified in the XQuery/XPath static context. For example, XQuery might provide syntax that specifies a default collation as part of the query prolog.
Otherwise, the Unicode codepoint collation (http://www.w3.org/2002/08/query-operators/collation/codepoint) is used.
XML allows elements to specify the xml:lang attribute to indicate the language associated with the content of such an element. This specification does not use xml:lang to identify the default collation, in part because collations should be determined by the user of the data, not (normally) the data itself, and because using xml:lang does not produce desired effects when the two strings to be compared have different xml:lang values or when a string is multilingual.
NOTE: Some data management environments allow collations to be associated with the definition of string items (that is, with the metadata that describes items whose type is string). While such association may be appropriate for use in environments in which data is held in a repository tightly bound to its descriptive metadata, it is not appropriate in the XML environment in which different documents being processed by a single query may be described by differing schemas.
[Issue 44: Collations: URIs and URI references or short names?]
[Issue 170: Some functions require collations with special capabilities. ]
| Function | Meaning | Source | 
|---|---|---|
xf:compare | 
              Compares two character strings; a collation may optionally be specified | XSLT 2.0, Req. 2.13 (Could) | 
[Issue 73: Is a "between" function needed?]
xf:compare(string? $comparand1, string? $comparand2) =>
                integer?
              xf:compare( | 
                    string?  | 
                    $comparand1, | 
                  
string?  | 
                    $comparand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => integer? | 
                  
Returns -1, 0, or 1, depending on whether the value
            of the $comparand1 is respectively less
            than, equal to, or greater than the value of
            $comparand2, according to the rules of the
            collation that is used.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
If the value of $comparand2 begins with
            a string that is equal to the value of
            $comparand1 (according to the collation
            that is used) and has additional characters following
            that beginning string, then the result is -1. If the
            value of $comparand1 begins with a string
            that is equal to the value of $comparand2
            (according to the collation that is used) and has
            additional characters following that beginning string,
            then the result is 1.
If either argument is the empty sequence, the result is the empty sequence.
This function backs up the "eq", "ne", "gt", "lt", "le" and "ge" operators on string values.
xf:compare('abc', 'abc') returns
                  0.
xf:compare('Strasse', 'Straße')
                  returns 0 if and only if the default collation
                  includes provisions that equate "ss" and the
                  (German) character "ß" ("sharp-s"). (Otherwise,
                  the returned value depends on the semantics of
                  the default collation.)
xf:compare('Strasse', 'Straße',
                  anyURI('deutsch')) returns 0 if and only
                  if the collation identified by the relative URI
                  constructed from the string value
                  "deutsch" includes provisions that equate "ss"
                  and the (German) character "ß" ("sharp-s").
                  (Otherwise, the returned value depends on the
                  semantics of that collation.)
xf:compare('Strassen', 'Straße')
                  returns 1 if and only if the default collation
                  includes provisions that equate "ss" and the
                  (German) character "ß" ("sharp-s"). (Since the
                  value of $comparand1 has an
                  additional character, an "n", following the
                  string that is equal to "Straße", it is greater
                  than the value of $comparand2.)
The following functions are defined on these string types. Several of these function use a collation. See 6.2 Equality and Comparison of Strings for a discussion of collations.
| Function | Meaning | Source | 
|---|---|---|
xf:concat | 
              Concatenates two or more character strings. | XPath 1.0 | 
xf:starts-with | 
              Indicates whether the value of one string begins with the characters of the value of another string. | XPath 1.0 | 
xf:ends-with | 
              Indicates whether the value of one string ends with the characters of the value of another string. | XPath 1.0 | 
xf:contains | 
              Indicates whether the value of one string contains the characters of the value of another string. A collation may optionally be specified. | XPath 1.0 | 
xf:substring | 
              Returns a string located at a specified place in the value of a string. | XPath 1.0 | 
xf:string-length | 
              Returns the length of the argument. | XPath 1.0 | 
xf:substring-before | 
              Returns the characters of one string that precede in that string the characters in the value of another string. A collation may optionally be specified. | XPath 1.0 | 
xf:substring-after | 
              Returns the characters of one string that precede in that string the characters in the value of another string. A collation may optionally be specified. | XPath 1.0 | 
xf:normalize-space | 
              Returns the whitespace-normalized value of the argument. | XPath 1.0 | 
xf:normalize-unicode | 
              Returns the normalized value of the first argument in the normalization form specified by the second argument. | XPath 2.0 Req 2.9 (Should) | 
xf:upper-case | 
              Returns the upper-cased value of the argument. | XPath 2.0 Req 2.4.3 (Should) | 
xf:lower-case | 
              Returns the lower-cased value of the argument. | XPath 2.0 Req 2.4.3 (Should) | 
xf:translate | 
              Returns the first argument string with occurrences of characters in the second argument replaced by the character at the corresponding position in the third string. | XPath 1.0 | 
xf:string-pad | 
              Returns a string composed of as many copies of its first argument as specified in its second argument. | XPath 2.0 Req 2.4.2, 4.4 (Should) | 
xf:matches | 
              Returns a boolean value that indicates whether the value of the first argument is matched by the regular expression that is the value of the second argument. | XPath 2.0 Req 3. (Must) | 
xf:replace | 
              Returns the value of the first argument with every substring matched by the regular expression that is the value of the second argument replaced by the replacement string that is the value of the third argument. | XPath 2.0 Req 2.4.1. (Should) | 
xf:tokenize | 
              Returns a sequence of zero or more strings whose values are substrings of the value of the first argument separated by substrings that match the regular expression that is the value of the second argument. | XSLT 2.0 Req (Should) | 
xf:escape-uri | 
              Returns the string representing a URI value with certain characters escaped as specified in [RFC 2396]. | 
[Issue 23: "Returns a copy" is not appropriate wording]
[Issue 21: What is the precise type returned by each function?]
[Issue 108: Should strings always be returned in Unicode normalized form?]
Note also that when the above operators and functions
          are applied to datatypes derived from
          string, they are guaranteeed to return legal
          strings, but they may not return legal value for the
          particular subtype to which they were applied.
[Issue 20: Many uses of "character" should be "codepoint"]
xf:concat()
                => string
              xf:concat(string? $op1) => string
              xf:concat(string? $op1, string? $op2, ...) =>
                string
              Accepts zero or more strings as arguments. Returns the string that is the concatenation of the values of its arguments. The resulting string might not be normalized in any Unicode or W3C normalization. If called with no arguments, returns the zero-length string. If any of the arguments is the empty sequence, it is treated as the zero-length string.
The concat() function is specified to
            allow an arbitrary number of string arguments that are
            concatenated together. This capability is retained for
            compatibility with [XPath 1.0]
            and is the only function specified in this document
            that has that characteristic.
[Issue 144: Should the concat function accept sequences as arguments?]
xf:starts-with(string? $operand1, string? $operand2) =>
                boolean?
              xf:starts-with( | 
                    string?  | 
                    $operand1, | 
                  
string?  | 
                    $operand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => boolean? | 
                  
Returns a boolean indicating whether or not the
            value of $operand1 starts with a string
            that is equal to the value of $operand2
            according to the collation that is used.
If the value of $operand2 is the
            zero-length string, then the function returns
            true. If the value of
            $operand1 is the zero-length string and
            the value of $operand2 is not the
            zero-length string, then the function returns
            false.
If the value of $operand1 or
            $operand2 is the empty sequence, the empty
            sequence is returned.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:ends-with(string? $operand1, string? $operand2) =>
                boolean?
              xf:ends-with( | 
                    string?  | 
                    $operand1, | 
                  
string?  | 
                    $operand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => boolean? | 
                  
Returns a boolean indicating whether or not the
            value of $operand1 ends with a string that
            is equal to the value of $operand2
            according to the specified collation.
If the value of $operand2 is the
            zero-length string, then the function returns
            true. If the value of
            $operand1 is the zero-length string and
            the value of $operand2 is not the
            zero-length string, then the function returns
            false.
If the value of $operand1 or
            $operand2 is the empty sequence, the empty
            sequence is returned.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:contains(string? $operand1, string? $operand2) =>
                boolean?
              xf:contains( | 
                    string?  | 
                    $operand1, | 
                  
string?  | 
                    $operand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => boolean? | 
                  
Returns a boolean indicating whether or not the
            value of $operand1 contains (at the
            beginning, at the end, or anywhere within) a string
            equal to the value of $operand2 according
            to the collation that is used.
If the value of $operand2 is the
            zero-length string, then the function returns
            true. If the value of
            $operand1 is the zero-length string and
            the value of $operand2 is not the
            zero-length string, then the function returns
            false.
If the value of $operand1 or
            $operand2 is the empty sequence, the empty
            sequence is returned.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:substring(string? $sourceString, decimal? $startingLoc) =>
                string?
              xf:substring( | 
                    string?  | 
                    $sourceString, | 
                  
decimal?  | 
                    $startingLoc, | 
                  |
decimal?  | 
                    $length)
                    => string? | 
                  
Returns the portion of the value of
            $sourceString beginning at the position
            indicated by the value of $startingLoc and
            continuing for the number of characters indicated by
            the value of $length. More specifically,
            returns the characters in $sourceString
            whose position $p obeys:
xf:round($startingLoc)
            <= $p < xf:round($startingLoc +
            $length)
If $length is not specified, the
            substring identifies characters to the end of
            $sourceString.
If $length is greater than the number
            of characters in the value of
            $sourceString following
            $startingLoc, the substring identifies
            characters to the end of
            $sourceString.
The first character of a string is located at position 1 (not position 0).
If the value of $startingLoc is
            negative or greater than the length of
            $sourceString, then an error is raised
            ("Invalid substring starting argument").
If the value of any of the three parameters is the empty sequence, the empty sequence is returned.
xf:string-length(string? $srcval) =>
                integer?
              Returns an integer equal to the length in characters
            of the value of $srcval. If the value of
            $srcval is the empty sequence, the empty
            sequence is returned.
xf:substring-before(string? $operand1, string? $operand2) =>
                string?
              xf:substring-before( | 
                    string?  | 
                    $operand1, | 
                  
string?  | 
                    $operand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => string? | 
                  
Returns the substring of the value of
            $operand1 that precedes in the value of
            $operand1 the first occurrence of a string
            that is equal to the value of $operand2
            according to the collation that is used.
If the value of $operand2 is the
            zero-length string, then the function returns the value
            of $operand1.
If the value of $operand1 does not
            contain a string that is equal to the value of
            $operand2, then the function returns the
            zero-length string.
If the value of $operand1 or
            $operand2 is the empty sequence, returns
            the empty sequence.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:substring-after(string? $operand1, string? $operand2) =>
                string?
              xf:substring-after( | 
                    string?  | 
                    $operand1, | 
                  
string?  | 
                    $operand2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => string? | 
                  
Returns the substring of the value of
            $operand1 that follows in the value of
            $operand1 the first occurrence of a string
            that is equal to the value of $operand2
            according to the collation that is used.
If the value of $operand2 is the
            zero-length string, then the function returns the value
            of $operand1.
If the value of $operand1 does not
            contain a string that is equal to the value of
            $operand2, then the function returns the
            zero-length string.
If the value of $operand1 or
            $operand2 is the empty sequence, returns
            the empty sequence.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:normalize-space(string? $srcval) =>
                string?
              Returns the value of the string argument with
            whitespace normalized by stripping leading and trailing
            whitespace and replacing sequences of more than one
            whitespace character by a single space. If the value of
            $srcval is the empty sequence, returns the
            empty sequence.
xf:normalize-unicode(string? $srcval) =>
                string?
              xf:normalize-unicode(string? $srcval, string $normalizationForm)
                => string?
              Returns the value of $srcval normalized
            according to the normalization criteria for a
            normalization form identified by the value of
            $normalizationForm. The effective value of
            the $normalizationForm is computed by
            removing leading and trailing blanks, if present, and
            converting to upper case:
If the $normalizationForm is absent, as
            in the first format above, it shall be assumed to be
            "NFC"
If the effective value of
                $normalizationForm is "NFC", then the
                value returned by the function is the value of
                $srcval in Unicode Normalization Form
                C (NFC).
If the effective value of
                $normalizationForm is "NFD", then the
                value returned by the function is the value of
                $srcval in Unicode Normalization Form
                D (NFD).
If the effective value of
                $normalizationForm is "NFKC", then the
                value returned by the function is the value of
                $srcval in Unicode Normalization Form
                KC (NFKC).
If the effective value of
                $normalizationForm is "NFKD", then the
                value returned by the function is the value of
                $srcval in Unicode Normalization Form
                KD (NFKD).
If the effective value of
                $normalizationForm is "W3C", then the
                value returned by the function is the value of
                $srcval is the fully normalized form.
                See [Character Model for the
                World Wide Web 1.0].
If the effective value of
                $normalizationForm is the zero-length
                string then no normalization is performed and
                $srcval is returned.
Implementations may choose to support other normalization forms in addition to the normalization forms discussed above.
If the effective value of the
            $normalizationForm is other than one of
            the values supported by the implementation, then an
            error is raised ("Invalid normalization form").
If the value of $srcval is the empty
            sequence, returns the empty sequence.
xf:upper-case(string? $srcval) =>
                string?
              Returns the value of $srcval after
            translating every lower-case letter to its upper-case
            correspondent. Every lower-case letter that does not
            have an upper-case correspondent, and every character
            that is not a lower-case letter, is included in the
            returned value in its original form.
A "lower-case letter" is a character whose Unicode General Category class includes "Ll". The corresponding upper-case letter is determined using [Unicode Case Mappings].
If the value of $srcval is the empty
            sequence, returns the empty sequence.
xf:lower-case(string? $srcval) =>
                string?
              Returns the value of $srcval after
            translating every upper-case letter to its lower-case
            correspondent. Every upper-case letter that does not
            have a lower-case correspondent, and every character
            that is not an upper-case letter, is included in the
            output in its original form.
An "upper-case letter" is a character whose Unicode General Category class includes "Lu". The corresponding lower-case letter is determined using [Unicode Case Mappings].
If the value of $srcval is the empty
            sequence, returns the empty sequence.
xf:translate( | 
                    string?  | 
                    $srcval, | 
                  
string?  | 
                    $mapString, | 
                  |
string?  | 
                    $transString)
                    => string? | 
                  
Returns the value of $srcval modified
            so that every character in the value of
            $srcval that occurs at some position
            N in the value of $mapString has
            been replaced by the character that occurs at position
            N in the value of
            $transString.
Every character in the value of $srcval
            that does not appear in the value of
            $mapString is unchanged.
Every character in the value of $srcval
            that appears at some position M in the value
            of $mapString, where the value of
            $transString is less than M
            characters in length, is omitted from the returned
            value.
If the value of $srcval or
            $mapString or $transString is
            the empty sequence, returns the empty sequence.
xf:string-pad(string? $padString, decimal? $padCount) =>
                string?
              Returns a string consisting of
            $padCount copies of
            $padString concatenated together. Returns
            the zero-length string if $padCount is
            zero (0).
If the value of $padCount is less than
            zero (0), then an error is raised ("Invalid string-pad
            count").
If the value of $padString or
            $padCount is the empty sequence, returns
            the empty sequence.
xf:matches(string? $input, string? $pattern) =>
                boolean?
              xf:matches(string? $input, string? $pattern, string? $flags) => boolean?
              The effect of calling the first version of this
            function (omitting the argument $flags) is
            the same as the effect of calling the second version
            with the $flags argument set to a
            zero-length string.
The function returns true if $input
            matches the regular expression supplied as
            $pattern; otherwise, it returns false.
If any of the arguments is an empty sequence, the result is an empty sequence.
Unless the metacharacters ^ and
            $ are used as anchors, the string is
            considered to match the pattern if any substring
            matches the pattern. But if anchors are used, the
            anchors must match the start/end of the string (in
            string mode), or the start/end of a line (in multiline
            mode).
Note:
This is different from the behavior of patterns in XML Schema, where regular expressions are implicitly anchored.
An error is raised ("Invalid matches argument") if
            the value of $pattern or of
            $flags does not conform to the required
            syntax defined in section 6.3.15.1 Regular Expression
            Syntax.
The regular expression syntax used by these functions is defined in terms of the regular expression syntax specified in XML Schema (see [XML Schema Part 2: Datatypes]), which in turn is based on the established conventions of languages such as Perl. However, because XML Schema uses regular expressions only for validity checking, it has omitted some facilities that are widely-used with languages such as Perl, and this section therefore describes extensions to the XML Schema regular expressions syntax that re-instate these capabilities.
The regular expression syntax and semantics for these functions are identical to those defined in [XML Schema Part 2: Datatypes] [add reference] with the following additions:
Two modes are defined, string mode and multiline mode.
Two meta-characters, ^ and
                  $ are added. In string mode, the
                  metacharacter ^ matches the start of
                  the entire string, while $ matches
                  the end of the entire string. In multiline mode,
                  ^ matches the start of any line
                  (that is, the start of the entire string, and the
                  position immediately after a newline character),
                  while $ matches the end of any line
                  (that is, the end of the entire string, and the
                  position immediately before a newline
                  character).
In string mode, the metacharacter
                  . matches any character whatsoever.
                  In multiline mode, the metacharacter
                  . matches any character except a
                  newline character.
Reluctant quantifiers are supported, specifically:
X?? matches X, once or not at
                      all
X*? matches X, zero or more
                      times
X+? matches X, one or more
                      times
X{n}? matches X, exactly n
                      times
X(n,}? matches X, at least n
                      times
X{n,m}? matches X, at least n
                      times, but not more than m times
The effect of these quantifiers is that the regular expression matches the shortest possible substring (consistent with the match as a whole succeeding). In the absence of these quantifiers, the regular expression matches the longest possible substring.
To achieve this, the production in XML Schema:
[4] quantifier ::= [?*+] | ( '{'
                  quantity '}' )
is changed to:
[4] quantifier ::= ( [?*+] | ( '{'
                  quantity '}' ) ) '?'?
Sub-expressions (groups) within the regular expression are recognized. The regular expression syntax defined by XML Schema allows a regular expression to contain parenthesized sub-expressions, but attaches no special significance to them. Some functions described here allow access to the parts of the input string that matched a sub-expression (called captured substrings). The sub-expressions are numbered according to the position of the opening parenthesis in left-to-right order within the top-level regular expression: the first opening parenthesis identifies group 1, the second group 2, and so on. If a sub-expression matches more than one substring (because it is within a construct that allows repetition) then only the last substring that it matched will be captured.
Note:
Reluctant quantifiers have no effect on the
                results of the boolean xf:matches
                function, since this is only interested in
                discovering whether a match exists, and not where
                it exists.
To enable conforming implementations to make use of existing regular expression library routines, this specification does not disallow extensions to the regular expression syntax described here. However, such extensions should only be provided if they conform to an existing recognized specification. All regular expressions that conform to the syntax described here must be accepted, and must implement the semantics described here.
[Issue 176: Should implementations be allowed to extend the regular expression syntax?]
All these functions provide an optional parameter,
              flags, to set options for the
              interpretation of the regular expression. The
              parameter is a string, in which individual letters
              are used to set options. The presence of a letter
              within the string indicates that the option is on,
              its absence indicates that the option is off. Letters
              may appear in any order and may be repeated. If there
              are letters present that are not defined here, then
              an error is raised ("Invalid regular expression
              syntax").
The following options are defined:
m: If present, the match operates
                  in multiline mode. Otherwise, the match operates
                  in string mode.
i: If present, the match operates
                  in case-insensitive mode. Otherwise, the match
                  operates in case-sensitive mode. The detailed
                  rules for character matching in case-insensitive
                  mode are implementation-dependent (and they may
                  be locale-dependent).
xf:matches("abracadabra", "bra")
                  returns true
xf:matches("abracadabra",
                  "^a.*a$") returns true
xf:matches("abracadabra", "^bra")
                  returns false
Given the source document:
<poem author="Wilhelm Busch"> Kaum hat
              dies der Hahn gesehen, Fängt er auch schon an zu
              krähen: «Kikeriki! Kikikerikih!!» Tak, tak, tak! - da
              kommen sie. </poem>
the following function calls produce the following
              results, with the poem element as the
              context node:
xf:matches(., "Kaum.*krähen")
                  returns true
xf:matches(., "Kaum.*krähen",
                  "m") returns false
xf:matches(., "^Kaum.*gesehen,$",
                  "m") returns true
xf:matches(., "^Kaum.*gesehen,$")
                  returns false
xf:matches(., "kiki", "i")
                  returns true
Note:
Regular expression matching is defined on the basis of Unicode code-points, it takes no account of collations.
xf:replace(string? $input, string? $pattern, string? $replacement) =>
                string?
              xf:replace( | 
                    string?  | 
                    $input, | 
                  
string?  | 
                    $pattern, | 
                  |
string?  | 
                    $replacement, | 
                  |
string?  | 
                    $flags)
                    => string? | 
                  
The effect of calling the first version of this
            function (omitting the argument $flags) is
            the same as the effect of calling the second version
            with the $flags argument set to a
            zero-length string.
The function returns the string that is obtained by
            replacing all non-overlapping substrings of
            $input that match the given
            $pattern with an occurrence of the
            $replacement string. The
            $flags argument is interpreted in the same
            way as for the xf:matches
            function.
If any of the arguments is an empty sequence, the result is an empty sequence.
Within the $replacement string, the variables
            $1 to $9 may be used to refer to
            the substring captured by each of the first nine
            parenthesized sub-expressions in the regular
            expression. A literal $ symbol must be
            written as \$.
An error is raised ("Invalid replace argument") if
            the value of $pattern or
            $flags is invalid according to the rules
            described in section 6.3.15.1 Regular Expression
            Syntax.
An error is raised ("Pattern matches zero-length string") if the pattern matches a zero-length string.
xf:tokenize(string? $input, string? $pattern) =>
                string*
              xf:tokenize(string? $input, string? $pattern, string? $flags) => string*
              The effect of calling the first version of this
            function (omitting the argument $flags) is
            the same as the effect of calling the second version
            with the $flags argument set to a
            zero-length string.
This function breaks the $input string
            into a sequence of strings, treating any substring that
            matches $pattern as a separator. The
            separators themselves are not returned. The
            $flags argument is interpreted in the same
            way as for the xf:matches
            function.
If any of the arguments is an empty sequence, the result is an empty sequence.
If a separator occurs at the start of the
            $input string, the result sequence will
            start with a zero-length string. Zero-length strings
            will also occur in the result sequence if a separator
            occurs at the end of the $input string, or
            if two adjacent substrings match the supplied
            $pattern.
xf:escape-uri(string $uri-part, boolean $escape-reserved)
                => string
              This function applies the URI escaping rules defined
            in section 2 of [RFC 2396] to
            the string supplied as $uri-part, which
            typically represents all or part of a URI. The effect
            of the function is to replace any special character in
            the string by an escape sequence of the form %xx%yy...,
            where xxyy... is the hexadecimal representation of the
            octets used to represent the character in UTF-8.
The set of characters that are escaped depends on the setting of the boolean argument $escape-reserved.
If $escape-reserved is true, all
            characters are escaped other than lower case letters
            a-z, upper case letters A-Z, digits 0-9, and the
            characters referred to in [RFC
            2396] as "marks": specifically, "-" | "_" | "." |
            "!" | "~" | "*" | "'" | "(" | ")". The "%" character
            itself is escaped only if it is not followed by two
            hexadecimal digits (that is, 0-9, a-f, and A-F).
If $escape-reserved is false, the
            behavior differs in that characters referred to in [RFC 2396] as reserved characters
            are not escaped. These characters are ";" | "/" | "?" |
            ":" | "@" | "&" | "=" | "+" | "$" | ",".
[RFC 2396] does not define whether escaped URIs should use lower case or upper case for hexadecimal digits. To ensure that escaped URIs can be compared using string comparison functions, this function must always use the upper-case letters A-F.
Generally, $escape-reserved should be
            set to true when escaping a string that is to form a
            single part of a URI, and to false when escaping an
            entire URI or URI reference.
xf:escape-uri
                  ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"),
                  true()) returns
                  "gopher%3A%2F%2Fspinaltap.micro.umn.edu%2F00%2FWeather%2FCalifornia%2FLos%20Angeles%23ocean"
xf:escape-uri
                  ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"),
                  false()) returns
                  "gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles%23ocean"
This section discusses operators on the [XML Schema Part 2: Datatypes] boolean datatype.
The following constructor funcions are defined on the boolean type.
| Function | Meaning | Source | 
|---|---|---|
xf:true | 
              boolean | XPath 1.0 | 
xf:false | 
              boolean | XPath 1.0 | 
The following functions are defined on boolean values to back up operators defined in [XQuery 1.0: An XML Query Language] and [XPath 2.0]:
| Operator | Meaning | Source | 
|---|---|---|
op:boolean-equal | 
              Equality comparison | XPath 1.0 | 
op:boolean-less-than | 
              A less-than operator for
              boolean vales: false is less-than
              true. | 
              XPath 1.0 | 
op:boolean-greater-than | 
              A greater-than operator
              for boolean vales: true is greater-than
              false. | 
              XPath 1.0 | 
op:boolean-equal(boolean $value1, boolean $value2) =>
                boolean
              The arguments and return type are all
            boolean. The result is true
            if both arguments are true or if both
            arguments are false. The result is
            false if one of the arguments is
            true and the other argument is
            false.
This function backs up the "eq" operator on boolean values.
The following functions are defined on boolean values:
| Function | Meaning | Source | 
|---|---|---|
xf:not | 
              Inverts the boolean value
              of the argument. A () argument returns
              true. | 
              XPath 1.0 | 
xf:not(item* $srcval) =>
                boolean
              $srcval is first reduced to an
            effective boolean value as defined in [XQuery 1.0: An XML Query
            Language].
Returns true if the effective boolean
            value is false, and false if
            the effective boolean value is true.
This section discusses operations on the [XML Schema Part 2: Datatypes] duration, date and time types. In addition, it discusses operations on two subtypes of the duration datatype that are defined in 8.2 Two Totally Ordered Subtypes of Duration.
[Issue 109: Calendar context allows for non-Gregorian calendars]
[Issue 136: Should we allow casting a date/time from one timezone to another?]
The operators described in this section are defined on the following duration date and time types:
duration
dateTime
date
time
gYearMonth
gYear
gMonthDay
gMonth
gDay
In addition, they are defined on the 8.2 Two Totally Ordered Subtypes of Duration:
yearMonthDuration
dayTimeDuration
CONFORMANCE NOTE
For a number of the above datatypes [XML Schema Part 2: Datatypes] extends the basic [ISO 8601] lexical representations, such as YYYY-MM-DDThh:mm:ss.s for dateTime, by allowing more than four digits to represent the year field -- no maximum is specified -- and an unlimited number of digits for fractional seconds.
For this specification, all minimally conforming processors must support year values with a minimum of 4 digits (i.e., YYYY) and a minimum fractional second precision of 100 nanoseconds or seven digits (i.e. s.sssssss). However, conforming processors may set larger application-defined limits on the maximum number of digits they support in these two situations, in which case those application-defined maximum numbers must be clearly documented.
[Issue 159: For fractional seconds precision use 6 digits to match SQL TIMESTAMP.]
These two totally ordered subtypes of duration
          are defined in this specification using the mechanisms
          described in [XML Schema Part 2:
          Datatypes] for defining user-defined types. They are
          available in the namespace
          http://www.w3.org/2002/08/xquery-functions.
The W3C XML Query Working Group has requested the W3C
          XML Schema Working Group that these two subtypes of
          duration be included in the built-in datatypes
          described in [XML Schema Part 2:
          Datatypes]. If the W3C XML Schema Working Group
          agrees to this request, these two datatypes will be
          removed from the above name space and moved into the XML
          Schema namespace
          http://www.w3.org/2001/XMLSchema.
[Definition:] yearMonthDuration is derived from duration by restricting its lexical representation to contain only the year and month components. The value space of yearMonthDuration is the set of integer month values. The year and month components of yearMonthDuration correspond to the Gregorian year and month components defined in section 5.5.3.2 of [ISO 8601], respectively.
yearMonthDuration is derived from duration as follows:
<simpleType name='yearMonthDuration'>
    <restriction base='duration'>
        <xsd:pattern value="[-]?P\p{Nd}+(Y(\p{Nd}+M)?|M)"/>
    </restriction>
</simpleType>
            The lexical representation for yearMonthDuration is the [ISO 8601] reduced format PnYnM, where nY represents the number of years and nM the number of months. The values of the years and months components are not restricted but allow an arbitrary positive integer.
An optional preceding minus sign ('-') is allowed to indicate a negative duration. If the sign is omitted a positive duration is indicated. To indicate a yearMonthDuration of 1 year, 2 months, one would write: P1Y2M. One could also indicate a yearMonthDuration of minus 13 months as: -P13M.
Reduced precision and truncated representations of this format are allowed provided they conform to the following:
If the number of years or months in any expression equals zero (0), the number and its corresponding designator may be omitted. However, at least one number and its designator must be present. For example, P1347Y and P1347M are all allowed; P-1347M is not allowed although -P1347M is allowed. P1Y2MT is not allowed.
The value of a yearMonthDuration lexical form is obtained by multiplying the value of the year component by 12 and adding the value of the month component. The value is positive or negative depending on the preceding sign.
The canonical representation of yearMonthDuration restricts the value of the months component to integer values between 0 and 11, both inclusive. To convert from a non-canonical representation to the canonical representation, the lexical representation is first converted to a value in integer number of months as defined above. This value is then divided by 12 to obtain the value of the years component of the canonical representation. The remaining number of months is the value of the months component of the canonical representation. If the value is zero (0) months, the canonical form is "P0M".
[Definition:] dayTimeDuration is derived from duration by restricting its lexical representation to contain only the day, hour, minute, and second components. The value space of dayTimeDuration is the set of fractional second values. The components of dayTimeDuration correspond to the day, hour, minute and second components defined in Section 5.5.3.2 of [ISO 8601], respectively. dayTimeDuration is derived from duration as follows:
<simpleType name='dayTimeDuration'>
    <restriction base='duration'>
         <xsd:pattern value="[-]?P(\p{Nd}D(T(\p{Nd}+(H(\p{Nd}+(M(\p{Nd}+(\.\p{Nd}*)?S
            |\.\p{Nd}+S)?|(\.\p{Nd}*)?S)|(\.\p{Nd}*)?S)?|M(\p{Nd}+
            (\.\p{Nd}*)?S|\.\p{Nd}+S)?|(\.\p{Nd}*)?S)|\.\p{Nd}+S))?
            |T(\p{Nd}+(H(\p{Nd}+(M(\p{Nd}+(\.\p{Nd}*)?S|\.\p{Nd}+S)?
            |(\.\p{Nd}*)?S)|(\.\p{Nd}*)?S)?|M(\p{Nd}+(\.\p{Nd}*)?S|\.\p{Nd}+S)?
            |(\.\p{Nd}*)?S)|\.\p{Nd}+S))"/>
    </restriction>
</simpleType>
            The lexical representation for dayTimeDuration is the [ISO 8601] truncated format PnDTnHnMnS, where nD represents the number of days, T is the date/time separator, nH the number of hours, nM the number of minutes and nS the number of seconds.
The values of the days, hours and minutes components are not restricted but allow an arbitrary positive integer. Similarly, the value of the seconds component allows an arbitrary positive decimal number. An optional minus sign ('-') is allowed to precede the 'P', indicating a negative duration. If the sign is omitted, the duration is positive. See also [ISO 8601] Date and Time Formats.
For example, to indicate a duration of 3 days, 10 hours, and 30 minutes, one would write: P3DT10H30M. One could also indicate a duration of minus 120 days as: -P120D. Reduced precision and truncated representations of this format are allowed, provided they conform to the following:
If the number of days, hours, minutes, or seconds in any expression equals zero (0), the number and its corresponding designator may be omitted. However, at least one number and its designator must be present.
The seconds part may have a decimal fraction.
The designator 'T' must be absent if all of the time items are absent. The designator 'P' must always be present.
For example, P13D, PT47H and P3DT2H are all allowed. P-134D is not allowed (invalid location of minus sign), although -P134D is allowed.
The value of a dayTimeDuration lexical form in fractional seconds is obtained by converting the day, hour minutes and seconds value to fractional seconds using the conversion rules: 24 hours = 1 day, 60 minutes = 1 hour and 60 seconds = 1 minute.
The canonical representation of dayTimeDuration restricts the value of the hours component to integer values between 0 and 23, both inclusive; the value of the minutes component to integer values between 0 and 59; both inclusive; and the value of the seconds component to decimal valued from 0.0 to 60.999... (see [XML Schema Part 2: Datatypes], Appendix D). To convert from a non-canonical representation to the canonical representation, the value of the lexical form in fractional seconds is first calculated in the manner described above. The value of the days component in the canonical form is then calculated by dividing the value by 24*60*60. The remainder is in fractional seconds. The value of the hours component in the canonical form is calculated by dividing this remainder by 60*60. The remainder is again in fractional seconds. The value of the minutes component in the canonical form is calculated by dividing this remainder by 60. The remainder in fractional seconds is the value of the seconds component in the canonical form. If all the components of the lexical form are zero (0), the canonical form is PT0S.
| Operator | Meaning | 
|---|---|
op:duration-equal | 
              Equality comparison on duration values | 
op:yearMonthDuration-equal | 
              Equality comparison on yearMonthDuration values | 
op:yearMonthDuration-less-than | 
              Less-than comparison on yearMonthDuration values | 
op:yearMonthDuration-greater-than | 
              Greater-than comparison on yearMonthDuration values | 
op:dayTimeDuration-equal | 
              Equality comparison on dayTimeDuration values | 
op:dayTimeDuration-less-than | 
              Less-than comparison on dayTimeDuration values | 
op:dayTimeDuration-greater-than | 
              Greater-than comparison on dayTimeDuration values | 
op:dateTime-equal | 
              Equality comparison on dateTime values | 
op:dateTime-less-than | 
              Less-than comparison on dateTime values | 
op:dateTime-greater-than | 
              Greater-than comparison on dateTime values | 
op:date-equal | 
              Equality comparison on date values | 
op:date-less-than | 
              Less-than comparison on date values | 
op:date-greater-than | 
              Greater-than comparison on date values | 
op:time-equal | 
              Equality comparison on time values | 
op:time-less-than | 
              Less-than comparison on time values | 
op:time-greater-than | 
              Greater-than comparison on time values | 
op:gYearMonth-equal | 
              Equality comparison on gYearMonth values | 
op:gYear-equal | 
              Equality comparison on gYear values | 
op:gMonthDay-equal | 
              Equality comparison on gMonthDay values | 
op:gMonth-equal | 
              Equality comparison on gMonth values | 
op:gDay-equal | 
              Equality comparison on gDay values | 
The following comparison operators are defined on date, time and duration values. Each operator takes two operands of the same type and returns a boolean result. As discussed in [XML Schema Part 2: Datatypes], the order relation on the duration and the date and time datatypes is not a total order but, rather, a partial order. For this reason, only the equality function is defined on duration. A full complement of comparison and arithmetic functions are defined on the two subtypes of duration described in 8.2 Two Totally Ordered Subtypes of Duration.
If either operand to a comparison function on date or time values does not have a explicit timezone then, for the purpose of the operation, an implicit timezone, provided by the implementation, is assumed to be present as part of the value.
op:duration-equal(duration $operand1, duration $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on duration values.
op:yearMonthDuration-equal( | 
                    yearMonthDuration  | 
                    $operand1, | 
                  
yearMonthDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on yearMonthDuration values.
op:yearMonthDuration-less-than( | 
                    yearMonthDuration  | 
                    $operand1, | 
                  
yearMonthDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is less than $operand2. Returns false
            otherwise.
This function backs up the "lt" and "ge" operators on yearMonthDuration values.
op:yearMonthDuration-greater-than( | 
                    yearMonthDuration  | 
                    $operand1, | 
                  
yearMonthDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is greater than $operand2. Returns false
            otherwise.
This function backs up the "gt" and "le" operators on yearMonthDuration values.
op:dayTimeDuration-equal( | 
                    dayTimeDuration  | 
                    $operand1, | 
                  
dayTimeDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on dayTimeDuration values.
op:dayTimeDuration-less-than( | 
                    dayTimeDuration  | 
                    $operand1, | 
                  
dayTimeDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is less than $operand2. Returns false
            otherwise.
This function backs up the "lt" and "ge" operators on dayTimeDuration values.
op:dayTimeDuration-greater-than( | 
                    dayTimeDuration  | 
                    $operand1, | 
                  
dayTimeDuration  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is greater than $operand2. Returns false
            otherwise.
This function backs up the "gt" and "le" operators on dayTimeDuration values.
op:dateTime-equal(dateTime $operand1, dateTime $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the dateTime data type is defined by section 3.2.7.3, "Order relation on dateTime", of [XML Schema Part 2: Datatypes].
This function backs up the "eq" and "ne" operators on dateTime values.
Assuming an implicit timezone value of -5:00.
                  op:dateTime-equal(xs:dateTime("2002-04-02T12:00"),
                  xs:dateTime("2002-04-02T17:00Z")) returns
                  true.
                  op:dateTime-equal(xs:dateTime("2002-04-02T12:00"),
                  xs:dateTime("2002-04-02T17:00")) returns
                  false.
                  op:dateTime-equal(xs:dateTime("2002-04-02T12:00"),
                  xs:dateTime("2002-04-02T12:00")) returns
                  true.
op:dateTime-less-than(dateTime $operand1, dateTime $operand2) =>
                boolean
              Returns true if and only if $operand1
            is less than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the dateTime data type is defined by section 3.2.7.3, "Order relation on dateTime", of [XML Schema Part 2: Datatypes].
This function backs up the "lt" and "ge" operators on dateTime values.
op:dateTime-greater-than( | 
                    dateTime  | 
                    $operand1, | 
                  
dateTime  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is greater than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the dateTime data type is defined by section 3.2.7.3, "Order relation on dateTime", of [XML Schema Part 2: Datatypes].
This function backs up the "gt" and "le" operators on dateTime values.
op:date-equal(date $operand1, date $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.9, "date", of [XML Schema Part 2: Datatypes].
This function backs up the "eq" and "ne" operators on date values.
op:date-less-than(date $operand1, date $operand2) =>
                boolean
              Returns true if and only if $operand1
            is less than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.9, "date", of [XML Schema Part 2: Datatypes].
This function backs up the "lt" and "ge" operators on date values.
op:date-greater-than(date $operand1, date $operand2) =>
                boolean
              Returns true if and only if $operand1
            is greater than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.9, "date", of [XML Schema Part 2: Datatypes].
This function backs up the "gt" and "le" operators on date values.
op:time-equal(time $operand1, time $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.8, "time", of [XML Schema Part 2: Datatypes].
This function backs up the "eq" and "ne" operators on time values.
op:time-less-than(time $operand1, time $operand2) =>
                boolean
              Returns true if and only if $operand1
            is less than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.8, "time", of [XML Schema Part 2: Datatypes].
This function backs up the "lt" and "ge" operators on time values.
op:time-greater-than(dateTime $operand1, dateTime $operand2) =>
                boolean
              Returns true if and only if $operand1
            is greater than $operand2. Returns false
            otherwise.
If either $operand1 or $operand2 is a value that does not contain a timezone, then for the purposes of this operation the Implicit Timezone is considered to be present in the value. The ordering of the date data type is defined by section 3.2.7.3, "Order relation on dateTime", and section 3.2.8, "time", of [XML Schema Part 2: Datatypes].
This function backs up the "gt" and "le" operators on time values.
op:gYearMonth-equal( | 
                    gYearMonth  | 
                    $operand1, | 
                  
gYearMonth  | 
                    $operand2)
                    => boolean | 
                  
Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on gYearMonth values.
op:gYear-equal(gYear $operand1, gYear $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on gYear values.
op:gMonthDay-equal(gMonthDay $operand1, gMonthDay $operand2) =>
                boolean
              Returns true if and only if $operand1
            is exactly equal to $operand2. Returns
            false otherwise.
This function backs up the "eq" and "ne" operators on gMonthDay values.
The date and time datatypes may be considered to be composite datatypes in that they contain distinct components. The extraction functions specified below extract one component from a date or time value.
| Function | Meaning | 
|---|---|
xf:get-years-from-yearMonthDuration | 
              Returns the year component of a yearMonthDuration value. | 
xf:get-months-from-yearMonthDuration | 
              Returns the months component of a yearMonthDuration value. | 
xf:get-days-from-dayTimeDuration | 
              Returns the days component of a dayTimeDuration value. | 
xf:get-hours-from-dayTimeDuration | 
              Returns the hours component of a dayTimeDuration value. | 
xf:get-minutes-from-dayTimeDuration | 
              Returns the minutes component of a dayTimeDuration value. | 
xf:get-seconds-from-dayTimeDuration | 
              Returns the seconds component of a dayTimeDuration value. | 
xf:get-year-from-dateTime | 
              Returns the year from a dateTime value. | 
xf:get-month-from-dateTime | 
              Returns the month from a dateTime value. | 
xf:get-day-from-dateTime | 
              Returns the day from a dateTime value. | 
xf:get-hours-from-dateTime | 
              Returns the hours from a dateTime value. | 
xf:get-minutes-from-dateTime | 
              Returns the minutes from a dateTime value. | 
xf:get-seconds-from-dateTime | 
              Returns the seconds from a dateTime value. | 
xf:get-timezone-from-dateTime | 
              Returns the timezone from a dateTime value. | 
xf:get-year-from-date | 
              Returns the year from a date value. | 
xf:get-month-from-date | 
              Returns the month from a date value. | 
xf:get-day-from-date | 
              Returns the day from a date value. | 
xf:get-timezone-from-date | 
              Returns the timezone from a date value. | 
xf:get-hours-from-time | 
              Returns the hours from a time value. | 
xf:get-minutes-from-time | 
              Returns the minutes from a time value. | 
xf:get-seconds-from-time | 
              Returns the seconds from a time value. | 
xf:get-timezone-from-time | 
              Returns the timezone from a time value. | 
xf:get-years-from-yearMonthDuration(yearMonthDuration? $srcval) =>
                integer?
              Returns an integer representing the years component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-months-from-yearMonthDuration( | 
                    yearMonthDuration?  | 
                    $srcval)
                    => integer? | 
                  
Returns an integer representing the months component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-days-from-dayTimeDuration(dayTimeDuration? $srcval) =>
                integer?
              Returns an integer representing the days component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-hours-from-dayTimeDuration(dayTimeDuration? $srcval) =>
                integer?
              Returns an integer representing the hours component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-minutes-from-dayTimeDuration(dayTimeDuration? $srcval) =>
                integer?
              Returns an integer representing the minutes
            component in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-seconds-from-dayTimeDuration(dayTimeDuration? $srcval) =>
                integer?
              Returns a decimal number representing the seconds
            component in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-year-from-dateTime(dateTime? $srcval) =>
                integer?
              Returns an integer representing the year component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-month-from-dateTime(dateTime? $srcval) =>
                integer?
              Returns an integer representing the month component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-day-from-dateTime(dateTime? $srcval) =>
                integer?
              Returns an integer representing the day component in
            the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-hours-from-dateTime(dateTime? $srcval) =>
                integer?
              Returns an integer representing the hours value
            identified in the value of $srcval. The
            hours value ranges from 0 to 23, inclusive. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-minutes-from-dateTime(dateTime? $srcval) =>
                integer?
              Returns an integer value representing the minute
            identified in the value of $srcval. The
            minute value ranges from 0 to 59, inclusive. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-seconds-from-dateTime(dateTime? $srcval) =>
                decimal?
              Returns a decimal value representing the seconds and
            fractional seconds identified in the value of
            $srcval. The value ranges from 0 to
            60.999..., inclusive. The number of digits of
            fractional seconds precision is determined by the
            relevant facet of the argument. Note that the value can
            be greater than 60 seconds to accomodate occassional
            leap seconds used to keep human time synchronized with
            the rotation of the planet. If $srcval is
            the empty sequence, returns the empty sequence.
xf:get-timezone-from-dateTime(dateTime? $srcval) =>
                string?
              Returns a string representing the timezone component
            of $srcval. The result is a duration in
            "hh:mm" format with an optional leading minus (-) sign,
            indicating the deviation from GMT (UTC). If
            $srcval does not contain a timezone, the
            result is the empty sequence. If $srcval
            is the empty sequence, returns the empty sequence.
[Issue 110: No timezone: Empty sequence or zero-length string?]
[Issue 137: Should functions that return timezones return a duration?]
xf:get-year-from-date(date? $srcval) =>
                integer?
              Returns an integer representing the year in the
            value of $srcval. If $srcval
            is the empty sequence, returns the empty sequence.
xf:get-month-from-date(date? $srcval) =>
                integer?
              Returns an integer representing the month component
            in the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-day-from-date(date? $srcval) =>
                integer?
              Returns an integer representing the day component in
            the value of $srcval. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-timezone-from-date(date? $srcval) =>
                string?
              Returns a string representing the timezone component
            of $srcval. The result is a duration in
            "hh:mm" format with an optional leading minus (-) sign,
            indicating the deviation from GMT (UTC). If
            $srcval does not contain a timezone, the
            result is the empty sequence. If $srcval
            is the empty sequence, returns the empty sequence.
xf:get-hours-from-time(time? $srcval) =>
                integer?
              Returns an integer representing the hours value
            identified in the value of $srcval. The
            hours value ranges from 0 to 23, inclusive. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-minutes-from-time(time? $srcval) =>
                integer?
              Returns an integer value representing the minute
            identified in the value of $srcval. The
            minute value ranges from 0 to 59, inclusive. If
            $srcval is the empty sequence, returns the
            empty sequence.
xf:get-seconds-from-time(time? $srcval) =>
                decimal?
              Returns a decimal value representing the seconds and
            fractional seconds identified in the value of
            $srcval. The value ranges from 0 to
            60.999..., inclusive. The number of digits of
            fractional seconds precision is determined by the
            relevant facet of the argument. Note that the value can
            be greater than 60 seconds to accomodate occassional
            leap seconds used to keep human time synchronized with
            the rotation of the planet. If $srcval is
            the empty sequence, returns the empty sequence.
xf:get-timezone-from-time(time? $srcval) =>
                string?
              Returns a string representing the timezone component
            of $srcval. The result is a duration in
            "hh:mm" format with an optional leading minus (-) sign,
            indicating the deviation from GMT (UTC). If
            $srcval does not contain a timezone, the
            result is the empty sequence. If $srcval
            is the empty sequence, returns the empty sequence.
| Function | Meaning | 
|---|---|
op:add-yearMonthDurations | 
              Adds two yearMonthDurations. Returns a yearMonthDuration. | 
op:subtract-yearMonthDurations | 
              Subtracts one yearMonthDuration from another. Returns a yearMonthDuration. | 
op:multiply-yearMonthDuration | 
              Multiply a yearMonthDuration by a decimal. Returns a yearMonthDuration. | 
op:divide-yearMonthDuration | 
              Divide a yearMonthDuration by a decimal. Returns a yearMonthDuration. | 
op:add-dayTimeDurations | 
              Adds two dayTimeDurations. Returns a dayTimeDuration. | 
op:subtract-dayTimeDurations | 
              Subtracts one dayTimeDuration from another. Returns a dayTimeDuration. | 
op:multiply-dayTimeDuration | 
              Multiply a dayTimeDuration by a decimal. Returns a dayTimeDuration. | 
op:divide-dayTimeDuration | 
              Divide a dayTimeDuration by a decimal. Returns a dayTimeDuration. | 
op:add-yearMonthDurations( | 
                    yearMonthDuration  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => yearMonthDuration | 
                  
Returns the result of adding the value of
            $srcval1 to the value of
            $srcval2. Backs up the "+" operator on
            yearMonthDuration values.
op:subtract-yearMonthDurations( | 
                    yearMonthDuration  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => yearMonthDuration | 
                  
Returns the result of subtracting the value of
            $srcval2 from the value of
            $srcval2. Backs up the "-" operator on
            yearMonthDuration values.
op:multiply-yearMonthDuration( | 
                    yearMonthDuration  | 
                    $srcval1, | 
                  
decimal  | 
                    $srcval2)
                    => yearMonthDuration | 
                  
Returns the result of multiplying the value of
            $srcval1 by $srcval2. The
            result is rounded to the nearest month. For a value
            v, 0 <= v < 0.5 rounds to 0;
            0.5 <= v < 1.0 rounds to 1.
Backs up the "*" operator on yearMonthDuration values.
op:divide-yearMonthDuration( | 
                    yearMonthDuration  | 
                    $srcval1, | 
                  
decimal  | 
                    $srcval2)
                    => yearMonthDuration | 
                  
Returns the result of dividing the value of
            $srcval1 by $srcval2. The
            result is rounded to the nearest month. For a value
            v, 0 <= v < 0.5 rounds to 0;
            0.5 <= v < 1.0 rounds to 1.
Backs up the "div" operator on yearMonthDuration values.
op:add-dayTimeDurations( | 
                    dayTimeDuration  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => dayTimeDuration | 
                  
Returns the result of adding the value of
            $srcval1 to the value of
            $srcval2. Backs up the "+" operator on
            dayTimeDuration values.
op:subtract-dayTimeDurations( | 
                    dayTimeDuration  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => dayTimeDuration | 
                  
Returns the result of subtracting the value of
            $srcval2 from the value of
            $srcval2. Backs up the "-" operator on
            dayTimeDuration values.
op:multiply-dayTimeDuration( | 
                    dayTimeDuration  | 
                    $srcval1, | 
                  
decimal  | 
                    $srcval2)
                    => dayTimeDuration | 
                  
Returns the result of multiplying the value of
            $srcval1 by $srcval2. Backs
            up the "*" operator on dayTimeDuration values.
| Function | Meaning | 
|---|---|
xf:add-timezone-to-dateTime | 
              Returns a dateTime with a timezone, whether implicit or explicit. | 
xf:remove-timezone-from-dateTime | 
              Returns a dateTime without a timezone. Values with an explicit timezone are converted to the implicit timezone. | 
xf:add-timezone-to-date | 
              Returns a date with a timezone, whether implicit or explicit. | 
xf:add-timezone-to-time | 
              Returns a time with a timezone, whether implicit or explicit. | 
xf:remove-timezone-from-time | 
              Returns a time without a timezone. Values with an explicit timezone are converted to the implicit timezone. | 
xf:add-timezone-to-dateTime(dateTime $srcval) =>
                dateTime
              xf:add-timezone-to-dateTime( | 
                    dateTime  | 
                    $srcval, | 
                  
dayTimeDuration  | 
                    $timezone)
                    => dateTime | 
                  
Returns a dateTime with a timezone.
If $srcval is a dateTime value without a timezone,
            then let $srcn be $srcval. Otherwise, let $srcn be the
            value of xf:remove-timezone-from-dateTime
            ($srcval). If $timezone is not specified,
            then $timezone will be the value of the implicit
            timezone for the query. The value of $srcn -
            $timezone is returned with a timezone of Z.
Assume an implicit timezone of -5:00.
let $tz :=
              xf:dayTimeDuration("-PT10H")
                  xf:add-timezone-to-dateTime(xs:dateTime("2002-03-07T10:00"))
                  returns 2002-03-07T15:00Z
                  xf:add-timezone-to-dateTime(xs:dateTime("2002-03-07T10:00-07:00"))
                  returns 2002-03-07T17:00Z
                  xf:add-timezone-to-dateTime(xs:dateTime("2002-03-07T10:00"),
                  $tz) returns
                  2002-03-07T20:00Z
                  xf:add-timezone-to-dateTime(xs:dateTime("2002-03-07T10:00-07:00"),
                  $tz) returns
                  2002-03-07T22:00Z
xf:remove-timezone-from-dateTime(dateTime $srcval) =>
                dateTime
              xf:remove-timezone-from-dateTime( | 
                    dateTime  | 
                    $srcval, | 
                  
dayTimeDuration  | 
                    $timezone)
                    => dateTime | 
                  
Returns a dateTime without a timezone.
If $srcval has a timezone, then let $srcn be
            $srcval. Otherwise, let $srcn be the value of xf:add-timezone-to-dateTime
            ($srcval). If $timezone is not specified,
            then $timezone will be the value of the implicit
            timezone for the query. The value returned is
            $srcn + $timezone, expressed in timezone
            Z, with the timezone of Z removed.
Assume an implicit timezone of -5:00.
let $tz :=
              xf:dayTimeDuration("-PT10H")
                  xf:remove-timezone-from-dateTime(xs:dateTime("2002-03-07T10:00"))
                  returns 2002-03-07T10:00
                  xf:remove-timezone-from-dateTime(xs:dateTime("2002-03-07T10:00-07:00"))
                  returns 2002-03-07T12:00
                  xf:remove-timezone-from-dateTime(xs:dateTime("2002-03-07T10:00"),
                  $tz) returns
                  2002-03-07T05:00
                  xf:remove-timezone-from-dateTime(xs:dateTime("2002-03-07T10:00-07:00"),
                  $tz) returns
                  2002-03-07T07:00
xf:add-timezone-to-date(date $srcval) =>
                date
              xf:add-timezone-to-date(date $srcval, dayTimeDuration $timezone) =>
                date
              Returns a date with a timezone.
If $srcval is a date value without a timezone, then
            let $srcn be $srcval. Otherwise, let $srcn be the value
            of xf:remove-timezone-from-date($srcval).
            If $timezone is not specified, then $timezone will be
            the value of the implicit timezone for the query. The
            value of $srcn - $timezone is returned
            with a timezone of Z.
Note:
EDITOR NOTE: The preceding paragraph makes use of
              a function xf:remove-timezone-from-date
              that has been removed by a different proposal. As a
              result, the preceding paragraph is "broken", as is
              the fourth example below.
Assume an implicit timezone of -5:00.
let $tz :=
              xf:dayTimeDuration("-PT10H")
                  xf:add-timezone-to-date(xs:date("2002-03-07))
                  returns 2002-03-07T-05:00
                  xf:add-timezone-to-date(xs:date("2002-03-07T-07:00"))
                  returns 2002-03-07T-07:00
                  xf:add-timezone-to-date(xs:date("2002-03-07"),
                  $tz) returns
                  2002-03-07T-10:00
                  xf:add-timezone-to-date(xs:date("2002-03-07T-07:00"),
                  $tz) returns 2002-03-07Z
Note:
EDITOR NOTE: The fourth example above is broken because it implies removing the timezone from the date value before adding a new timezone to it.
xf:add-timezone-to-time(time $srcval) =>
                time
              xf:add-timezone-to-time(time $srcval, dayTimeDuration $timezone) =>
                time
              Returns a time with a timezone.
If $srcval is a time value without a timezone, then
            let $srcn be $srcval. Otherwise, let $srcn be the value
            of xf:remove-timezone-from-time($srcval).
            If $timezone is not specified, then $timezone will be
            the value of the implicit timezone for the query. The
            value of $srcn - $timezone is returned
            with a timezone of Z.
Assume an implicit timezone of -5:00.
let $tz :=
              xf:dayTimeDuration("-PT10H")
                  xf:add-timezone-to-time(xs:time("10:00"))
                  returns 15:00Z
                  xf:add-timezone-to-time(xs:time("10:00-07:00"))
                  returns 17:00Z
                  xf:add-timezone-to-time(xs:time("10:00"),
                  $tz) returns 20:00Z
                  xf:add-timezone-to-time(xs:time("10:00-07:00"),
                  $tz) returns 22:00Z
xf:remove-timezone-from-time(time $srcval) =>
                time
              xf:remove-timezone-from-time( | 
                    time  | 
                    $srcval, | 
                  
dayTimeDuration  | 
                    $timezone)
                    => time | 
                  
Returns a time without a timezone.
If $srcval has a timezone, then let $srcn be
            $srcval. Otherwise, let $srcn be the value of xf:add-timezone-to-time
            ($srcval). If $timezone is not specified,
            then $timezone will be the value of the implicit
            timezone for the query. The value returned is
            $srcn + $timezone, expressed in timezone
            Z, with the timezone of Z removed.
Assume an implicit timezone of -5:00.
let $tz :=
              xf:dayTimeDuration("-PT10H")
                  xf:remove-timezone-from-time(xs:time("10:00"))
                  returns 10:00
                  xf:remove-timezone-from-time(xs:time("10:00-07:00"))
                  returns 12:00
                  xf:remove-timezone-from-time(xs:time("10:00"),
                  $tz) returns 05:00
                  xf:remove-timezone-from-time(xs:time("10:00-07:00"),
                  $tz) returns 07:00
A time period is defined as an interval
          or duration of time with a fixed start and end. Thus,
          time periods have three properties, two of which are
          independent. The functions below take two of the
          properties as arguments and return the third.
These functions require adding or subtracting a duration value to or from a dateTime, a date or a time value. Appendix E of [XML Schema Part 2: Datatypes] describes an algorithm for performing such operations.
If any of the arguments to the functions below is a dateTime, date or time value that does not contain a timezone, then, for the purposes of the function, the argument is considered to a have an implicit timezone provided by the implementation.
| Function | Meaning | 
|---|---|
              xf:get-yearMonthDuration-from-dateTimes | 
              Returns the difference between two dateTimes as a yearMonthDuration. | 
              xf:get-dayTimeDuration-from-dateTimes | 
              Returns the difference between two dateTimes as a dayTimeDuration. | 
op:subtract-dates | 
              Returns the difference between two dates as a dayTimeDuration. | 
op:subtract-times | 
              Returns the difference between two times as a dayTimeDuration. | 
op:add-yearMonthDuration-to-dateTime | 
              Returns the end of a time period by adding a yearMonthDuration to the dateTime that starts the period. | 
op:add-dayTimeDuration-to-dateTime | 
              Returns the end of a time period by adding a dayTimeDuration to the dateTime that starts the period. | 
op:subtract-yearMonthDuration-from-dateTime | 
              Returns the beginning of a time period by subtracting a yearMonthDuration from the dateTime that ends the period. | 
              op:subtract-dayTimeDuration-from-dateTime | 
              Returns the beginning of a time period by subtracting a dayTimeDuration from the dateTime that ends the period. | 
op:add-yearMonthDuration-to-date | 
              Returns the end of a time period by adding a yearMonthDuration to the date that starts the period. | 
op:add-dayTimeDuration-to-date | 
              Returns the end of a time period by adding a dayTimeDuration to the date that starts the period. | 
              op:subtract-yearMonthDuration-from-date | 
              Returns the beginning of a time period by subtracting a yearMonthDuration from the date that ends the period. | 
              op:subtract-dayTimeDuration-from-date | 
              Returns the beginning of a time period by subtracting a dayTimeDuration from the date that ends the period. | 
op:add-dayTimeDuration-to-time | 
              Adds the value of the hours, minutes and seconds components of a dayTimeDuration to a time value. | 
              op:subtract-dayTimeDuration-from-time | 
              Subtracts the value of the hours, minutes and seconds components of a dayTimeDuration to a time value. | 
xf:get-yearMonthDuration-from-dateTimes( | 
                    dateTime  | 
                    $srcval1, | 
                  
dateTime  | 
                    $srcval2)
                    => yearMonthDuration | 
                  
Returns the yearMonthDuration that corresponds to
            the difference between the value of
            $srcval1 and the value of
            $srcval2. If the value of
            $srcval1 follows in time the value of
            $srcval2, then the returned value is a
            negative duration. If one or both arguments do not have
            a timezone they are assigned an implicit ·implementation-defined· timezone. If either argument
            is the empty sequence, returns the empty sequence.
In general, the difference between two dateTime
            values will be a duration that contains years and
            months as well as days, hours, etc. In fact, it can be
            looked at as a yearMonthDuration plus a
            dayTimeDuration. This function returns the result
            rounded to contain only years and months. The
            calculation is as follows: first the duration is
            calculated as the value of a dayTimeDuration in
            seconds. Then, starting from $srcval2, the
            maximum number of months in the duration are
            calculated. The remainder r is is rounded
            and added to the number of months. If 0 <=
            r < 15.5 days, r rounds to 0
            months; if 15.5 days <= r, r
            rounds to 1 month.
xf:get-dayTimeDuration-from-dateTimes( | 
                    dateTime  | 
                    $srcval1, | 
                  
dateTime  | 
                    $srcval2)
                    => dayTimeDuration | 
                  
Returns the dayTimeDuration that corresponds to the
            difference between the value of $srcval1
            and the value of $srcval2. If the value of
            $srcval1 follows in time the value of
            $srcval2, then the returned value is a
            negative duration. If one or both arguments do not have
            a timezone they are assigned an implicit ·implementation-defined· timezone. If either argument
            is the empty sequence, returns the empty sequence.
This function returns the value of a dayTimeDuration in seconds. Note that the number of days in this value can be greater than 31.
op:subtract-dates(date $srcval1, date $srcval2) =>
                dayTimeDuration
              Returns the dayTimeDuration that corresponds to the
            difference between the value of $srcval1
            and the value of $srcval2. If the value of
            $srcval1 follows in time the value of
            $srcval2, then the returned value is a
            negative duration. If one or both arguments do not have
            a timezone, they are assigned an implicit ·implementation-defined· timezone. If either argument
            is the empty sequence, returns the empty sequence.
This function returns the value of a dayTimeDuration in seconds. Note that the number of days in this value can be greater than 31.
Backs up the subtract, "-", operator on date values.
op:subtract-times(time $srcval1, time $srcval2) =>
                dayTimeDuration
              Returns the dayTimeDuration that corresponds to the
            difference between the value of $srcval1
            and the value of $srcval2. If the value of
            $srcval1 follows in time the value of
            $srcval2, then the returned value is a
            negative duration. If one or both arguments do not have
            a timezone, they are assigned an implicit ·implementation-defined· timezone. If either argument
            is the empty sequence, returns the empty sequence.
This function returns the value of a dayTimeDuration in seconds.
Backs up the subtract, "-", operator on time values.
op:add-yearMonthDuration-to-dateTime( | 
                    dateTime  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => dateTime | 
                  
Returns the end of a time period by adding a yearMonthDuration ($srcval2) to the dateTime that starts the period ($srcval1). If the duration is negative, then the "end" of the period precedes the "start" of the period.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "+" operator on dateTime and yearMonthDuration.
op:add-dayTimeDuration-to-dateTime( | 
                    dateTime  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => dateTime | 
                  
Returns the end of a time period by adding a dayTimeDuration ($srcval2) to the dateTime that starts the period ($srcval1). If the duration is negative, then the "end" of the period precedes the "start" of the period.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "+" operator on dateTime and dayTimeDuration.
op:subtract-yearMonthDuration-from-dateTime( | 
                    dateTime  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => dateTime | 
                  
Returns the start of a time period by subtracting a yearMonthDuration ($srcval2) from the dateTime that ends the period ($srcval1). If the duration is negative, then the "start" of the period precedes the "end" of the period.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "-" operator on dateTime and yearMonthDuration.
op:subtract-dayTimeDuration-from-dateTime( | 
                    dateTime  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => dateTime | 
                  
Returns the start of a time period by subtracting a dayTimeDuration ($srcval2) from the dateTime that ends the period ($srcval1). If the duration is negative, then the "start" of the period precedes the "end" of the period.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "-" operator on dateTime and dayTimeDuration.
op:add-yearMonthDuration-to-date( | 
                    date  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => date | 
                  
Returns the date computed by adding the
            yearMonthDuration in $srcval2 to the date
            in $srcval1. If the duration is negative,
            then the result date precedes
            $srcval1.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "+" operator on date and yearMonthDuration.
op:add-dayTimeDuration-to-date( | 
                    date  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => dateTime | 
                  
Returns the date computed by adding the days
            component of the canonical representation of the
            dayTimeDuration in $srcval2 to the date in
            $srcval1.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "+" operator on date and dayTimeDuration.
op:subtract-yearMonthDuration-from-date( | 
                    date  | 
                    $srcval1, | 
                  
yearMonthDuration  | 
                    $srcval2)
                    => date | 
                  
Returns the date computed by subtracting the
            yearMonthDuration in $srcval2 from the
            date in $srcval. If the duration is
            negative, then the result date follows
            $srcval1.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "-" operator on date and yearMonthDuration.
op:subtract-dayTimeDuration-from-date( | 
                    date  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => date | 
                  
Returns the date computed by subtracting the days
            component of the canonical representation of the
            dayTimeDuration in $srcval2 from the date
            in $srcval1. If the duration is negative,
            then the result date follows $srcval1
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "-" operator on date and dayTimeDuration.
op:add-dayTimeDuration-to-time( | 
                    time  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => time | 
                  
First, the days component of $srcval2
            is set to zero (0) and the value of the resulting
            duration is calculated. This value is added to
            $parameter1 and the result returned.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "+" operator on time and dayTimeDuration.
op:subtract-dayTimeDuration-from-time( | 
                    time  | 
                    $srcval1, | 
                  
dayTimeDuration  | 
                    $srcval2)
                    => time | 
                  
First, the days component of $srcval2
            is set to zero (0) and the value of the resulting
            duration is calculated. This value is subtracted from
            $srcval1 and the result returned.
The result has the same timezone as
            srcval1. If srcval1 has no
            timezone the result has no timezone.
This functions backs up the "-" operator on time and dayTimeDuration.
This section discusses constructor functions for
          QNames as defined in [XML Schema Part
          2: Datatypes]. Each constructor function takes one or
          more single string values as arguments.
          Leading and trailing whitespace, if present, is stripped
          from the value before the result is constructed.
| Function | Meaning | Source | 
|---|---|---|
xf:expanded-QName | 
              Returns a QName with the namespace URI given in the first argument and the local name in the second argument. | 
This section discusses functions on QNames as defined in [XML Schema Part 2: Datatypes].
| Function | Meaning | Source | 
|---|---|---|
op:QName-equal | 
              Returns true
              if the local names and namespace URIs of the two
              arguments are equal. | 
              |
xf:get-local-name-from-QName | 
              Returns a string representing the local part of the QName argument. | |
xf:get-namespace-from-QName | 
              Returns the namespace URI for the QName argument. This may be the empty sequence if the QName is in no namespace. | 
op:QName-equal(QName $srcval1, QName $srcval2) =>
                boolean
              Returns true if the namespace names of
            $srcval1 and $srcval2 are
            equal and the local-name parts of $srcval1
            and $srcval2 are identical on a
            codepoint-by-codepoint basis. Otherwise, returns
            false. Two namespace names are considered
            equal if they are either both absent or both present
            and identical on a codepoint-by-codepoint basis.
Backs up the "eq" and "ne" operators on values of type QName.
If either namespace name is a relative URI, it is undefined whether it will compare equal to any other namespace name.
xf:get-local-name-from-QName(QName? $srcval) =>
                string?
              Returns a string representing the local part of
            $srcval. If $srcval is the
            empty sequence, returns the empty sequence.
This section defines a constructor function for anyURI as defined in [XML Schema Part 2: Datatypes].
| Function | Meaning | Source | 
|---|---|---|
xf:resolve-uri | 
              Returns an absolute
              anyURI given a base URI and a relative
              URI. | 
              
xf:resolve-uri(anyURI $base, anyURI $relative) =>
                anyURI
              This functions expects $base to be an
            absolute URI and $relative to be a
            relative URI. It resolves the relative URI
            $relative against the base URI
            $base and returns an absolute URI. Returns
            $relative if it is an absolute URI. If
            $base is a relative URI, then an error is
            raised ("Relative URI base argument to
            resolve-uri").
This section specifies functions that take anyURI as arguments.
| Function | Meaning | Source | 
|---|---|---|
op:anyURI-equal | 
              Returns true
              if the two arguments are equal. | 
              
We define the following comparison operators on base64Binary and hexBinary values. Comparisons take two operands of the same type; that is, both operands must be base64Binary or hexBinary. Each returns a boolean value.
| Function | Meaning | Source | 
|---|---|---|
op:hex-binary-equal | 
              Returns true
              if the two arguments are equal. | 
              |
op:base64-binary-equal | 
              Returns true
              if the two arguments are equal. | 
              
op:hex-binary-equal(hexBinary $value1, hexBinary $value2) =>
                boolean
              Returns true if $value1
            and value2 are of the same length and
            contain the same code-points. Otherwise, returns
            false.
This function backs up the "eq" and "ne" operators on hexBinary values.
op:base64-binary-equal( | 
                    base64Binary  | 
                    $value1, | 
                  
base64Binary  | 
                    $value2)
                    => boolean | 
                  
Returns true if $value1
            and value2 are of the same length and
            contain the same code-points. Otherwise, returns
            false.
This function backs up the "eq" and "ne" operators on base64Binary values.
This section discusses functions that take NOTATION as arguments.
| Function | Meaning | Source | 
|---|---|---|
op:NOTATION-equal | 
              Returns true
              if the two arguments are equal. | 
              
This section discusses functions and operators on
        nodes. Nodes are formally defined
        in [XQuery 1.0 and XPath 2.0 Data
        Model].
| Function | Meaning | Source | 
|---|---|---|
xf:name | 
              Returns the name of the context node or the specified node as a string. | XPath 1.0 modified | 
xf:local-name | 
              Returns the local name of the context node or the specified node as a QName. | XPath 1.0 modified | 
xf:namespace-uri | 
              Returns the namespace URI as a string for the QName of the argument node or the context node if the argument is omitted. This may be the zero-length string if the QName is in no namespace. | |
xf:number | 
              Returns the value of the context node or the specified node converted to a number. | XPath 2.0 req 1.5 (Could) | 
xf:lang | 
              Returns true or false depending on whether the language of the context node, as defined using the xml:lang attribute, is the same as, or a sublanguage of, the language specified by the argument. | XPath 1.0 | 
op:node-equal | 
              Returns true if the two arguments have the same identity. | Data Model | 
xf:deep-equal | 
              Returns true if the two arguments have the same value. | Data Model | 
op:node-before | 
              Indicates whether one node appears before another node in document order. | Data Model | 
op:node-after | 
              Indicates whether one node appears after another node in document order. | Data Model | 
xf:copy | 
              Returns a deep copy of a node. Not supported in XSLT. | Data Model | 
xf:root | 
              Returns the root of the tree to which the node argument belongs. | Data Model | 
For the illustrative examples below, assume an XQuery
          operating on a Purchase Order document containing a
          number of item elements. Each item has child elements
          called description, quantity, etc. Quantity has simple
          content of type decimal. Further assume that variables
          $item1, $item2, etc. are bound
          to the nodes for the item elements in the document in
          sequence.
xf:name()
                => string
              xf:name(node? $srcval) =>
                string
              Returns the name of a node, as a string that is either the zero-length string, or has the lexical form of a QName.
If the argument is omitted, it defaults to the context node. If there is no context node (that is, if the context item is not a node), the function returns the zero-length string.
If the argument is supplied and is the empty sequence, the function returns the zero-length string.
If the target node has no name (that is, if it is a document node, a comment, or a text node), the function returns the zero-length string.
Otherwise, the value returned is a string whose lexical form is a QName.
If $srcval is a processing instruction
            or a namespace node, or if it is an element or
            attribute node whose expanded QName (as determined by
            the name accessor in the data model) is in no
            namespace, then the function returns the local part of
            the expanded QName.
If $srcval is an element or attribute
            whose expanded QName is in a namespace, then a prefix
            is determined by searching the namespace nodes for that
            element, or in the case of an attribute, the namespace
            nodes for the element that is the parent of the
            attribute. There will always be at least one such
            namespace node whose namespace URI matches the
            namespace URI of the node's expanded QName. The prefix
            is taken from one of these namespace nodes; if there
            are several, then the implementation may choose one of
            them arbitrarily (implementations have the option to
            record the original namespace prefix as part of the
            data associated with a node, but they are not required
            to do so). This prefix is then combined with the local
            part of the node's expanded QName to form a string
            which will take one of the forms "prefix:local-part"
            (if the prefix is a non-zero length string) or
            "local-part" (if the prefix is a zero-length
            string).
xf:local-name()
                => string
              xf:local-name(node? $srcval) =>
                string
              Returns the local part of the name of
            $srcval as a string that will either be
            the zero-length string, or will have the lexical form
            of an NCName.
If the argument is omitted, it defaults to the context node. If there is no context node (that is, if the context item is not a node), the function returns the zero-length string.
If the argument is supplied and is the empty sequence, the function returns the zero-length string.
If the target node has no name (that is, if it is a document node, a comment, or a text node), the function returns the zero-length string.
Otherwise, the value returned will be the local part of the expanded QName of the target node (as determined by the name accessor in the data model). This will be a string whose lexical form is an NCName.
xf:namespace-uri()
                => string
              xf:namespace-uri(node? $srcval) =>
                string
              Returns the namespace URI of the QName of
            $srcval as a string. If the argument is
            omitted, it defaults to the context node. If there is
            no context node (that is, if the context item is not a
            node), the function returns the zero-length string. If
            $srcval is the empty sequence, the
            zero-length string is returned.
If the $srcval is neither an element
            nor an attribute node, or if it is an element or
            attribute node which has no QName or whose expanded
            QName (as determined by the name accessor in the data
            model) is in no namespace, then the function returns
            the zero-length string.
xf:number()
                => double
              xf:number(node $srcval) =>
                double
              Returns the value of the node indicated by
            $srcval or, if $srcval is not
            specified, the context node, converted to a double. If
            the string value of the node is not a valid lexical
            representation of a numeric simple type as defined in
            [XML Schema Part 2: Datatypes],
            then an error is raised ("Invalid lexical
            representation").
xf:lang(string $testlang) =>
                boolean
              Returns true or false
            depending on whether the language of the context node,
            as defined using the xml:lang attribute,
            is the same as, or a sublanguage of, the language
            specified by $testlang.
The relevant xml:lang attribute is
            determined by the value of the XPath expression:
            (ancestor-or-self::*/@xml:lang)[last()]
If this expression returns an empty sequence, the
            function returns false.
Otherwise, the function returns true if
            and only if the string-value of the relevant
            xml:lang attribute is equal to
            $testlang ignoring case, or if the
            string-value of the relevant testlang
            attribute contains some hyphen (-) such that the part
            of the string-value preceding that hyphen is equal to
            $testlang, ignoring case.
op:node-equal(node $parameter1, node $parameter2) =>
                boolean
              If the node identified by the value of
            $parameter1 is the same node as the node
            identified by the value of $parameter2
            (that is, the two nodes have the same identity), then
            the function returns true; otherwise, the
            function returns false. This function
            backs up the "is" and "isnot" operators on nodes.
xf:deep-equal(node $parameter1, node $parameter2) =>
                boolean
              xf:deep-equal( | 
                    node  | 
                    $parameter1, | 
                  
node  | 
                    $parameter2, | 
                  |
anyURI  | 
                    $collation)
                    => boolean | 
                  
This function tests whether the name and content of
            the node $parameter1 are the same as the
            name and content of the node
            $parameter2.
The following (recursive) tests are applied in order to determine whether two nodes are deep-equal.
If the two nodes are of different node-kinds, the result is false.
if (xf:node-kind($parameter1) ne xf:node-kind($parameter2)) then false else
If the two nodes have names, and the names are different when compared as expanded-QNames, the result is false.
if (xf:node-name($parameter1) != xf:node-name($parameter2)) then false else
If the two nodes are text nodes, comment nodes, processing instruction nodes, or namespace nodes, then the result is true if and only if the two nodes have equal string-values, when compared using the selected collation.
if (some $n in ("text", "comment", "processing-instruction", "namespace")
         satisfies $n eq xf:node-kind($parameter1)
    and xf:compare(xf:string($parameter1), xf:string($parameter2), $collation) ne 0)
then false
else
            If either node has attributes, then the result is false if either node has an attribute that is not deep-equal to an attribute of the other node, using the selected collation.
if (some $a1 in $parameter1/@* satisfies
      not (some $a2 in $parameter2/@* 
           satisfies xf:deep-equal($a1, $a2, $collation))
    or some $a2 in $parameter2/@* satisfies
      not (some $a1 in $parameter1/@* 
           satisfies xf:deep-equal($a1, $a2, $collation)))
then false
else
            If neither node has element children, then the
            result is true only if the other node also has simple
            content, and if the simple content of the two nodes
            (that is, the result of the xf:data function) is
            equal under the rules for the xf:sequence-deep-equal
            function, using the selected collation. (Note:
            attributes always have simple content.)
if (empty($parameter1/*) and empty($parameter2/*))
then xf:sequence-deep-equal( xf:data($parameter1),
                             xf:data($parameter2),
                             $collation )
else
            Otherwise, the result is true if and only if the
            children of node $parameter1 are pairwise
            deep-equal to the children of node
            $parameter2, ignoring comment and
            processing instruction nodes in both cases.
xf:sequence-deep-equal( $parameter1/(* | text()),
                        $parameter2/(* | text()),
                        $collation )
            Note:
The two nodes are not required to have the same type annotation, and they are not required to have the same in-scope namespaces. They may also differ in their parent, their base URI, and their unique-ID. The order of children is significant, but the order of attributes is insignificant. The contents of comments and processing instructions are significant only if these nodes are used directly as arguments to the function, not if they appear as children of the nodes supplied as arguments.
Note:
The result of sequence-deep-equal(1,
              current-dateTime()) is false; it does not
              cause an error to be returned.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
op:node-before(node $parameter1, node $parameter2) =>
                boolean
              If the node identified by the value of
            $parameter1 occurs in document order
            before the node identified by the value of
            $parameter2, this function returns
            true; otherwise, it returns
            false. The rules determining the order of
            nodes within a single document and in different
            documents can be found in [XQuery
            1.0 and XPath 2.0 Data Model]. This function backs
            up the "<<" operator.
op:node-after(node $parameter1, node $parameter2) =>
                boolean
              If the node identified by the value of
            $parameter1 occurs in document after the
            node identified by the value of
            $parameter2, this function returns
            true; otherwise, it returns
            false. The rules determining the order of
            nodes within a single document and in different
            documents can be found in [XQuery
            1.0 and XPath 2.0 Data Model]. This function backs
            up the ">>" operator.
xf:copy(node? $srcval) =>
                node?
              Returns a copy of the node that is the value of
            $srcval including all its attributes and
            descendants; the copy has a different identity than the
            node indicated by the value of
            $srcval.
Note:
XSLT will not support this function.
[Issue 60: What are the precise semantics of the copy() function?]
$var = xf:copy($item1) creates a node
              that is a copy of the value of $item1, including its
              attributes and descendants, gives it a different
              identity, and sets the value of $var equal to it.
              Assume that the value of $item1 was the
              element node:
   <family name='green'>
      <father>peter</father>
      <mother>mary<mother>
      <child>joseph</child>
   </family>
              The value of $var would be
   <family name='green'>
      <father>peter</father>
      <mother>mary<mother>
      <child>joseph</child>
   </family>
              xf:root(node $srcval) =>
                node
              Returns the root of the tree to which
            $srcval belongs. This will usually, but
            not necessarily, be a document node. If
            $srcval is a document node it is
            returned.
[Issue 162: Can we omit the node argument to root() and use the context item if it is omitted.]
| Function | Meaning | Source | 
|---|---|---|
xf:if-absent | 
              If first argument is the empty sequence, returns second argument; otherwise, returns content of first argument. | XQuery | 
xf:if-empty | 
              If first argument is the empty sequence or an element node with empty content, returns second argument; otherwise, returns content of first argument. | XQuery | 
It is sometimes desirable to write arithmetic expressions in which absent data will be replaced by a default value. For example, it might be desirable for the expression emp/(salary + bonus) to return the salary in the case where an employee has no bonus. The + operator will return the empty sequence in this case. The above functions address this problem.
[Issue 183: Should xf:if-absent and xf:if-empty have static typing rules?]
xf:if-absent(node? $node, anySimpleType $value) => anySimpleType*
              If the first argument is the empty sequence,
            if-absent() returns the second argument;
            otherwise, it returns the content of the first
            argument.
xf:if-empty(node? $node, anySimpleType $value) => anySimpleType*
              If the first argument is the empty sequence or an element with empty content, if-empty() returns the second argument; otherwise, it returns the content of the first argument.
[Issue 155: The term 'empty content' should be changed or, at least, be carefully defined.]
A sequence is an ordered collection of zero
        or more items. An item is either
        a node or an atomic value. The terms sequence
        and item are defined formally in [XQuery 1.0: An XML Query Language] and
        [XPath 2.0].
[Issue 82: Clarify distinction between node sets, lists, and sequences]
[Issue 89: Functions that have anyType in their return are problematic.]
The following constructor functions are defined for sequences.
| Function | Meaning | 
|---|---|
op:to | 
              Returns the sequence containing every integer between the values of the operands. | 
op:to(decimal $firstval, decimal $lastval) =>
                integer+
              The effective values of $firstval and
            $lastval are computed as cast as
            integer(floor($firstval)) and cast as
            integer(floor($lastval)).
Converts both its operands to integers and returns
            the sequence containing every integer whose value is
            between the effective value of $firstval
            (inclusive) and the effective value of
            $lastval (inclusive), in monotonic order.
            If the effective value of the first operand is less
            than the effective value of the second, the sequence is
            in increasing order; otherwise, it is in decreasing
            order. If the effective value of the two operands is
            equal, a sequence containing a single integer equal to
            the effective value is returned.
This function backs up the "to" operator.
The following functions are defined on sequences.
| Function | Meaning | Source | 
|---|---|---|
xf:boolean | 
              Casts a sequence to a boolean. See also 16.9 Casting to boolean . | XPath 1.0 | 
op:concatenate | 
              Concatenates two sequences. | XPath 1.0 | 
xf:item-at | 
              Returns the item at given index. | XPath 2.0 Req 4.4 (Should) | 
xf:index-of | 
              Returns a sequence of unsignedInts, each of which is the index of a member of the specified sequence that is equal to the simple value or node that is the value of the second argument. If no members of the specified sequence are equal to the value of the second argument, the function returns an empty sequence. | XPath 2.0 Req 4.4 (Should) | 
xf:empty | 
              Indicates whether or not the provided sequence is empty. | XPath 2.0 Req 4.4 (Should) | 
xf:exists | 
              Indicates whether or not the provided sequence is not empty. | |
xf:distinct-nodes | 
              Returns a sequence in which all redundant duplicate nodes, based on node identity, have been deleted. The specific node in a collection of redundant duplicate nodes that is retained in implementation-dependent. | XPath 2.0 Req 4.4 (Should) | 
xf:distinct-values | 
              Returns a sequence in which all redundant duplicate nodes or values, based on value equality, have been deleted. The specific node or value in a collection of redundant duplicate nodes or values that is retained is implementation-dependent. | XPath 2.0 Req 4.4 (Should) | 
xf:insert | 
              Inserts an item or sequence of items into a specified position of a sequence. | XPath 2.0 Req 2.4, 4.4 (Should) | 
xf:remove | 
              Removes an item from a specified position of a sequence. | XPath 2.0 Req 2.4, 4.4 (Should) | 
xf:subsequence | 
              Returns the subsequence of a given sequence identified by location. | XPath 2.0 Req 4.4 (Should) | 
[Issue 63: Do we need variations of index-of for values and identity?]
[Issue 66: A function to reorder a sequence into document order is needed]
As in the previous section, for the illustrative
          examples below, assume an XQuery operating on a Purchase
          Order document containing a number of item elements. The
          variable $seq is bound to the sequence of
          item nodes in document order. The variables
          $item1, $item2, etc. are bound
          to individual item nodes in the sequence.
xf:boolean(item* $srcval) =>
                boolean
              Returns the effective boolean value of the argument
            as defined in [XQuery 1.0: An XML
            Query Language] (true if the effective
            boolean value is true, and
            false if the effective boolean value is
            false).
If fallback conversion is enabled, then the function
            is applied to the first item in the sequence. This is
            expected to be a value. If the first item in the
            sequence is a node, then its typed value is extracted.
            The value is converted to boolean as
            defined in 16.9 Casting
            to boolean .
op:concatenate(item* $seq1, item* $seq2) => item*
              Returns a sequence consisting of the items in
            $seq1 followed by the items in
            $seq2. This function backs up the infix
            operator ",". If either sequence is the empty sequence,
            the other operand is returned.
xf:item-at(item* $seqParam, decimal $posParam) =>
                item?
              Returns the item in $seqParam that is
            located at the index that is the value of
            $posParam.
If $seqParam is the empty sequence,
            returns the empty sequence.
If the value of $posParam is greater
            than the number of items in the sequence, or is less
            than or equal to zero (0), then an error is raised
            ("Invalid position").
This function is used in the definition of the
            formal semantics of filter expressions, that is,
            expressions of the form
            expression-1[expression-2]
xf:node-equal(xf:item-at($seq,
                  1), $item1) returns
                  true.
xf:index-of(item* $seqParam, item $srchParam) =>
                unsignedInt*
              xf:index-of( | 
                    item*  | 
                    $seqParam, | 
                  
item  | 
                    $srchParam, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => unsignedInt* | 
                  
If the value of $seqParam contains only
            simple values, then the function returns a sequence of
            unsigned integers indicating the indexes (positions) of
            items in the value of $seqParam that are
            equal to the simple value of $srchParam.
            If the data types of the simple values are strings,
            then equality is determined according to the collation
            that is used.
If the value of $seqParam contains
            nodes, then the function returns a sequence of unsigned
            integers indicating the indexes (positions) of nodes
            whose string values are equal to the string value of
            the node in the second argument. Equality of string
            values is determined according to the collation that is
            used.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
The sequence must contain either simple
            values or nodes, not both. In addition, if the
            sequence contains simple values $srchParam
            must be a simple value and if the sequence contains
            nodes $srchParam must be a node. If the
            above conditions are violated, then an error is raised
            ("Mixed simple values and nodes").
If the value of $seqParam is the empty
            sequence, the empty sequence is returned.
The index is 1-based, not 0-based.
xf:empty(item* $srcval) =>
                boolean
              If the value of $srcval is the empty
            sequence, the function returns true;
            otherwise, the function returns false.
xf:exists(item* $srcval) =>
                boolean
              If the value of $srcval is not the
            empty sequence, the function returns true;
            otherwise, the function returns false.
xf:empty($seq)
                  returns true.
xf:distinct-nodes(node* $srcval) =>
                node*
              Returns the sequence that results from removing from
            $srcval all but one of a set of nodes that
            have the same identity as one another, based on node
            identity (that is, using node-equal()).
            The specific occurrence in a collection of identical
            nodes that is retained is implementation-dependent. If
            $srcval is the empty sequence, returns the
            empty sequence.
[Issue 154: Should we define a second order distinct function?]
xf:distinct-values(item* $srcval) =>
                item*
              xf:distinct-values(item* $srcval, anyURI $collationLiteral)
                => item*
              $srcval must contain either
            simple values or nodes, not both. If the
            sequence contains both simple values and nodes, then an
            error is raised ("Mixed simple values and nodes").
If $srcval contains only nodes, returns
            the sequence that results from removing from
            $srcval all but one of a set of nodes that
            are equal to one other, based on the nodes' values
            (that is, using deep-equal()). The
            specific node in a collection of nodes having equal
            values that is retained is
            implementation-dependent.
If $srcval contains only values,
            returns the sequence that results from removing from
            $srcval all but one of a set of values
            that are eq to one other. Values of the
            same type must have a total order: date/time values
            must either all contain a timezone or all not contain a
            timezone; duration values must all contain either only
            years and months or only days, hours, minutes and
            seconds. If this condition is not satisfied, then an
            error is raised ("Invalid duration value"). Equality of
            string values are determined according to the collation
            that is used. The specific node in a collection of
            values having equal values that is retained is
            implementation-dependent.
If $srcval is the empty sequence,
            returns the empty sequence.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:insert(item* $target, decimal $position, item* $inserts) =>
                item*
              Returns a new sequence constructed from the value of
            $target with the value of
            $inserts inserted at the position
            specified by the value of $position. (The
            value of $target is not affected by the
            sequence construction.)
Let the effective value of $position be
            N computed as cast as
            unsignedInt(floor($position)).
If N is less than zero (0), the effective
            value of N is zero (0). If N is
            greater than the number of items in
            $target, then the effective value of
            N is equal to the number of items in
            $target plus 1.
The value returned by the function consists of all
            items of $target whose index is less than
            or equal to N, followed by all items of
            $inserts, followed by the remaining
            elements of $target, in that sequence.
If $target is the empty sequence, a
            copy of $inserts is returned. If
            $inserts is the empty sequence, a copy of
            $target is returned.
xf:remove(item* $target, decimal $position) =>
                item*
              Returns a new sequence constructed from the value of
            $target with the item at the position
            specified by the value of $position
            removed.
Let the effective value of $position be
            N computed as cast as
            unsignedInt(floor($position)).
If N is less than 1 or greater than the
            number of items in $target, no action is
            taken. Otherwise, the value returned by the function
            consists of all items of $target whose
            index is less than N, followed by all items of
            $target whose index is greater than
            N. If $target is the empty
            sequence, the empty sequence is returned.
xf:subsequence(item* $sourceSeq, decimal $startingLoc) =>
                item*
              xf:subsequence( | 
                    item*  | 
                    $sourceSeq, | 
                  
decimal  | 
                    $startingLoc, | 
                  |
decimal  | 
                    $length)
                    => item* | 
                  
Returns the contiguous sequence of items in the
            value of $sourceSeq beginning at the
            position indicated by the value of
            $startingLoc and continuing for the number
            of items indicated by the value of
            $length.
If $length is not specified, then the
            subsequence includes items to the end of
            $sourceSeq.
The value of $length can be greater
            than the number of items in the value of
            $sourceSeq following the beginning
            position, in which case the subsequence includes items
            to the end of $length.
The first item of a sequence is located at position 1, not position 0.
If $sourceSeq is the empty sequence,
            returns the empty sequence.
| Function | Meaning | Source | 
|---|---|---|
xf:sequence-deep-equal | 
              Returns true if the two arguments have the same value. | Data Model | 
xf:sequence-node-equal | 
              Returns true if the two arguments have the same nodes. | Data Model | 
op:union | 
              Returns the union of the two sequence arguments, eliminating duplicates. | XPath 2.0 Req 1.5 (Should) | 
op:intersect | 
              Returns the intersection of the two sequence arguments, eliminating duplicates. | XPath 2.0 Req 1.5 (Should) | 
op:except | 
              Returns the difference of the two sequence arguments, eliminating duplicates. | XPath 2.0 Req 1.5 (Should) | 
As in the previous sections, for the illustrative
          examples below, assume a XQuery operating on a Purchase
          Order document containing a number of item elements. The
          variables $item1, $item2, etc.
          are bound to individual item nodes in the sequence. We
          shall use sequences of these nodes in the examples
          below.
xf:sequence-deep-equal(item* $parameter1, item* $parameter2) =>
                boolean?
              xf:sequence-deep-equal( | 
                    item*  | 
                    $parameter1, | 
                  
item*  | 
                    $parameter2, | 
                  |
anyURI  | 
                    $collationLiteral)
                    => boolean? | 
                  
If the sequences that are the values of
            $parameter1 and $parameter2
            have the same values (that is, they have the same
            number of items and items in corresponding positions in
            the two sequences compare equal if they are values and
            deep-equal() if they are nodes.), then the
            function returns true; otherwise, the
            function returns false. Returns the empty
            sequence if one or both of its arguments is the empty
            sequence.
String values are compared according to the collation that is used.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:sequence-node-equal(node* $parameter1, node* $parameter2) =>
                boolean?
              Returns the empty sequence if one or both of its arguments is the empty sequence.
If the sequences that are the values of
            $parameter1 and $parameter2
            have the same nodes as content (that is, they have the
            same number of items and items in corresponding
            positions in the two sequences are the identical
            nodes), then the function returns true;
            otherwise, the function returns false.
op:union(node* $parameter1, node* $parameter2) =>
                node*
              Constructs a sequence containing every node that
            occurs in the values of $parameter1 or
            $parameter2, eliminating duplicate nodes.
            Nodes are returned in document order. Two nodes are
            equal if they are xf:node-equal().
This function backs up the "union" or "|" operator.
op:intersect(node* $parameter1, node* $parameter2) =>
                node*
              Constructs a sequence containing every node that
            occurs in the values of both $parameter1
            and $parameter2, eliminating duplicate
            nodes. Nodes are returned in document order.
If either operand is the empty sequence, the empty sequence is returned.
Two nodes are equal if they are xf:node-equal().
This function backs up the "intersect" operator.
op:except(node* $parameter1, node* $parameter2) =>
                node*
              Constructs a sequence containing every node that
            occurs in the values of $parameter1, but
            not in the value of $parameter2,
            eliminating duplicate nodes. Nodes are returned in
            document order.
If $parameter1 is the empty sequence,
            the empty sequence is returned. If
            $parameter2 is the empty sequence, a copy
            of $parameter1 is returned.
Two nodes are equal if they are xf:node-equal().
This function backs up the "except" operator.
Aggregate functions take a sequence as argument and
          return a single value computed from values in the
          sequence. Except for xf:count, if the
          sequence contains nodes, the value is extracted from the
          node and used in the computation.
| Function | Meaning | Source | 
|---|---|---|
xf:count | 
              Returns the number of items in the sequence. | XPath 1.0 | 
xf:avg | 
              Returns the average of a sequence of numbers. | XSLT 2.0 Req. 1.4 (Must) | 
xf:max | 
              Returns the object with maximum value from a collection of comparable objects. | XSLT 2.0 Req. 1.4 (Must) | 
xf:min | 
              Returns the object with minimum value from a collection of comparable objects. | XSLT 2.0 Req. 1.4 (Must) | 
xf:sum | 
              Returns the sum of a sequence of numbers. | XSLT 1.0 | 
xf:count(item* $srcval) =>
                unsignedInt
              Returns the number of items in the value of
            $srcval. Returns 0 if $srcval
            is the empty sequence.
xf:avg(item* $srcval) =>
                double?
              If $srcval contains nodes, the value of
            each node is extracted using the xf:data() function.
            Values that equal the empty sequence are discarded. If
            after this, $srcval contains only numbers,
            xf:avg() returns the average of the
            numbers (computed as sum($srcval) div
            count($srcval)). If $srcval is the
            empty sequence, the empty sequence is returned.
If, after extracting the values from nodes,
            $srcval does not contain only numbers,
            then an error is raised ("Argument not numeric").
xf:max(item* $srcval) =>
                anySimpleType?
              xf:max(item* $srcval, anyURI $collationLiteral)
                => anySimpleType?
              If $srcval contains nodes, the value of
            each node is extracted using the xf:data() function.
            Values that equal the empty sequence are discarded. If,
            after this, $srcval is the empty sequence,
            the empty sequence is returned. After extracting the
            values from nodes, $srcval must contain
            only values of a single type. (For numeric values, the
            type promotion rules defined in 5.2 Operators on Numeric
            Values are used to promote all values to a
            single common type.) In addition, the values in the
            sequence must have a total order. Date/time values must
            either all contain a timezone or all not contain a
            timezone. Duration values must either all be
            yearMonthDuration values or must all be dayTimeDuration
            values. If any of these conditions is not true, then an
            error is raised ("Invalid argument").
xf:max returns the item in the value of
            $srcval whose value is greater than or
            equal to the value of every other item in the value of
            $srcval. If there are two or more such
            items, then the specific item whose value is returned
            is implementation-dependent.
If the items in the value of $srcval
            are strings, then the determination of the greatest
            item is made according to the collation that is
            used.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:min(item* $srcval) =>
                anySimpleType?
              xf:min(item* $srcval, anyURI $collationLiteral)
                => anySimpleType?
              If $srcval contains nodes, the value of
            each node is extracted using the xf:data() function.
            Values that equal the empty sequence are discarded. If,
            after this, $srcval is the empty sequence,
            the empty sequence is returned. After extracting the
            values from nodes, $srcval must contain
            only values of a single type. (For numeric values, the
            type promotion rules defined in 5.2 Operators on Numeric
            Values are used to promote all values to a
            single common type.) In addition, the values in the
            sequence must have a total order. Date/time values must
            either all contain a timezone or all not contain a
            timezone. Duration values must either all be
            yearMonthDuration values or must all be dayTimeDuration
            values. If any of these conditions is not true, then an
            error is raised ("Invalid argument").
xf:min returns the item in the value of
            $srcval whose value is less than or equal
            to the value of every other item in the value of
            $srcval. If there are two or more such
            items, then the specific item whose value is returned
            is implementation-dependent.
If the items in the value of $srcval
            are strings, then the determination of the least item
            is made according to the collation that is used.
The collation used by the invocation of this function is determined according to the rules in 6.2 Equality and Comparison of Strings.
xf:sum(item* $srcval) =>
                double
              If $srcval contains nodes, the value of
            each node is extracted using the xf:data() function.
            Values that equal the empty sequence are discarded. If,
            after this, $srcval contains only numbers,
            xf:sum returns the sum of the numbers. If
            $srcval is the empty sequence, then 0.0 is
            returned.
If, after extracting the values from nodes,
            $srcval does not contain only numbers,
            then an error is raised ("Non-numeric values").
| Function | Meaning | Source | 
|---|---|---|
xf:id | 
              Returns the sequence of nodes having unique IDs that match the IDREFs represented by the argument sequence. | XPath 1.0 | 
xf:idref | 
              Returns the sequence of nodes with IDREFs matching the items in the argument sequence. | XSLT 2.0 Req. 2.11 (Could) | 
xf:document | 
              Returns a sequence of document nodes retrieved using the URIs specified in its arguments. | XSLT 1.0 | 
xf:collection | 
              Returns a sequence of document nodes retrieved using the URI specified as its argument. | |
xf:input | 
              Returns the input sequence. | 
xf:id(IDREF* $srcval) =>
                element*
              Returns the sequence of element nodes with ID values
            matching the value of one of the IDREFs in the sequence
            argument. If the value of $srcval is a
            single IDREF, it behaves as though a sequence of length
            one was supplied.
The nodes that are returned all belong to the context document. See 15.4 op:context-document. If the context document is not specified, then an error is raised ("No context document"). If the context document is the empty sequence, returns the empty sequence.
xf:idref(string* $srcval) =>
                element*
              Returns the sequence of elements nodes having either
            an IDREF attribute whose value matches the value of one
            of the items in the value of $srcval or an
            IDREFS attribute whose value contains an IDREF value
            that matches the value of one of the items in the value
            of $srcval. This function allows reverse
            navigation from IDs to IDREFs.
The nodes that are returned all belong to the context document. See 15.4 op:context-document. If the context document is not specified, then an error is raised ("No context document"). If the context document is the empty sequence, returns the empty sequence.
xf:document(item* $srcval1) =>
                node*
              xf:document(item* $srcval1, node* $srcval2) =>
                node*
              If $srcval2 is the empty sequence, or a
            sequence whose first item is not a node, unless all the
            URIs in $srcval1 are absolute URIs, then
            an error is raised ("Invalid arguments to document
            function"). If $srcval2 is a sequence of
            more than one node, the effect is as if only the first
            node in the sequence were supplied.
Two documents are treated as the same document if they are identified by the same URI. The URI used for the comparison is the absolute URI into which any relative URI was resolved and does not include any fragment identifier. Thus, the following expression (if it does not cause an error) will always be true:
document("foo.xml") is document("foo.xml")
            Note:
The scope over which this applies depends on the processing context. In XSLT, it applies to any two calls on the document function executed during the same transformation. In XQuery, it applies to any two calls executed during the same query evaluation.
The result of the document function can be explained
            in terms of an internal primitive function
            one-doc, which takes a requested URI and a
            base URI as arguments and returns a node sequence as
            its result. The result of the document function is the
            union of the node sequences obtained by calling
            one-doc once for each member of
            $srcval1.
The one-doc function retrieves a
            document using a request URI R and a base URI B.
For a member of $srcval1 that is a node
            N, the one-doc function is called with the
            string-value of N as the request URI and the effective
            base URI of $srcval2 if
            $srcval2 is supplied. If
            srcval2 is not supplied, the base URI is
            the effective base URI of N.
For a member of $srcval1 that is a
            simple value, the one-doc function is
            called using a request URI obtained by converting the
            simple value to a string as if by using the string
            function, and the effective base URI of
            $srcval2 if $srcval2 is
            supplied. If srvcal2 is not supplied, the
            base URI is obtained from the static context.
The effective base URI of a node is defined to be the base URI of the node (as defined in [XQuery 1.0 and XPath 2.0 Data Model] in the case of document nodes and element nodes, and the base URI of the parent of the node for any other kind of node. If the node is not a document or element node and has no parent, then an error is raised ("Invalid arguments to document function").
The internal one-doc function operates
            as follows.
The resource identified by the URI is retrieved. The data resulting from the retrieval action is parsed as an XML document and a tree is constructed in accordance with the [XQuery 1.0 and XPath 2.0 Data Model]. An error retrieving the resource is classed as a dynamic error. In such cases, either an error is raised ("Error retrieving resource"), or the processor must recover by returning an empty sequence. One possible kind of retrieval error is that the implementation does not support the URI scheme used by the URI. An implementation is not required to support any particular URI schemes. The documentation for an implementation should specify which URI schemes the implementation supports.
If the URI reference does not contain a fragment identifier, then the document node of the document is returned. If the URI reference does contain a fragment identifier, the function returns a node sequence containing the nodes in the tree identified by the fragment identifier of the URI reference. The semantics of the fragment identifier are dependent on the media type of the result of retrieving the URI. An error in processing the fragment identifier is classed as a dynamic error. In such cases, then an error is raised ("Error processing fragment identifier"), or the processor must recover by returning an empty sequence. Possible errors include:
The fragment identifier identifies something that cannot be represented by a node sequence (such as a range of characters within a text node).
The implementation does not support fragment identifiers for the media-type of the retrieval result. An implementation is not required to support any particular media types. The documentation for an implementation should specify for which media types the implementation supports fragment identifiers.
The data resulting from the retrieval action is parsed as an XML document regardless of the media type of the retrieval result; if the top-level media type is text, then it is parsed in the same way as if the media type were text/xml; otherwise, it is parsed in the same way as if the media type were application/xml.
xf:collection(string $srcval) =>
                node*
              Takes a string as argument and returns a sequence of
            nodes obtained by casting $srcval to
            anyURI and resolving it. If $srcval is not
            in the lexical space of anyURI or if the value, after
            casting, does not resolve to a collection, then an
            error is raised ("Invalid argument to collection
            function").
The following functions are defined to obtain information from the evaluation context. The context is always defined but may be the empty sequence.
| Function | Meaning | Source | 
|---|---|---|
xf:context-item | 
            Returns the context item. | XPath 1.0 | 
xf:position | 
            Returns the position of the context item within the sequence of items currently being processed. | XPath 1.0 | 
xf:last | 
            Returns the number of items in the sequence of items currently being processed. | XPath 1.0 | 
op:context-document | 
            Returns the source document currently being processed. | XPath 1.0 | 
xf:current-dateTime | 
            Returns the current dateTime. | XPath 1.0 | 
xf:current-date | 
            Returns the current date. | |
xf:current-time | 
            Returns the current time. | 
xf:context-item()
              => item?
            Returns the context item i.e. the item currently being processed. Returns the empty sequence if the context is the empty sequence.
xf:position()
              => unsignedInt?
            Returns an unsignedInt indicating the position of the context item within the sequence of items currently being processed. Returns the empty sequence if the context is the empty sequence.
xf:last()
              => unsignedInt?
            Returns an unsignedInt indicating the number of items in the sequence of items currently being processed. Returns the empty sequence if the context is the empty sequence.
op:context-document()
              => document?
            Returns a document node indicating the source document being processed. If the context document is not specified, then an error is raised ("No context document"). If the context document is the empty sequence, returns the empty sequence. This function backs up the "/" operator.
xf:current-dateTime()
              => dateTime
            Returns the dateTime (with timezone) that is current
          at some time during the evaluation of the XQuery or XPath
          expression in which current-dateTime() is
          executed. All invocations of
          current-dateTime() that are executed during
          the course of a single outermost XQuery or XPath
          expression return the same value. The precise instant
          during that XQuery or Xpath expression's evaluation
          represented by the value of
          current-dateTime() is ·implementation-defined·.
xf:current-date()
              => date
            Returns the date (with timezone) that is current at
          some time during the evaluation of the XQuery or XPath
          expression in which current-date() is
          executed. All invocations of current-date()
          that are executed during the course of a single outermost
          XQuery or XPath expression return the same value. The
          precise instant during that XQuery or Xpath expression's
          evaluation represented by the value of
          current-date() is ·implementation-defined·.
xf:current-time()
              => time
            Returns the date (with timezone) that is current at
          some time during the evaluation of the XQuery or XPath
          expression in which current-date() is
          executed. All invocations of current-date()
          that are executed during the course of a single outermost
          XQuery or XPath expression return the same value. The
          precise instant during that XQuery or Xpath expression's
          evaluation represented by the value of
          current-date() is ·implementation-defined·.
Cast functions and cast operators take an expression as
        their argument and return a value of a given type. There
        are two ways of converting values to a given type:
        constructor functions, and cast expressions. Constructor
        functions are provided only for conversion to the built-in
        types defined in [XML Schema Part 2:
        Datatypes], whereas the cast expression syntax can also
        be used for conversion to a user-defined (derived) type.
        The name of a constructor function is the same as the name
        of the [XML Schema Part 2:
        Datatypes] built-in type that is the target for the
        conversion, and the semantics are exactly the same as for a
        cast expression: for example,
        xs:date("2002-01-01") means exactly the same
        as cast as xs:date("2002-01-01").
This specification starts by defining casting between the 19 primitive types defined in [XML Schema Part 2: Datatypes]. The type conversions that are supported are indicated in the table below. In this table, there is a row for each primitive type with that type as the source of the conversion and there is a column for each primitive type as the target of the conversion. The intersections of rows and columns contain one of three characters: "Y" indicates that a conversion from values of the type to which the row applies to the type to which the column applies is supported; "N" indicates that there are no supported conversions from values of the type to which the row applies to the type to which the column applies; and "M" indicates that a conversion from values of the type to which the row applies to the type to which the column applies may be supported, subject to restrictions discussed in this section.
Where the argument to a cast is a literal, the result of the function may be evaluated statically; if an error is encountered during such evaluation, it may be reported as a static error.
The casting described in Sections 16.7 Casting to numeric
        types through 16.11 Casting
        to anyURI and NOTATION is confined to casts in
        which the source data type and the target data type are
        derived from different primitive types, and neither the
        source data type nor the target data type are
        string. The reason is that casting from a
        value of some derived type to its primitive type is merely
        a simple promotion of the value (properly described as
        modification its type annotation, usually requiring no
        value manipulations), and casting from a primitive type to
        one of its derived types requires only application of the
        facets involved in the restriction. Thus, to cast between
        types derived from a value of a given simple derived type
        involves, at most, promoting up to its primitive type and
        then restricting down to the target derived type. As a
        result, the rules for casting define here need only discuss
        performing casts where the primitive types are
        different.
In the following table, the columns and rows are identified by short codes that identify simple types as follows:
aURI = anyURI
b64 = base64Binary
bool = boolean
dat = date
Day = gDay
dbl = double
dec = decimal
dT = dateTime
dur = duration
flt = float
hxB = hexBinary
MD = gMonthDay
Mon = gMonth
NOT = NOTATION
QN = Qname
str = string
tim = time
YM = gYearMonth
Yr = gYear
In the following table, the notation "S\T" indicates that the source ("S") of the conversion is indicated in the column below the notation and that the target ("T") is indicated in the row to the right of the notation.
The following table covers casting from primitive types to primitive types.
| S\T | str | flt | dbl | dec | dur | dT | tim | dat | YM | Yr | MD | Day | Mon | Bool | b64 | hxB | aURI | QN | NOT | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| str | Y | M | M | M | M | M | M | M | M | M | M | M | M | M | N | N | M | N | M | 
| flt | Y | Y | Y | M | N | N | N | N | N | N | N | N | N | M | N | N | N | N | N | 
| dbl | Y | Y | Y | M | N | N | N | N | N | N | N | N | N | M | N | N | N | N | N | 
| dec | Y | Y | Y | Y | N | N | N | N | N | N | N | N | N | M | N | N | N | N | N | 
| dur | Y | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | 
| dT | Y | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | 
| tim | Y | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | N | N | 
| dat | Y | N | N | N | N | N | N | Y | Y | N | N | N | N | N | N | N | N | N | N | 
| YM | Y | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | 
| Yr | Y | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | 
| MD | Y | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | 
| Day | Y | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | 
| Mon | Y | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | 
| bool | Y | Y | Y | Y | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | 
| b64 | Y | N | N | N | N | N | N | N | N | N | N | N | N | M | Y | N | N | N | N | 
| hxB | Y | M | M | M | N | N | N | N | N | N | N | N | N | M | N | Y | N | N | N | 
| aURI | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | 
| QN | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | 
| NOT | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | 
It is possible to cast a value of any type to a type
          from which its original type is derived (directly or
          indirectly) by restriction. This includes the primitive
          type from which the original type is ultimately derived.
          For example, it is possible to cast an
          unsignedShort to an
          unsignedInt, an unsignedLong,
          an unsignedInteger, an integer,
          or a decimal. Since the value space of the
          original type is a subset of the value space of the
          target type, such a cast is always successful. The result
          will have same value as the original, but it will have a
          new type annotation.
There are three circumstances in which it is possible to cast a value to an unrelated derived type. These are:
When the supplied value is an instance of a type that is derived by restriction from the target type: this is described in section 16.2 Casting from derived types to primitive types above.
When the supplied value is a string, or an instance of anySimpleType: this is described in section 16.4 Casting from strings below.
When the supplied value is of a type derived by restriction from the same primitive type as the target type: this is described in 16.5 Casting within a branch of the type hierarchy below.
When the supplied value is a string, or
          an instance of anySimpleType, it is treated
          as being a value in the lexical space of the target type.
          The target type may be either a primitive type or a
          derived type; if it is derived, it may be derived either
          by restriction, by list, or by union. The rules are
          exactly the same as those applied by [XML Schema Part 2: Datatypes]. If
          the target data type is a list type, the supplied value
          is first tokenized using whitespace as the token
          separator. If any of the resulting tokens is not a valid
          value in the lexical space of the target type, then an
          error is raised ("Invalid lexical value").
For example, cast as
          xsd:unsignedInteger("13") returns the
          unsignedInteger 13. This could also be
          written xsd:unsignedInteger("13").
Similarly, cast as my:list-of-shoe-sizes("8 9
          9.5 10 11") (where
          my:list-of-shoe-sizes is derived by list
          from my:shoe-size) splits the supplied
          string at white-space boundaries and treats each of the
          five strings as a value in the lexical space of
          my:shoe-size. Assuming these values conform
          with the facets defined for my:shoe-size,
          the result is a sequence of five items, each of which has
          type my:shoe-size.
It is possible to cast a value to a target type if the
          type of the source value and the target type are both
          derived by restriction (directly or indirectly) from the
          same primitive type, provided that the supplied value
          conforms to the constraints implied by the facets of the
          target type. For example an instance of
          xs:byte can be cast to
          xs:unsignedShort, provided the value is not
          negative. This includes the case where the target type is
          derived from the type of the supplied value as well as
          the case where both derive from a common supertype.
If the value does not conform to the facets defined by the target type, then an error is raised ("Value does not conform to facets"). In the case of the pattern facet (which applies to the lexical space rather than the value space), the pattern is tested against the canonical lexical representation of the value, as defined by the source data type (or the result of casting the value to a string, in the case of types that have no canonical lexical representation).
Note: this will cause casts to fail if the pattern
          excludes the canonical lexical representation. For
          example, if the type my:currency is defined
          as a restriction of xs:decimal with a
          pattern that requires two digits after the decimal point,
          casting of an integer to my:currency will
          always fail, because the canonical representation of an
          integer does not conform to this pattern.
Casting is permitted from any primitive type to the
          primitive type string.
Note:
It has not been fully determined how, or if, QName values are cast to string. This issue is related to other namespace issues and will be resolved concurrently with those issues. See , for example.
When a value of any simple type is cast to
              string, the derivation of the
              string value TV depends on the
              source type ST and on the source value
              SV, as follows.
If ST is string,
                  TV is SV.
If ST is float,
                  double, or decimal then
                  TV is the canonical representation of
                  SV, as defined by [XML Schema Part 2:
                  Datatypes].
If ST is duration, then
                  TV is the lexical representation of
                  SV, as defined by [XML Schema Part 2:
                  Datatypes], in which each integer and decimal
                  component is expressed in its canonical
                  representation.
If ST is dateTime or
                  time, then TV is the
                  canonical representation of SV, as
                  defined by [XML Schema Part 2:
                  Datatypes].
If ST is date,
                  gYearMonth, gYear,
                  gMonthDay, gDay, or
                  gMonth, then TV is the
                  lexical representation of SV, as defined
                  by [XML Schema Part 2:
                  Datatypes].
If ST is boolean, then
                  TV is "true" if SV is true and
                  "false" if SV is false.
If ST is hexBinary, then
                  TV is the canonical representation of
                  SV, as defined by [XML Schema Part 2:
                  Datatypes].
If ST is anyURI, then
                  TV is the lexical representation of
                  SV, as defined in [XML Schema Part 2:
                  Datatypes], with each space replaced by the
                  sequence "%20".
If ST is NOTATION, then
                  TV is SV.
As specified in the preceding table, conversion from
          various simple types to the various numeric types (that
          is, float, double and
          decimal depends on factors considered
          below.
When a value of any simple type is cast to
              float, the float value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is float, then
                  TV is SV and the conversion is
                  complete.
If ST is double and
                  SV cannot be represented in the value
                  space of float as defined in [XML Schema Part 2:
                  Datatypes], then the cast returns NaN..
If ST is double and
                  SV can be represented in the value space
                  of float as defined in [XML Schema Part 2:
                  Datatypes], then TV is SV
                  and the conversion is complete.
If ST is decimal or a
                  type derived from decimal, then
                  TV is xs:float(cast as
                  string( SV )) and
                  the conversion is complete.
If ST is boolean, SV is
                  converted to 1.0 if SV is
                  1 or true and
                  0.0 if SV is 0 or
                  false and the conversion is
                  complete.
SV is converted to an intermediate
                  value IV of type token.
If the value of xf:upper-case(
                  IV ) is INF,
                  -INF, or NAN, then
                  TV is positive infinity, negative
                  infinity, or not-a-number, respectively, and the
                  conversion is complete.
If IV does not match the lexical
                  structure of NumericLiteral as
                  defined in [XQuery 1.0: An XML
                  Query Language], then an error is raised
                  ("Invalid lexical value").
Otherwise, let NL be a
                  NumericLiteral comprising the same
                  sequence of characters as IV.
                  TV is xs:float( NL
                  ).
When a value of any simple type is cast to
              double, the double value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is double, then
                  TV is SV and the conversion is
                  complete.
If ST is float or
                  decimal or types derived from them,
                  then TV is xs:double(cast as
                  string( SV )) and
                  the conversion is complete.
If ST is boolean, SV is
                  converted to 1.0 if SV is
                  1 or true and
                  0.0 if SV is 0 or
                  false and the conversion is
                  complete.
SV is converted to an intermediate
                  value IV of type token.
If the value of xf:upper-case(
                  IV ) is INF,
                  -INF, or NAN, then
                  TV is positive infinity, negative
                  infinity, or not-a-number, respectively, and the
                  conversion is complete.
If IV does not match the lexical
                  structure of NumericLiteral as
                  defined in [XQuery 1.0: An XML
                  Query Language], then an error is raised
                  ("Invalid lexical value").
Otherwise, let NL be a
                  NumericLiteral comprising the same
                  sequence of characters as IV.
                  TV is xs:double(
                  NL ).
When a value of any simple type is cast to
              decimal, the decimal value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is decimal, or a
                  type derived from decimal, then
                  TV is decimal(cast as
                  string( SV )) and
                  the conversion is complete.
If ST is float or
                  double, then TV is
                  decimal(cast as string(xf:round(
                  SV ))) and the conversion
                  is complete.
If ST is boolean, SV is
                  converted to 1.0 if SV is
                  1 or true and
                  0.0 if SV is 0 or
                  false and the conversion is
                  complete.
SV is converted to an intermediate
                  value IV of type token.
If IV does not match the lexical
                  structure of NumericLiteral as
                  defined in [XQuery 1.0: An XML
                  Query Language], then an error is raised
                  ("Invalid lexical value").
Otherwise, let NL be a
                  NumericLiteral comprising the same
                  sequence of characters as IV.
                  TV is decimal(cast as
                  string(xf:round( NL
                  ))).
Conversion from primitive types to duration and date and time types depends on factors considered below.
When a value of any primitive type is cast to
              duration, the duration
              value TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is duration, then
                  TV is SV.
If ST is string or a
                  type derived from string, then
                  TV is xs:duration(cast as
                  string( SV)).
When a value of any primitive type is cast to
              dateTime, time,
              date, gYearMonth,
              gYear, gMonthDay,
              gDay, or gMonth, let
              CYR be cast as string( xf:get-Year(
              xf:currentDateTime() ) ), let CMO be
              cast as string( xf:get-month(
              xf:currentDateTime() ) ), and let CDA
              be cast as string( xf:get-day(
              xf:currentDateTime() ) ).
When a value of any primitive type is cast to
              dateTime, the dateTime
              value TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime, then
                  TV is SV.
If ST is time, then let
                  SHR be cast as string(
                  xf:get-hour( SV ) ),
                  let SMI be cast as string(
                  xf:get-minute( SV )
                  ), and let SSE be cast as
                  string( xf:get-second( SV )
                  ); TV is xs:dateTime(
                  xf:concat( CYR ,
                  '-', CMO , '-',
                  CDA , 'T', SHR
                  , ':', SMI ,
                  ':', SSE ) ).
If ST is date, then let
                  SYR be cast as string(
                  xf:get-Year( SV ) ),
                  let SMO be cast as string(
                  xf:get-month( SV )
                  ), and let SDA be cast as
                  string( xf:get-day( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SYR ,
                  '-', SMO , '-',
                  SDA , 'T00:00:00') ).
If ST is gYearMonth,
                  then let SYR be cast as string(
                  xf:get-Year( SV ) )
                  and let SMO be cast as string(
                  xf:get-month( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SYR ,
                  '-', SMO , '-01T00:00:00')
                  ).
If ST is gYear, then let
                  SYR be cast as string(
                  xf:get-Year( SV ) );
                  TV is xs:dateTime(
                  xf:concat( SYR ,
                  '-01-01T00:00:00') ).
If ST is gMonthDay, then
                  let SMO be cast as string(
                  xf:get-month( SV ) )
                  and let SDA be cast as string(
                  xf:get-day( SV ) );
                  TV is xs:dateTime(
                  xf:concat( CYR ,
                  '-', SMO , '-',
                  SDA , 'T00:00:00') ).
If ST is gDay, then let
                  SDA be cast as string(
                  SV ); TV is
                  xs:dateTime( xf:concat( CYR
                  , '-', CMO ,
                  '-', SDA , 'T00:00:00')
                  ).
If ST is gMonth, then
                  let SMO be cast as string(
                  SV ); TV is
                  xs:dateTime( xf:concat( CYR
                  , '-', SMO ,
                  '-01T00:00:00') ).
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for dateTime as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  dateTime as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:dateTime( SV
                  ).
When a value of any primitive type is cast to
              time, the time value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is time, then
                  TV is SV.
If ST is dateTime, then
                  TV is xs:time( xf:concat( cast as
                  string( xf:get-hour( SV )
                  ), ':', cast as string( xf:get-minute(
                  SV ) ), ':', cast as string(
                  xf:get-second( SV ) ) )
                  ).
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  time as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:time( SV
                  ).
When a value of any primitive type is cast to
              date, the date value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime, then
                  let SYR be cast as string(
                  xf:get-Year( SV ) ),
                  let SMO be cast as string(
                  xf:get-month( SV )
                  ), and let SDA be cast as
                  string( xf:get-day( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SYR ,
                  '-', SMO , '-',
                  SDA ) ).
If ST is date, then
                  TV is SV.
If ST is gYearMonth,
                  then let SYR be cast as string(
                  xf:get-Year( SV ) )
                  and let SMO be cast as
                  string(xf:get-month( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SYR ,
                  '-', SMO , '-01')
                  ).
If ST is gYear, then let
                  SYR be cast as string(
                  xf:get-Year( SV ) );
                  TV is xs:dateTime(
                  xf:concat( SYR , '-01-01')
                  ).
If ST is gMonthDay, then
                  let SMO be cast as string(
                  xf:get-month( SV ) )
                  and let SDA be cast as string(
                  xf:get-day( SV ) );
                  TV is xs:dateTime(
                  xf:concat( CYR ,
                  '-', SMO , '-',
                  SDA ) ).
If ST is gDay, then let
                  SDA be cast as string(
                  SV ); TV is
                  xs:dateTime( xf:concat( CYR
                  , '-', CMO ,
                  '-', SDA ) ).
If ST is gMonth, then
                  let SMO be cast as string (
                  SV ); TV is
                  xs:dateTime( xf:concat( CYR
                  , '-', SMO , '-01')
                  ).
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for date as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  date as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
              gYearMonth, the gYearMonth
              value TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime or
                  date, then let SMO be
                  cast as string( xf:get-month(
                  SV ) ) and let SDA
                  be cast as string( xf:get-day(
                  SV ) ); TV is
                  xs:gYearMonth( xf:concat(
                  SMO , '-', SDA
                  ) ).
If ST is gYearMonth,
                  then TV is SV.
If ST is gYear, then let
                  SYR be cast as string(
                  xf:get-Year( SV ) );
                  TV is xs:dateTime(
                  xf:concat( SYR , '-01')
                  ).
If ST is gMonthDay or
                  gMonth, then let SMO be
                  cast as string( xf:get-month(
                  SV ) ); TV is
                  xs:dateTime( xf:concat( CYR
                  , '-', SMO )
                  ).
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for gYearMonth as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  gYearMonth as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
              gYear, the gYear value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime,
                  date, or gYearMonththen
                  let SYR be cast as string(
                  xf:get-Year( SV ) );
                  TV is xs:gYear(
                  SYR ).
If ST is gYearMonth,
                  then TV is SV.
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for gYear as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  gYear as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
              gMonthDay, the gMonthDay
              value TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime or
                  date, then let SMO be
                  cast as string( xf:get-month(
                  SV ) ) and let SDA
                  be cast as string( xf:get-day(
                  SV ) ); TV is
                  xs:gYearMonth( xf:concat(
                  SMO , '-', SDA
                  ) ).
If ST is gYearMonth,
                  then let SMO be cast as string(
                  xf:get-month( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SMO , '-01')
                  ).
If ST is gMonthDay, then
                  TV is SV.
If ST is gDay, then let
                  SDA be cast as string(
                  xf:get-day( SV ) );
                  TV is xs:dateTime(
                  xf:concat( CMO ,
                  CDA ) ).
If ST is gMonth, then
                  let SMO be cast as string(
                  xf:get-month( SV )
                  ); TV is xs:dateTime(
                  xf:concat( SMO , '-01')
                  ).
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for gMonthDay as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  gMonthDay as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
              gDay, the gDay value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime,
                  date, or gMonthDay,
                  then let SDA be cast as string(
                  xf:get-day( SV ) );
                  TV is xs:gDay( SDA
                  ).
If ST is gDay, then
                  TV is SV.
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for gDay as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  gDay as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
              gMonth, the gMonth value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is dateTime,
                  date, gYearMonth, or
                  gMonthDay, then let SMO be
                  cast as string( xf:get-month(
                  SV ) ); TV is
                  xs:gMonth( SMO
                  ).
If ST is gMonth, then
                  TV is SV.
If ST is string or a
                  type derived from string and
                  SV is not a valid lexical representation
                  for gMonth as specified in [XML Schema Part 2:
                  Datatypes], then an error is raised ("Invalid
                  lexical value").
If ST is string or a
                  type derived from string and
                  SV is a valid lexical representation for
                  gMonth as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  xs:date( SV
                  ).
When a value of any primitive type is cast to
          boolean, the boolean value
          TV is derived from the source type ST
          and the source value SV as follows:
If ST is string and xf:upper-case(
              SV ) is " TRUE "
              or " 1 ", then TV is
              true; if ST is
              string and xf:upper-case(
              SV ) is " FALSE "
              or " 0 ", then TV is
              false.
If ST is float,
              double, or decimal and
              SV is 0, +0, -0, or NaN, then TV is
              false.
If ST is float,
              double, or decimal and
              SV is not one of the above values, then
              TV is true.
If ST is boolean, then
              TV is SV.
If ST is base64Binary or
              hexBinary and SV is "
              1 ", then TV is
              true; if ST is
              base64Binary or hexBinary
              and SV is " 0 ", then
              TV is false.
Otherwise, an error is raised ("Invalid lexical value").
Casting from any other simple type to
          base64Binary and hexBinary is
          not supported.
Casting to anyURI or
          NOTATION is possible only from the same type
          or possibly from string.
When a value of any primitive type is cast to
              anyURI, the anyURI value
              TV is derived from the source type
              ST and the source value SV as
              follows:
If ST is string or
                  normalizedString and SV
                  conforms to the format of a Uniform Resource
                  Identifier Reference as specified in [XML Schema Part 2:
                  Datatypes], then TV is
                  SV.
Otherwise, an error is raised ("Invalid lexical value").
It is not possible to cast values of any other
              type to NOTATION because the validity of
              a NOTATION value is context dependent
              and cannot, in general, be determined.
This appendix summarizes the relationship between certain functions defined in [XPath 1.0] and the corresponding functions defined in this document. The first column of the table provides the signature of functions defined in this document, while the second column provides the signature of the corresponding function in [XPath 1.0]. The third column records issues concerning the relationship between the corresponding functions.
| XQuery 1.0 and XPath 2.0 | XPath 1.0 | Issues | |||||||
|---|---|---|---|---|---|---|---|---|---|
              xf:node-name(node $srcval) =>
                QName?
               | 
            name(node-set?) =>
            string | 
            The XPath 1.0 function is retained to provide compatibility. | |||||||
              xf:string()
                => string
               | 
            string(object) =>
            string | 
            The string representation of double values is not backwards-compatible. When multiple items are supplied, an error is raised ("type exception"), with fall-back of first node, for XPath 1.0 compatibility. | |||||||
              xf:string(item* $srcval) =>
                string
               | 
          |||||||||
              xf:floor(integer? $srcval) =>
                integer?
               | 
            Potential problems with double arguments that are NaN, infinite, or out of range for an integer. | ||||||||
              xf:ceiling(integer? $srcval) =>
                integer?
               | 
            ceiling(number)=>
            number | 
            Potential problems with double arguments that are NaN, infinite, or out of range for an integer. | |||||||
              xf:round(integer? $srcval) =>
                integer?
               | 
            round(number)=>
            number | 
            Potential problems with double arguments that are NaN, infinite, or out of range for an integer. | |||||||
              xf:string(string $srcval) =>
                string
               | 
            string(object?) =>
            string | 
            ||||||||
              xf:concat()
                => string
               | 
            concat(string,
            string, string*) => string | 
            In 2.0 the arguments are optional, which is not really a backward compatibility issue. | |||||||
              xf:concat(string? $op1) => string
               | 
          |||||||||
              xf:concat(string? $op1, string? $op2, ...) =>
                string
               | 
          |||||||||
              xf:starts-with(string? $operand1, string? $operand2) =>
                boolean?
               | 
            starts-with(string,
            string) => boolean | 
            At 1.0 returns false if the first argument is an empty node-set. At 2.0, returns (). | |||||||
              
  | 
          |||||||||
              xf:contains(string? $operand1, string? $operand2) =>
                boolean?
               | 
            contains(string,
            string) => boolean | 
            At 1.0 returns false if the first argument is an empty node-set. At 2.0, returns (). | |||||||
              
  | 
          |||||||||
              xf:substring(string? $sourceString, decimal? $startingLoc) =>
                string?
               | 
            substring(string,
            number, number?) => string | 
            At 1.0 returns "" if the first argument is an empty node-set. At 2.0, returns (). At 1.0 allows the second or third arguments to be the double value Infinity (and there are programming tricks that exploit this). 1.0 also allows argument to be NaN. Also, 2.0 spec does not make it clear how surrogate pairs are handled (only needs a note). | |||||||
              
  | 
          |||||||||
              xf:string-length(integer? $srcval) =>
                integer?
               | 
            
            string-length(string?) => number | 
            Note: 2.0 does not mention if it defaults to the context node converted to a string when the argument is omitted. Also, 2.0 spec does not make it clear how surrogate pairs are handled (only needs a note). | |||||||
              xf:substring-before(string? $operand1, string? $operand2) =>
                string?
               | 
            
            substring-before(string, string) =>
            string | 
            At 1.0 returns "" if the first argument is an empty node-set. At 2.0, returns (). | |||||||
              
  | 
          |||||||||
              xf:substring-after(string? $operand1, string? $operand2) =>
                string?
               | 
            
            substring-after(string, string) =>
            string | 
            At 1.0 returns "" if the first argument is an empty node-set. At 2.0, returns (). | |||||||
              
  | 
          |||||||||
              xf:normalize-space(string? $srcval) =>
                string?
               | 
            
            normalize-space(string?) => string | 
            1.0 optional argument vs. 2.0 required argument. Note: 2.0 does not mention if it defaults to the context node converted to a string when the argument is omitted. | |||||||
              
  | 
            translate(string,
            string, string)=> string | 
            At 1.0 returns "" if the first argument is an empty node-set. At 2.0, returns (). Also, 2.0 spec does not make it clear how surrogate pairs are handled (only needs a note). | |||||||
              xf:true()
                => boolean
               | 
            true() =>
            boolean | 
            ||||||||
              xf:false()
                => boolean
               | 
            false() =>
            boolean | 
            ||||||||
              xf:not(item*? $srcval) =>
                boolean
               | 
            not(boolean) =>
            boolean | 
            In 2.0 the strings "0" and "false" are treated as false, while in 1.0, they were treated as true. | |||||||
              xf:namespace-uri()
                => string
               | 
            
            namespace-uri(node-set?) => string | 
            2.0 The required type for this function is node. If fallback conversion is enabled and $srcval is a node sequence, the first node in the sequence is used as the argument. 1.0 Not an issue if fallback is enabled. | |||||||
              xf:namespace-uri(string* $srcval) =>
                string
               | 
          |||||||||
              xf:name()
                => string
               | 
            name(node-set?) =>
            string | 
            ||||||||
              xf:name(string* $srcval) =>
                string
               | 
          |||||||||
              xf:local-name()
                => string
               | 
            local-name(node-set?)
            => string | 
            Should 2.0 be node*? | |||||||
              xf:local-name(node $srcval) =>
                string
               | 
          |||||||||
              xf:number()
                => anySimpleType
               | 
            number(object?) =>
            number | 
            2.0 Returns the error value instead of NaN. 2.0 No longer accepts any object, but takes a node or the context node when a node isn't supplied. 2.0 "Other" types are now errors. | |||||||
              xf:number(node $srcval) =>
                anySimpleType
               | 
          |||||||||
              xf:lang(string $testlang) =>
                boolean
               | 
            lang(strong) =>
            boolean | 
            2.0 If $srcval is a sequence containing more than one item, an error is raised (type exception). 1.0 Takes first node in a node-set. 2.0 If this is an untyped node, an error is raised (type exception); otherwise, its typed-value is accessed. The value is then converted to boolean. 1.0 Nodes are not typed. | |||||||
              op:concatenate(item*? $seq1, item*? $seq2) => item*?
               | 
            concat (string,
            string, string*) => string | 
            ||||||||
              xf:count(item*? $srcval) =>
                unsignedInt
               | 
            count(node-set) =>
            number | 
            ||||||||
              xf:sum(item*? $srcval) =>
                double
               | 
            sum(node-set) =>
            number | 
            2.0 returns error value if sequence contains anything not a number. 1.0 returns NaN. | |||||||
              xf:id(IDREF*? $srcval) =>
                elementNode*?
               | 
            id(object) =>
            node-set | 
            See [Issue 168: For compatibility with the XPath 1.0 function of the same name, xf:id() should accept a list of strings.]. | |||||||
              xf:document(anyURI*? $srcval1, node*? $srcval2) =>
                node*?
               | 
            document(object,
            node-set?) => node-set | 
            1.0 allows a string or node-set as argument; the 2.0 spec is more restrictive. Fallback conversions do not currently handle this. | |||||||
              xf:position()
                => unsignedInt
               | 
            
            position() | 
            ||||||||
              xf:last()
                => unsignedInt
               | 
            last() =>
            number | 
            
This appendix contains the current issues related to the operators specification.
| Originator: | Operators Task Force F2F 2001-03-21 | 
| Locus: | Syntax | 
A function signature like "make_string(string)" is misleading since it implies that the argument might have to be of most specific type "string" as opposed to IDREF. This document must make it clear that other types (e.g., subtypes of "string", or derived types derived from "string", such as "token" are acceptable. Question arose about whether there should also be a version of "make-string" with a "number" argument, as opposed (or in addition to) to explicit and/or implicit "cast" functions. The intent is to have "make-string(string)" only for symmetry, not to allow for subtypes.
Resolution:
None recorded.
This issue is not referenced!
| Originator: | Operators Task Force F2F 2001-03-21 | 
| Locus: | Syntax | 
Many uses of the word "character" in this specification would probably be better if changed to "codepoint" to make it clear precisely what Unicode concept is meant.
Resolution:
None recorded.
This issue occurs in 6.3 Functions on String Values
| Originator: | Operators Task Force F2F 2001-03-21 | 
| Locus: | Syntax | 
What is the precise type returned by various functions? Is the specific type of the argument the returned type, or does it get "upcast" to "string"? Some operations might not be able to keep the most specific type (e.g., SUBSTRING(NCNAME,2) may not be a NCNAME!)
Resolution:
None recorded.
This issue occurs in 6.3 Functions on String Values
| Originator: | Operators Task Force F2F 2001-03-21 | 
| Locus: | Syntax | 
Currently, the specification uses the phrase "...returns a copy" in several locations. That phrase is not appropriate and the wording should be changed to accurately describe the intended semantics.
Resolution:
None recorded.
This issue occurs in 6.3 Functions on String Values
| Originator: | Michael Sperberg-McQueen | 
| Locus: | Syntax | 
In a presentation at the July, 2001 F2F, it was said that collations would be referred to by URI references. Michael Rys said one rationale is to allow relative URI(-reference)s so one can refer to "French" rather than http://www.example.com/i18n/collation-sequences/case-sensitive/French, and so on. There may be negative impacts on the interoperability results caused by allowing relative URI referneces for this function. It is tempting to suggest requiring collation names to be absolute URIs without fragment identifiers. If brevity is really important, perhaps we should invent a way to assign short names to collations. See, also, issue 70.
Issue resulted from e-mail: Michael Sperberg-McQueen (member-only message)
Resolution:
None recorded.
This issue occurs in 6.2 Equality and Comparison of Strings
| Originator: | Anders Berglund | 
| Locus: | Syntax | 
The requirement is to have an underlying design that permits (either in version 1.0, or at least permits a natural extension to) supporting:
Converting a "date" to a string in a non-Gregorian calendar.
Converting a string, in an appropriate format for a non Gregorian calendar, to a "date".
Comparisons of "dates" where the XML has these expressed in non-Gregorian calendar(s).
The range of supported calendars should probably be left to the implementation.
A possible design approach could be to:
Keep the schema/ISO-8601 date as the "hub" datatype.
Change some of the existing constructor functions by adding a "calendar" parameter, which would default to Gregorian.
Add some "date" to string functions for presenting non-Gregorian calendar dates.
A comparison of, say, two BE years would be achieved by
-- Year("2544", "BE") > Year("2540", "BE")
Naturally there is no requirement that the two calendars match, so a comparison
-- Year("2544", "BE") > Year("1374", "AH")
would be perfectly reasonable.
There are some issues that need solving/clear definition. These include:
What to do if the calendars do not match, for example a year in a lunar calendar (where a year is shorter than a Gregorian year) typically corresponds to two Gregorian years and arithmetic can become very interesting and certain functions may well need to be changed to accomodate this. This applies to calendars in use today.
Should country and date variations be taken into account? For example in some countries using the Julian calendar the year started September 1st (many of these countries changed it later to January 1st). This applies to "historic" dates.
Should "calendar change over" effects be taken into account? For example if a country had a "Gregorian April" with more than 30 days the year a switch from Julian to Gregorian calendar took place should this be reflected in the conversion? This applies to "historic" dates.
Issue resulted from member-only e-mail: Anders Berglund (member-only message) and subsequently amended by(member-only message)
Resolution:
None recorded.
This issue occurs in 8 Functions and Operators on Durations, Dates, and Times
| Originator: | Anders Berglund | 
| Locus: | Syntax | 
The various get-timezone-from-*()
            functions will not really work for those areas that
            still use "sun time" (Saudi Arabia at least used to).
            Thus better to have "get-timezone" return a string and
            e.g. get-timezone-difference-from-GMT give a duration,
            which for sun time would vary.
Issue resulted from e-mail: Anders Berglund (member-only message)
Resolution:
None recorded.
This issue is not referenced!
| Originator: | Michael Kay | 
| Locus: | Syntax | 
We need to specify which aspects of the newly constructed node are the same as the original. E.g. does it have the same name? string-value? namespaces? parent? children? This is the only function in this document with side-effects, so it needs special care. How does it relate to the node-construction functions defined in the data model?
Issue resulted from e-mail: Michael Kay (member-only message)
Resolution:
None recorded.
This issue occurs in 13.1.10 xf:copy
| Originator: | Michael Kay | 
| Locus: | Syntax | 
index-of. Need find-by-value and find-by-identity. Currently index-of takes a sequence of nodes *or* valies. Do we need to change this?
Issue resulted from e-mail: Michael Kay (member-only message)
Resolution:
None recorded.
This issue occurs in 14.2 Functions and Operators on Sequences
| Originator: | Michael Kay | 
| Locus: | Syntax | 
reverse-sort() looks like a composite function that could and should be defined in terms of reverse() and sort(): so replace it with a new primitive function reverse().
If there were an xf:reverse() function, would xf:reverse(xf:sort(x,y)) = xf:reverse-sort(x,y)?
Issue resulted from e-mail: Michael Kay (member-only message)
Resolution:
Sort and reverse-sort are removed but there is still no reverse() function.
This issue is not referenced!
| Originator: | Michael Kay (member-only message). | 
| Locus: | Syntax | 
Need a simple function to sort a sequence in document order (equivalent to union( (), $x )). See also item 20 in member-only e-mail from Don Chamberlin: http://lists.w3.org/Archives/Member/w3c-xml-query-wg/2001Aug/0216.html
Resolution:
None recorded.
This issue occurs in 14.2 Functions and Operators on Sequences,
| Originator: | Andrew Eisenberg | 
| Locus: | Syntax | 
I believe that we should have an xf:compare-between function (analogous to SQL's BETWEEN predicate, allowing quick determination of whether one value lies between two other values).
Issue resulted from e-mail: Andrew Eisenberg (member-only message)
Resolution:
None recorded.
This issue occurs in 6.2 Equality and Comparison of Strings
| Originator: | Mary Fernandez | 
| Locus: | Syntax | 
Jerome and I are working on the mapping from XQuery to the core. We want to know whether there should be any operators defined on individual characters or whether all operators are on strings. At a minimum, we think we need a constructor that takes an individual character and returns a string.
Issue resulted from e-mail: Mary Fernandez (member-only message)
Resolution:
None recorded.
This issue is not referenced!
| Originator: | Steve Tolkin | 
| Locus: | Syntax | 
The xf:numeric-mod()
            function, the div operator, and others do
            not specify what the required number of digits of
            precision is in the result.
Resolution:
The resolution depends on (1)how many digits Schema supports for decimals, and (2)what Functions and Operators does about overflow.
This issue occurs in 5.4 Functions on Numeric Values
| Originator: | Steve Tolkin | 
| Locus: | Syntax | 
This document must properly align with [XQuery 1.0 and XPath 2.0 Data Model] when dealing with node sets (which are defined in [XPath 1.0]), lists, and sequences. The current wording in this document is sometimes confused about the distinctions.
Resolution:
This issue occurs in 14 Functions and Operators on Sequences
| Originator: | Steve Tolkin | 
| Locus: | Syntax | 
The tables would be much more useful if these names grouped by "family" (e.g., all numeric types started with the letter "n", all date and time types with "d", string-like types with "s", and binary types with "b"). (Of course, boolean could go either in with the numeric types or in with the binary types.) Then the tables could be sorted alphabetically. There is already a system: the types cast to in the next few sections.
Resolution:
This issue is not referenced!
| Originator: | Steve Tolkin | 
| Locus: | Syntax | 
The current definition of casting to
            token states that all line feed codes and
            all tab characters are removed, after which leading and
            trailing spaces are deleted and multiple spaces are
            replaced with a single space. Shouldn't line feed codes
            and tabs be converted to spaces instead of simply
            deleted?
Resolution:
This issue is not referenced!
| Originator: | Phil Wadler (member-only message) | 
| Locus: | Syntax | 
Functions with AnyType in the return are problematic for two reasons. To be concrete, I discuss the following.
-- xf:item-at(anyType* $seqParam, decimal $posParam) => anyType
(1) Note that the types anyType* and anyType are equivalent, which suggests that the typing here is not quite right. We should define
-- define group AnyItem = AnyElement | AnyAttribute | AnySimpleType
and then give the above the type
-- xf:item-at(anyItem* $seqParam, decimal $posParam) => anyItem
(2) Even having made the above change, the type is too broad to be useful, and one will almost always have to cast the result of calling xf:item-at (and similarly for other functions with anyItem or anyType in the result).
Instead, we should allow parametric polymorphism when specifying the signatures of built-in functions.
-- xf:item-at($anyItem* $seqParam, decimal $posParam) => $anyItem
Here $anyItem is a type variable which ranges over any group $anyItem such that $anyItem <: AnyItem. (Recall that s <: t if the extent of type s is a subset of the extent of type t, where the extent of a type is the set of values that have that type.)
Here are two examples of functions written with the current signature.
-- define function second-integer (integer* $integer-sequence) integer { treat as integer (xf:item($integer-sequence, 2)) }
-- define function third-book (Book* $book-sequence) book { treat as Book (xf:item($book-sequence, 3)) }
Here are two examples of functions that would type check under this scheme.
-- define function second-integer (integer* $integer-sequence) integer { xf:item($integer-sequence, 2) }
-- define function third-book (Book* $book-sequence) book { xf:item($book-sequence, 3) }
The definitions are easier to write and more efficient to execute (since no "treat as" needs to check the structure of the result).
Parametric polymorphism would also be useful for user-defined functions, it were clear how to define it for user-defined functions in general. But at the very least, we should allow parametric polymorphism for the built-in functions defined in the functions and operators document.
Resolution:
This issue occurs in 14 Functions and Operators on Sequences
| Originator: | Norm Walsh (member-only message) | 
| Locus: | Syntax | 
When does it make sense for a function to return a string that is in a form other than some Unicode normalized form?
Resolution:
This issue occurs in 6.3 Functions on String Values
| Originator: | Norm Walsh (member-only message) | 
| Locus: | Syntax | 
Some sort of (defaulted) calendar context is required for all these functions to allow for future support of non-Gregorian calendars.
Resolution:
This issue occurs in 8 Functions and Operators on Durations, Dates, and Times
| Originator: | Norm Walsh (member-only message) | 
| Locus: | Syntax | 
"...does not contain a timezone, the result is the empty sequence" should be "...does not contain a timezone, the result is the empty string". Whatever we do, the result should be consistent with other such decisions e.g. what does the name accessor return if the node has no name.
Resolution:
This issue occurs in 8.4.13 xf:get-timezone-from-dateTime
| Originator: | Don Chamberlin (member-only message) | 
| Locus: | Syntax | 
string(node) contains the XPath 1.0 definition of the string() function. This definition is based on the type system of XPath 1.0, which has only four types, and it should be reconsidered for XQuery. For example, the definition says that a sequence is converted to a string by returning the string-value of the first item in the sequence. This conflicts with our general policy of raising an error if a scalar function is called with a sequence of length greater than one.
Resolution:
This issue is not referenced!
| Originator: | Don Chamberlin (member-only message) | 
| Locus: | Syntax | 
Section 6.1.2.4 refers to namespace URI's as being "in scope". I do not understand what this means. XQuery has a concept of a scope for namespace prefixes, but as far as I know we have not defined the concept of scope for URI's.
Resolution:
This issue is not referenced!
| Originator: | (member-only message) Minutes of 10/31 Query telcon. | 
| Locus: | Syntax | 
The ? is used in the XML EBNF to indicate that a token is optional. Using the ? after a type name in a function signature to indicate that the empty sequence is allowed uses the ? to indicate a quite different semantic. This may be confusing to users.
Resolution:
This issue occurs in 1.4 Notations
| Originator: | (member-only message) Anders Berglund. | 
| Locus: | Syntax | 
Should we have functions that convert a date/time time value from one timezone to another? If the original value has no timezone, the timezone is added. If it has a timezone, the value is changed to conform to the specified timezone. Perhaps an alternate signature takes a timezone delta.
Resolution:
This issue occurs in 8 Functions and Operators on Durations, Dates, and Times
| Originator: | Andrew Eisenberg. (member-only message) | 
| Locus: | Syntax | 
"Should the functions that return timezones return a duration rather than a string?"
Resolution:
This issue occurs in 8.4.13 xf:get-timezone-from-dateTime
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
What do floor, ceiling and round return? The document says integer. But NaN and the empty sequnce are allowed. Should they return the same type as their operand (without a fractional part)? This allows them to operate on numbers larger than a decimal or integer can accomodate.
See related issue at [Issue 179: What is the appropriate return type for xf:floor, xf:celing, and xf:round?]
Resolution:
This issue occurs in 5.4 Functions on Numeric Values,
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
Should the concat function accept sequences as arguments? Should sequences of strings be flattened? Should string-values be used if the items in the sequence are not strings?
Resolution:
This issue occurs in 6.3.1 xf:concat
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
We need to specify minimum conformance requirements based on resource limitations such as the maximum number of nodes in a sequence, number of text nodes in a document, etc."
Resolution:
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
The document will be made more complete and smaller by having a single extraction function for each date/time datatype that takes as a parameter the name of the bfield it extracts. Break timezone into timezone hours and timezone minutes or extract as) duration.
Resolution:
This issue occurs in 8.4 Component Extraction Functions on Duration, Date and Time Values
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
Should we define a second order distinct function where the comparison function is passed as an argument? Mike Kay to write a proposal.
Resolution:
This issue occurs in 14.2.7 xf:distinct-nodes
| Originator: | (member-only message) Minutes of December 5, 2001 meeting. | 
| Locus: | Syntax | 
The term 'empty content' should be changed or, at least, be carefully defined. Is an attribute node with the value of the empty string empty content?
Resolution:
This issue occurs in 13.2.2 xf:if-empty
| Originator: | Andrew Eisenberg. (member-only message) | 
| Locus: | Syntax | 
boolean-from-string should accept only 1, 0, true, false. This is what XML Schema allows and that's all we need.
Resolution:
This issue is not referenced!
| Originator: | Andrew Eisenberg. (member-only message) | 
| Locus: | Syntax | 
For fractional seconds precision we should choose a limit that matched SQL's TIMESTAMP data type, which is 6 digits of fractional seconds precision.
Resolution:
This issue occurs in 8.1 Duration, Date, and Time Types
| Originator: | Michael Kay (member-only message) | 
| Locus: | Syntax | 
Consider changing the rules for casting to string so they are the same as the rules given here for the string function.
Resolution:
This issue occurs in 2.3 xf:string
| Originator: | Jonathan Robie. (member-only message) | 
| Locus: | Syntax | 
Currently the root() function requires a mandatory node as argument. Should we allow that this argument may be omitted and, if it is omitted, the context item used as argument. If the context item argument is not a node, the function returns the empty sequence or it should return an error.
Resolution:
This issue occurs in 13.1.11 xf:root
| Originator: | Minutes of Cambridge meeting. (member-only message) and subsequent discussion with Michael Kay on xf:id(). | 
| Locus: | Syntax | 
For compatibility with the XPath 1.0 function of the same name, xf:id() should accept a list of strings as argument. A possible resolution is to allow fallback conversions from string to IDREF.
Resolution:
This issue occurs in 14.5.1 xf:id,
| Originator: | Minutes of Functions and Operators Meeting 5/14/2002(member-only message). | 
| Locus: | Syntax | 
For functions like contains() and startsWith(), collations have to have certain properties that aren't necessary for other functions such as compare(), see section 4.3.1
Resolution:
This issue occurs in 6.2 Equality and Comparison of Strings
| Originator: | Minutes of Functions and Operators Meeting 5/14/2002(member-only message). | 
| Locus: | Syntax | 
These functions can be written by the user. Also, they foul up static typing. Do we really need them?
Resolution:
This issue occurs in 13.2.2 xf:if-empty
| Originator: Andrew Eisenberg | Email 2002-04-18 (member-only message) | 
| Locus: | Syntax | 
In the description of some functions it is possible to justify more than one result for an invocation. Rules to disambiguate these situations are necessary.
For example, for the function invocation xf:normalize-unicode
            ( (), "NFANDREW"), there are rules in the
            specification that justify returning either () or
            error. Such ambiguities must be resolved.
Resolution:
This issue is not referenced!
| Originator: Functions and Operators Task Force | Email 2002-06-26 (member-only message) | 
| Locus: | Syntax | 
The expression currently alllows implementations to provide extensions to the regular expression syntax. Some participants would prefer a stricter conformance requirement than this.
Resolution:
This issue occurs in 6.3.15.1 Regular Expression Syntax
| Originator: | Ashok Malhotra (member-only message) | 
| Locus: | Syntax | 
There is precedence in XSLT for not always reporting overflow and underflow resulting from multiplication and division. Should this specification require that such errors always be reported or should it be more permissive, perhaps using XSLT as a guide?
Resolution:
This issue occurs in 5.2 Operators on Numeric Values,
| Originator: | Don Chamberlin (member-only message) | 
| Locus: | Syntax | 
The signatures of the xf:floor and xf:ceiling functions ("integer | double") are not valid SequenceTypes. One of the following should be done: (Solution 1) Make xf:floor, xf:ceiling, and xf:round return integers. You call these functions to get an integer. If the argument is NaN or infinity, an error is raised. (Solution 2) Make these functions return the same type as their argument. The signature and return type should be listed as "numeric", meaning it accepts any numeric type and returns the same type. In this case, an argument of NaN or infinity should still raise an error. (What does the floor of infinity mean??). There appears to be inclination towards Solution 2, but the final decision has not yet been made.
See related issue at [Issue 142: Should floor ceiling and round return the same type as their argument? ].
Resolution:
This issue occurs in 5.4 Functions on Numeric Values,
| Originator: | Functions & Operators editorial team | 
| Locus: | Syntax | 
We now have an xf:error function that is implicitly invoked by our specs and possibly even explicitly by XQuery applications. However, the precise semantics of this function are not at all clear.
Resolution:
This issue occurs in 3 The xf:error Function
| Originator: | Functions & Operators editorial team | 
| Locus: | Syntax | 
The xf:error function can be given an argument whose type is "item". In this document, most of the instances of "an error is raised" are accompanied by a parenthesized statement of what error is to be raised. All such instances, in this and other XQuery/XPath documents should specify an explicit error that is to be raised. All of these errors should be presented in one place (perhaps in an Informative Appendix) for reference. In addition, special markup must be created to ease the process of making error situations consistently specified.
Resolution:
This issue occurs in 3 The xf:error Function
| Originator: | XQuery editorial team | 
| Locus: | Syntax | 
Should the functions xf:if-absent() and xf:if-empty() have specific static typing rules? Should similar functions on sequences that bypass static typing be added---for instance, a function xf:exactly-one() that checks dynamically if the input expression is a singleton sequence, or a function xf:first-item() that returns the first item in any sequence?
Resolution:
This issue occurs in 13.2 xf:if-absent() and xf:if-empty()
This appendix tracks gross changes in the document; it is not intended to provide a fine-grained revision history.
23-Apr-2002 (AM) Rewrote xf:substring() to account for non-integer arguments based on input from Mike Kay and Andrew Eisenberg.
28-Apr-2002 (AM) Added a table of functions before each section with pointers to the functions.
28-Apr-2002 (AM) Closed issue 113; added requisite behavior for +-INF, NaN and +-0 to Numeric Comparison Functions.
06-May-2002 (AM) Changed semantics for xf:boolean so that a sequence with one or more nodes and only nodes returns true. See http://lists.w3.org/Archives/Member/w3c-xsl-query/2002Apr/0168.html. Closed issue 156.
07-May-2002 (AM) Made changes suggested by Don Chamberlin as per agenda of the 5/14/2002 meeting.
07-May-2002 (AM) Reworded xf:deep-equal to address comments from Don Chamberlin.
07-May-2002 (AM) Reworded para in status section re. date/time types to reflect changes below.
07-May-2002 (AM) Added subtract functions for date and time.
07-May-2002 (AM) Added add/remove timezone functions for dateTime, date and time.
07-May-2002 (AM) Added equal functions for gYearMonth, gYear, gMonthDay, gMonth, and gDay.
07-May-2002 (AM) Added greater-than, less-than and equal functions for dateTime, date and time. Closed issues 150 and 151.
20-May-2002 (AM) Reworded xf:document() to take into account mail from David Carlisle and Per Bothner and close XSLT Issue 87.
07-Jun-2002 (JM) Cleaned up the way links to function definitions are generated.
17-Jun-2002 (JM) Implemented decisions made in Redwood Shores
17-Jun-2002 (JM) Corrected "op:item-at" to "xf:item-at"
17-Jun-2002 (JM) Corrected function signature of op:time-less-than
17-Jun-2002 (JM) Created Issue regarding ambiguities when function rules support multiple possible resulting behaviors.
17-Jun-2002 (JM) Created Issue regarding expectations when current-dateTime() (et al) functions are invoked multiple times during a single query or stylesheet.
17-Jun-2002 (JM) Applied current-date and current-time proposal.
17-Jun-2002 (JM) Applied escape-URI proposal.
17-Jun-2002 (JM) Applied revised pattern for dayTimeDuration.
20-Jun-2002 (JM) Removed statement that long, int, short, and byte are (directly) supported numeric types.
12-Jul-2002 (JM) Applied proposal to change timezone handling.
12-Jul-2002 (JM) Added informative appendix explaining relationship of functions defined in this document to their analogs in XPath 1.0
12-Jul-2002 (JM) Applied proposal defining integer arithmetic (treat integer as though it were a primitive type), including support for idiv.
12-Jul-2002 (JM) Simplified casting and replaced existing built-in type constructors with constructor functions that take expressions.
12-Jul-2002 (JM) Added and cleaned up regular expression handling.
12-Jul-2002 (JM) Applied proposal defining how default collations are determined.
12-Jul-2002 (JM) Added clarification that constructor functions take (only) lexical forms defined by XML Schema.
30-Jul-2002 (JM) Applied review comments from Query WG reviewers.
31-Jul-2002 (JM) Added xf:error function and invocations of that function.
                    yearMonthDuration
                    $operand1,
                    yearMonthDuration
                    $operand2) =>
                    boolean
                  
                    yearMonthDuration
                    $operand1,
                    yearMonthDuration
                    $operand2) =>
                    boolean
                  
                    yearMonthDuration $srcval1,
                    yearMonthDuration
                    $srcval2) =>
                    yearMonthDuration
                  
                    yearMonthDuration $srcval1,
                    yearMonthDuration
                    $srcval2) =>
                    yearMonthDuration
                  
                    dayTimeDuration $srcval1,
                    dayTimeDuration
                    $srcval2) =>
                    dayTimeDuration
                  
                    dateTime $srcval1,
                    yearMonthDuration
                    $srcval2) =>
                    dateTime
                  
            yearMonthDuration $srcval1,
            yearMonthDuration $srcval2)
            => yearMonthDuration
          
            dayTimeDuration $srcval1,
            dayTimeDuration $srcval2)
            => dayTimeDuration
          
            dateTime $srcval1,
            yearMonthDuration $srcval2)
            => dateTime
          
            yearMonthDuration $srcval1,
            yearMonthDuration $srcval2)
            => yearMonthDuration
          
            yearMonthDuration $operand1,
            yearMonthDuration $operand2)
            => boolean
          
            yearMonthDuration $operand1,
            yearMonthDuration $operand2)
            => boolean