Another abandoned server code base... this is kind of an ancestor of taskrambler.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

21605 lines
878 KiB

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 1st December 2004), see www.w3.org" />
<title>XQuery 1.0 and XPath 2.0 Functions and Operators</title>
<style type="text/css">
/*<![CDATA[*/
code { font-family: monospace; }
div.constraint,
div.issue,
div.note,
div.notice { margin-left: 2em; }
div.issue
p.title { margin-left: -2em; }
ol.enumar { list-style-type: decimal; }
ol.enumla { list-style-type: lower-alpha; }
ol.enumlr { list-style-type: lower-roman; }
ol.enumua { list-style-type: upper-alpha; }
ol.enumur { list-style-type: upper-roman; }
li p { margin-top: 0.3em;
margin-bottom: 0.3em; }
sup small { font-style: italic;
color: #8F8F8F;
}
div.exampleInner pre { margin-left: 1em;
margin-top: 0em; margin-bottom: 0em}
div.exampleOuter {border: 4px double gray;
margin: 0em; padding: 0em}
div.exampleInner { background-color: #d5dee3;
border-top-width: 4px;
border-top-style: double;
border-top-color: #d3d3d3;
border-bottom-width: 4px;
border-bottom-style: double;
border-bottom-color: #d3d3d3;
padding: 4px; margin: 0em }
div.exampleWrapper { margin: 4px }
div.exampleHeader { font-weight: bold;
margin: 4px}
div.issue { border-bottom-color: black;
border-bottom-style: solid;
border-bottom-width: 1pt;
margin-bottom: 20pt;
}
th.issue-toc-head { border-bottom-color: black;
border-bottom-style: solid;
border-bottom-width: 1pt;
}
div.schemaComp { border: 4px double gray;
margin: 0em 1em;
padding: 0em;
}
div.compHeader { margin: 4px;
font-weight: bold;
}
span.schemaComp { background-color: white;
color: #A52A2A;
}
div.compBody { border-top-width: 4px;
border-top-style: double;
border-top-color: #d3d3d3;
padding: 4px;
margin: 0em;
}
div.exampleInner { background-color: #d5dee3;
color: black;
border-top-width: 4px;
border-top-style: double;
border-top-color: #d3d3d3;
border-bottom-width: 4px;
border-bottom-style: double;
border-bottom-color: #d3d3d3;
padding: 4px;
margin-bottom: 4px;
}
div.issueBody { margin-left: 0.25in;
}
code.function { font-weight: bold;
}
code.return-type { font-style: italic;
}
code.return-varies { font-weight: bold;
font-style: italic;
}
code.type { font-style: italic;
}
code.as { font-style: normal;
}
code.arg {
}
code.strikeout { text-decoration: line-through;
}
p.table.footnote { font-size: 8pt;
}
table.casting { font-size: x-small;
}
table.hierarchy { font-size: x-small;
}
td.castY { background-color: #7FFF7F;
color: black;
}
td.castN { background-color: #FF7F7F;
color: black;
}
td.castM { background-color: white;
color: black;
}
td.castOther { background-color: yellow;
color: black;
}
span.cancast:hover { background-color: #ffa;
color: black;
}
div.protoref { margin-left: 0.5in;
text-indent: -0.5in;
}
/*]]>*/
</style>
<link rel="stylesheet" type="text/css" href=
"http://www.w3.org/StyleSheets/TR/W3C-REC.css" />
</head>
<body>
<div class="head">
<p><a href="http://www.w3.org/"><img src=
"http://www.w3.org/Icons/w3c_home" alt="W3C" height="48" width=
"72" /></a></p>
<h1><a name="title" id="title"></a>XQuery 1.0 and XPath 2.0
Functions and Operators</h1>
<h2><a name="w3c-doctype" id="w3c-doctype"></a>W3C Recommendation
23 January 2007</h2>
<dl>
<dt>This version:</dt>
<dd><a href=
"http://www.w3.org/TR/2007/REC-xpath-functions-20070123/">http://www.w3.org/TR/2007/REC-xpath-functions-20070123/</a></dd>
<dt>Latest version:</dt>
<dd><a href=
"http://www.w3.org/TR/xpath-functions/">http://www.w3.org/TR/xpath-functions/</a></dd>
<dt>Previous version:</dt>
<dd><a href=
"http://www.w3.org/TR/2006/PR-xpath-functions-20061121/">http://www.w3.org/TR/2006/PR-xpath-functions-20061121/</a></dd>
<dt>Editors:</dt>
<dd>Ashok Malhotra (XML Query and XSL WGs), Oracle Corporation
<a href=
"mailto:ashok.malhotra@alum.mit.edu">&lt;ashok.malhotra@alum.mit.edu&gt;</a></dd>
<dd>Jim Melton (XML Query WG), Oracle Corporation <a href=
"mailto:jim.melton@acm.org">&lt;jim.melton@acm.org&gt;</a></dd>
<dd>Norman Walsh (XSL WG), Sun Microsystems <a href=
"mailto:Norman.Walsh@Sun.COM">&lt;Norman.Walsh@Sun.COM&gt;</a></dd>
</dl>
<p>Please refer to the <a href=
"http://www.w3.org/XML/2007/qt-errata/xpath-functions-errata.html"><strong>
errata</strong></a> for this document, which may include some
normative corrections.</p>
<p>See also <a href=
"http://www.w3.org/2003/03/Translations/byTechnology?technology=xpath-functions">
<strong>translations</strong></a>.</p>
<p>This document is also available in these non-normative formats:
<a href=
"http://www.w3.org/TR/2007/REC-xpath-functions-20070123/xpath-functions.xml">
XML</a> and&#160;<a href=
"http://www.w3.org/TR/2007/REC-xpath-functions-20070123/diff-from-20061121.html">
Recent revisions</a>.</p>
<p class="copyright"><a href=
"http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>&#160;©&#160;2007&#160;<a href="http://www.w3.org/">
<acronym title=
"World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href=
"http://www.csail.mit.edu/"><acronym title=
"Massachusetts Institute of Technology">MIT</acronym></a>, <a href=
"http://www.ercim.org/"><acronym title=
"European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved.
W3C <a href=
"http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a href=
"http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a href=
"http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
</div>
<hr />
<div>
<h2><a name="abstract" id="abstract"></a>Abstract</h2>
<p>This document defines constructor functions, operators and
functions on the datatypes defined in <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> and the datatypes
defined in <a href="#xpath-datamodel">[XQuery 1.0 and XPath 2.0
Data Model]</a>. It also discusses functions and operators on nodes
and node sequences as defined in the <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a>. These
functions and operators are defined for use in <a href=
"#xpath20">[XML Path Language (XPath) 2.0]</a>, <a href=
"#xquery">[XQuery 1.0: An XML Query Language]</a> and <a href=
"#xslt20">[XSL Transformations (XSLT) Version 2.0]</a> and other
related XML standards. The signatures and summaries of functions
defined in this document are available at: <a href=
"http://www.w3.org/2005/xpath-functions">http://www.w3.org/2005/xpath-functions</a>.</p>
</div>
<div>
<h2><a name="status" id="status"></a>Status of this Document</h2>
<p><em>This section describes the status of this document at the
time of its publication. Other documents may supersede this
document. A list of current W3C publications and the latest
revision of this technical report can be found in the <a href=
"http://www.w3.org/TR/">W3C technical reports index</a> at
http://www.w3.org/TR/.</em></p>
<p>This is one document in a set of eight documents that have
progressed to Recommendation together (XQuery 1.0, XQueryX 1.0,
XSLT 2.0, Data Model, Functions and Operators, Formal Semantics,
Serialization, XPath 2.0).</p>
<p>This is a <a href=
"http://www.w3.org/2004/02/Process-20040205/tr.html#RecsW3C">Recommendation</a>
of the W3C. It has been jointly developed by the W3C <a href=
"http://www.w3.org/XML/Query">XML Query Working Group</a> and the
W3C <a href="http://www.w3.org/Style/XSL">XSL Working Group</a>,
each of which is part of the <a href=
"http://www.w3.org/XML/Activity">XML Activity</a>.</p>
<p>This document has been reviewed by W3C Members, by software
developers, and by other W3C groups and interested parties, and is
endorsed by the Director as a W3C Recommendation. It is a stable
document and may be used as reference material or cited from
another document. W3C's role in making the Recommendation is to
draw attention to the specification and to promote its widespread
deployment. This enhances the functionality and interoperability of
the Web.</p>
<p>This document incorporates minor changes made against the
<a href=
"http://www.w3.org/2004/02/Process-20040205/tr.html#RecsPR">Proposed
Recommendation</a> of 21 November 2006; please see the public
disposition of comments for details. Changes to this document since
the <a href=
"http://www.w3.org/2004/02/Process-20040205/tr.html#RecsPR">Proposed
Recommendation</a> are detailed in the <a href="#changelog"><b>B
Change Log for this Version of the Document</b></a>.</p>
<p>Please report errors in this document using W3C's <a href=
"http://www.w3.org/Bugs/Public/">public Bugzilla system</a>
(instructions can be found at <a href=
"http://www.w3.org/XML/2005/04/qt-bugzilla">http://www.w3.org/XML/2005/04/qt-bugzilla</a>).
If access to that system is not feasible, you may send your
comments to the W3C XSLT/XPath/XQuery public comments mailing list,
<a href=
"mailto:public-qt-comments@w3.org">public-qt-comments@w3.org</a>.
It will be very helpful if you include the string “[FO]” in the
subject line of your report, whether made in Bugzilla or in email.
Each Bugzilla entry and email message should contain only one error
report. Archives of the comments and responses are available at
<a href=
"http://lists.w3.org/Archives/Public/public-qt-comments/">http://lists.w3.org/Archives/Public/public-qt-comments/</a>.</p>
<p>This document was produced by groups operating under the
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
February 2004 W3C Patent Policy</a>. W3C maintains a <a href=
"http://www.w3.org/2004/01/pp-impl/18797/status#disclosures">public
list of any patent disclosures</a> made in connection with the
deliverables of the XML Query Working Group and also maintains a
<a href=
"http://www.w3.org/2004/01/pp-impl/19552/status#disclosures">public
list of any patent disclosures</a> made in connection with the
deliverables of the XSL Working Group; those pages also include
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains
<a href=
"http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">
Essential Claim(s)</a> must disclose the information in accordance
with <a href=
"http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">
section 6 of the W3C Patent Policy</a>.</p>
</div>
<div class="toc">
<h2><a name="contents" id="contents"></a>Table of Contents</h2>
<p class="toc">1 <a href="#intro">Introduction</a><br />
&#160;&#160;&#160;&#160;1.1 <a href=
"#conformance">Conformance</a><br />
&#160;&#160;&#160;&#160;1.2 <a href=
"#namespace-prefixes">Namespaces and Prefixes</a><br />
&#160;&#160;&#160;&#160;1.3 <a href="#func-overloading">Function
Overloading</a><br />
&#160;&#160;&#160;&#160;1.4 <a href="#func-signatures">Function
Signatures and Descriptions</a><br />
&#160;&#160;&#160;&#160;1.5 <a href=
"#namespace-terminology">Namespace Terminology</a><br />
&#160;&#160;&#160;&#160;1.6 <a href="#datatypes">Type
Hierarchy</a><br />
&#160;&#160;&#160;&#160;1.7 <a href=
"#terminology">Terminology</a><br />
2 <a href="#accessors">Accessors</a><br />
&#160;&#160;&#160;&#160;2.1 <a href=
"#func-node-name">fn:node-name</a><br />
&#160;&#160;&#160;&#160;2.2 <a href=
"#func-nilled">fn:nilled</a><br />
&#160;&#160;&#160;&#160;2.3 <a href=
"#func-string">fn:string</a><br />
&#160;&#160;&#160;&#160;2.4 <a href="#func-data">fn:data</a><br />
&#160;&#160;&#160;&#160;2.5 <a href=
"#func-base-uri">fn:base-uri</a><br />
&#160;&#160;&#160;&#160;2.6 <a href=
"#func-document-uri">fn:document-uri</a><br />
3 <a href="#func-error">The Error Function</a><br />
&#160;&#160;&#160;&#160;3.1 <a href=
"#func-error-examples">Examples</a><br />
4 <a href="#func-trace">The Trace Function</a><br />
&#160;&#160;&#160;&#160;4.1 <a href=
"#func-trace-examples">Examples</a><br />
5 <a href="#constructor-functions">Constructor Functions</a><br />
&#160;&#160;&#160;&#160;5.1 <a href=
"#constructor-functions-for-xsd-types">Constructor Functions for
XML Schema Built-in Types</a><br />
&#160;&#160;&#160;&#160;5.2 <a href="#func-dateTime">A Special
Constructor Function for xs:dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;5.2.1 <a href=
"#func-dateTime-examples">Examples</a><br />
&#160;&#160;&#160;&#160;5.3 <a href=
"#constructor-qname-notation">Constructor Functions for xs:QName
and xs:NOTATION</a><br />
&#160;&#160;&#160;&#160;5.4 <a href=
"#constructor-functions-for-user-defined-types">Constructor
Functions for User-Defined Types</a><br />
6 <a href="#numeric-functions">Functions and Operators on
Numerics</a><br />
&#160;&#160;&#160;&#160;6.1 <a href="#numeric-types">Numeric
Types</a><br />
&#160;&#160;&#160;&#160;6.2 <a href="#op.numeric">Operators on
Numeric Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.1 <a href=
"#func-numeric-add">op:numeric-add</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.2 <a href=
"#func-numeric-subtract">op:numeric-subtract</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.3 <a href=
"#func-numeric-multiply">op:numeric-multiply</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.4 <a href=
"#func-numeric-divide">op:numeric-divide</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.5 <a href=
"#func-numeric-integer-divide">op:numeric-integer-divide</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.6 <a href=
"#func-numeric-mod">op:numeric-mod</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.7 <a href=
"#func-numeric-unary-plus">op:numeric-unary-plus</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.2.8 <a href=
"#func-numeric-unary-minus">op:numeric-unary-minus</a><br />
&#160;&#160;&#160;&#160;6.3 <a href="#comp.numeric">Comparison
Operators on Numeric Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.3.1 <a href=
"#func-numeric-equal">op:numeric-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.3.2 <a href=
"#func-numeric-less-than">op:numeric-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.3.3 <a href=
"#func-numeric-greater-than">op:numeric-greater-than</a><br />
&#160;&#160;&#160;&#160;6.4 <a href=
"#numeric-value-functions">Functions on Numeric Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.4.1 <a href=
"#func-abs">fn:abs</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.4.2 <a href=
"#func-ceiling">fn:ceiling</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.4.3 <a href=
"#func-floor">fn:floor</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.4.4 <a href=
"#func-round">fn:round</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;6.4.5 <a href=
"#func-round-half-to-even">fn:round-half-to-even</a><br />
7 <a href="#string-functions">Functions on Strings</a><br />
&#160;&#160;&#160;&#160;7.1 <a href="#string-types">String
Types</a><br />
&#160;&#160;&#160;&#160;7.2 <a href=
"#func-assemble-disassemble-string">Functions to Assemble and
Disassemble Strings</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.2.1 <a href=
"#func-codepoints-to-string">fn:codepoints-to-string</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.2.2 <a href=
"#func-string-to-codepoints">fn:string-to-codepoints</a><br />
&#160;&#160;&#160;&#160;7.3 <a href="#string-compare">Equality and
Comparison of Strings</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.3.1 <a href=
"#collations">Collations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.3.2 <a href=
"#func-compare">fn:compare</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.3.3 <a href=
"#func-codepoint-equal">fn:codepoint-equal</a><br />
&#160;&#160;&#160;&#160;7.4 <a href=
"#string-value-functions">Functions on String Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.1 <a href=
"#func-concat">fn:concat</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.2 <a href=
"#func-string-join">fn:string-join</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.3 <a href=
"#func-substring">fn:substring</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.4 <a href=
"#func-string-length">fn:string-length</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.5 <a href=
"#func-normalize-space">fn:normalize-space</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.6 <a href=
"#func-normalize-unicode">fn:normalize-unicode</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.7 <a href=
"#func-upper-case">fn:upper-case</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.8 <a href=
"#func-lower-case">fn:lower-case</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.9 <a href=
"#func-translate">fn:translate</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.10 <a href=
"#func-encode-for-uri">fn:encode-for-uri</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.11 <a href=
"#func-iri-to-uri">fn:iri-to-uri</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.4.12 <a href=
"#func-escape-html-uri">fn:escape-html-uri</a><br />
&#160;&#160;&#160;&#160;7.5 <a href=
"#substring.functions">Functions Based on Substring
Matching</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.5.1 <a href=
"#func-contains">fn:contains</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.5.2 <a href=
"#func-starts-with">fn:starts-with</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.5.3 <a href=
"#func-ends-with">fn:ends-with</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.5.4 <a href=
"#func-substring-before">fn:substring-before</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.5.5 <a href=
"#func-substring-after">fn:substring-after</a><br />
&#160;&#160;&#160;&#160;7.6 <a href="#string.match">String
Functions that Use Pattern Matching</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.6.1 <a href=
"#regex-syntax">Regular Expression Syntax</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.6.2 <a href=
"#func-matches">fn:matches</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.6.3 <a href=
"#func-replace">fn:replace</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7.6.4 <a href=
"#func-tokenize">fn:tokenize</a><br />
8 <a href="#anyURI-functions">Functions on anyURI</a><br />
&#160;&#160;&#160;&#160;8.1 <a href=
"#func-resolve-uri">fn:resolve-uri</a><br />
9 <a href="#boolean-functions">Functions and Operators on Boolean
Values</a><br />
&#160;&#160;&#160;&#160;9.1 <a href=
"#boolean-constructors">Additional Boolean Constructor
Functions</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.1.1 <a href=
"#func-true">fn:true</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.1.2 <a href=
"#func-false">fn:false</a><br />
&#160;&#160;&#160;&#160;9.2 <a href="#op.boolean">Operators on
Boolean Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.2.1 <a href=
"#func-boolean-equal">op:boolean-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.2.2 <a href=
"#func-boolean-less-than">op:boolean-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.2.3 <a href=
"#func-boolean-greater-than">op:boolean-greater-than</a><br />
&#160;&#160;&#160;&#160;9.3 <a href=
"#boolean-value-functions">Functions on Boolean Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;9.3.1 <a href=
"#func-not">fn:not</a><br />
10 <a href="#durations-dates-times">Functions and Operators on
Durations, Dates and Times</a><br />
&#160;&#160;&#160;&#160;10.1 <a href=
"#duration-date-time-types">Duration, Date and Time Types</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.1.1 <a href=
"#date-time-duration-conformance">Limits and Precision</a><br />
&#160;&#160;&#160;&#160;10.2 <a href="#date-time-values">Date/time
datatype values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.2.1 <a href=
"#date-time-lexical-mapping">Examples</a><br />
&#160;&#160;&#160;&#160;10.3 <a href="#duration-subtypes">Two
Totally Ordered Subtypes of Duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.3.1 <a href=
"#dt-yearMonthDuration">xs:yearMonthDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.3.2 <a href=
"#dt-dayTimeDuration">xs:dayTimeDuration</a><br />
&#160;&#160;&#160;&#160;10.4 <a href=
"#comp.duration.datetime">Comparison Operators on Duration, Date
and Time Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.1 <a href=
"#func-yearMonthDuration-less-than">op:yearMonthDuration-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.2 <a href=
"#func-yearMonthDuration-greater-than">op:yearMonthDuration-greater-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.3 <a href=
"#func-dayTimeDuration-less-than">op:dayTimeDuration-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.4 <a href=
"#func-dayTimeDuration-greater-than">op:dayTimeDuration-greater-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.5 <a href=
"#func-duration-equal">op:duration-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.6 <a href=
"#func-dateTime-equal">op:dateTime-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.7 <a href=
"#func-dateTime-less-than">op:dateTime-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.8 <a href=
"#func-dateTime-greater-than">op:dateTime-greater-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.9 <a href=
"#func-date-equal">op:date-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.10 <a href=
"#func-date-less-than">op:date-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.11 <a href=
"#func-date-greater-than">op:date-greater-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.12 <a href=
"#func-time-equal">op:time-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.13 <a href=
"#func-time-less-than">op:time-less-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.14 <a href=
"#func-time-greater-than">op:time-greater-than</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.15 <a href=
"#func-gYearMonth-equal">op:gYearMonth-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.16 <a href=
"#func-gYear-equal">op:gYear-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.17 <a href=
"#func-gMonthDay-equal">op:gMonthDay-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.18 <a href=
"#func-gMonth-equal">op:gMonth-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.4.19 <a href=
"#func-gDay-equal">op:gDay-equal</a><br />
&#160;&#160;&#160;&#160;10.5 <a href=
"#component-extraction-functions">Component Extraction Functions on
Durations, Dates and Times</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.1 <a href=
"#func-years-from-duration">fn:years-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.2 <a href=
"#func-months-from-duration">fn:months-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.3 <a href=
"#func-days-from-duration">fn:days-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.4 <a href=
"#func-hours-from-duration">fn:hours-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.5 <a href=
"#func-minutes-from-duration">fn:minutes-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.6 <a href=
"#func-seconds-from-duration">fn:seconds-from-duration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.7 <a href=
"#func-year-from-dateTime">fn:year-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.8 <a href=
"#func-month-from-dateTime">fn:month-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.9 <a href=
"#func-day-from-dateTime">fn:day-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.10 <a href=
"#func-hours-from-dateTime">fn:hours-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.11 <a href=
"#func-minutes-from-dateTime">fn:minutes-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.12 <a href=
"#func-seconds-from-dateTime">fn:seconds-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.13 <a href=
"#func-timezone-from-dateTime">fn:timezone-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.14 <a href=
"#func-year-from-date">fn:year-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.15 <a href=
"#func-month-from-date">fn:month-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.16 <a href=
"#func-day-from-date">fn:day-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.17 <a href=
"#func-timezone-from-date">fn:timezone-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.18 <a href=
"#func-hours-from-time">fn:hours-from-time</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.19 <a href=
"#func-minutes-from-time">fn:minutes-from-time</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.20 <a href=
"#func-seconds-from-time">fn:seconds-from-time</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.5.21 <a href=
"#func-timezone-from-time">fn:timezone-from-time</a><br />
&#160;&#160;&#160;&#160;10.6 <a href=
"#duration-arithmetic">Arithmetic Operators on Durations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.1 <a href=
"#func-add-yearMonthDurations">op:add-yearMonthDurations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.2 <a href=
"#func-subtract-yearMonthDurations">op:subtract-yearMonthDurations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.3 <a href=
"#func-multiply-yearMonthDuration">op:multiply-yearMonthDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.4 <a href=
"#func-divide-yearMonthDuration">op:divide-yearMonthDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.5 <a href=
"#func-divide-yearMonthDuration-by-yearMonthDuration">op:divide-yearMonthDuration-by-yearMonthDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.6 <a href=
"#func-add-dayTimeDurations">op:add-dayTimeDurations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.7 <a href=
"#func-subtract-dayTimeDurations">op:subtract-dayTimeDurations</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.8 <a href=
"#func-multiply-dayTimeDuration">op:multiply-dayTimeDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.9 <a href=
"#func-divide-dayTimeDuration">op:divide-dayTimeDuration</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.6.10 <a href=
"#func-divide-dayTimeDuration-by-dayTimeDuration">op:divide-dayTimeDuration-by-dayTimeDuration</a><br />
&#160;&#160;&#160;&#160;10.7 <a href="#timezone.functions">Timezone
Adjustment Functions on Dates and Time Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.7.1 <a href=
"#func-adjust-dateTime-to-timezone">fn:adjust-dateTime-to-timezone</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.7.2 <a href=
"#func-adjust-date-to-timezone">fn:adjust-date-to-timezone</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.7.3 <a href=
"#func-adjust-time-to-timezone">fn:adjust-time-to-timezone</a><br />
&#160;&#160;&#160;&#160;10.8 <a href=
"#dateTime-arithmetic">Arithmetic Operators on Durations, Dates and
Times</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.1 <a href=
"#func-subtract-dateTimes">op:subtract-dateTimes</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.2 <a href=
"#func-subtract-dates">op:subtract-dates</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.3 <a href=
"#func-subtract-times">op:subtract-times</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.4 <a href=
"#func-add-yearMonthDuration-to-dateTime">op:add-yearMonthDuration-to-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.5 <a href=
"#func-add-dayTimeDuration-to-dateTime">op:add-dayTimeDuration-to-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.6 <a href=
"#func-subtract-yearMonthDuration-from-dateTime">op:subtract-yearMonthDuration-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.7 <a href=
"#func-subtract-dayTimeDuration-from-dateTime">op:subtract-dayTimeDuration-from-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.8 <a href=
"#func-add-yearMonthDuration-to-date">op:add-yearMonthDuration-to-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.9 <a href=
"#func-add-dayTimeDuration-to-date">op:add-dayTimeDuration-to-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.10 <a href=
"#func-subtract-yearMonthDuration-from-date">op:subtract-yearMonthDuration-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.11 <a href=
"#func-subtract-dayTimeDuration-from-date">op:subtract-dayTimeDuration-from-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.12 <a href=
"#func-add-dayTimeDuration-to-time">op:add-dayTimeDuration-to-time</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10.8.13 <a href=
"#func-subtract-dayTimeDuration-from-time">op:subtract-dayTimeDuration-from-time</a><br />
11 <a href="#QName-funcs">Functions Related to QNames</a><br />
&#160;&#160;&#160;&#160;11.1 <a href=
"#QName-constructors">Additional Constructor Functions for
QNames</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.1.1 <a href=
"#func-resolve-QName">fn:resolve-QName</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.1.2 <a href=
"#func-QName">fn:QName</a><br />
&#160;&#160;&#160;&#160;11.2 <a href="#QName-functions">Functions
and Operators Related to QNames</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.1 <a href=
"#func-QName-equal">op:QName-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.2 <a href=
"#func-prefix-from-QName">fn:prefix-from-QName</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.3 <a href=
"#func-local-name-from-QName">fn:local-name-from-QName</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.4 <a href=
"#func-namespace-uri-from-QName">fn:namespace-uri-from-QName</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.5 <a href=
"#func-namespace-uri-for-prefix">fn:namespace-uri-for-prefix</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;11.2.6 <a href=
"#func-in-scope-prefixes">fn:in-scope-prefixes</a><br />
12 <a href="#binary-functions">Operators on base64Binary and
hexBinary</a><br />
&#160;&#160;&#160;&#160;12.1 <a href=
"#binary-value-comparisons">Comparisons of base64Binary and
hexBinary Values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;12.1.1 <a href=
"#func-hexBinary-equal">op:hexBinary-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;12.1.2 <a href=
"#func-base64Binary-equal">op:base64Binary-equal</a><br />
13 <a href="#NOTATION-functions">Operators on NOTATION</a><br />
&#160;&#160;&#160;&#160;13.1 <a href="#op.NOTATION">Operators on
NOTATION</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;13.1.1 <a href=
"#func-NOTATION-equal">op:NOTATION-equal</a><br />
14 <a href="#node-functions">Functions and Operators on
Nodes</a><br />
&#160;&#160;&#160;&#160;14.1 <a href="#func-name">fn:name</a><br />
&#160;&#160;&#160;&#160;14.2 <a href=
"#func-local-name">fn:local-name</a><br />
&#160;&#160;&#160;&#160;14.3 <a href=
"#func-namespace-uri">fn:namespace-uri</a><br />
&#160;&#160;&#160;&#160;14.4 <a href=
"#func-number">fn:number</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.4.1 <a href=
"#func-number-examples">Examples</a><br />
&#160;&#160;&#160;&#160;14.5 <a href="#func-lang">fn:lang</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.5.1 <a href=
"#func-lang-examples">Examples</a><br />
&#160;&#160;&#160;&#160;14.6 <a href=
"#func-is-same-node">op:is-same-node</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.6.1 <a href=
"#func-is-same-node-examples">Examples</a><br />
&#160;&#160;&#160;&#160;14.7 <a href=
"#func-node-before">op:node-before</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.7.1 <a href=
"#func-node-before-examples">Examples</a><br />
&#160;&#160;&#160;&#160;14.8 <a href=
"#func-node-after">op:node-after</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.8.1 <a href=
"#func-node-after-examples">Examples</a><br />
&#160;&#160;&#160;&#160;14.9 <a href="#func-root">fn:root</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14.9.1 <a href=
"#func-root-examples">Examples</a><br />
15 <a href="#sequence-functions">Functions and Operators on
Sequences</a><br />
&#160;&#160;&#160;&#160;15.1 <a href="#general-seq-funcs">General
Functions and Operators on Sequences</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.1 <a href=
"#func-boolean">fn:boolean</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.2 <a href=
"#func-concatenate">op:concatenate</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.3 <a href=
"#func-index-of">fn:index-of</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.4 <a href=
"#func-empty">fn:empty</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.5 <a href=
"#func-exists">fn:exists</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.6 <a href=
"#func-distinct-values">fn:distinct-values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.7 <a href=
"#func-insert-before">fn:insert-before</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.8 <a href=
"#func-remove">fn:remove</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.9 <a href=
"#func-reverse">fn:reverse</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.10 <a href=
"#func-subsequence">fn:subsequence</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.1.11 <a href=
"#func-unordered">fn:unordered</a><br />
&#160;&#160;&#160;&#160;15.2 <a href=
"#cardinality-functions">Functions That Test the Cardinality of
Sequences</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.2.1 <a href=
"#func-zero-or-one">fn:zero-or-one</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.2.2 <a href=
"#func-one-or-more">fn:one-or-more</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.2.3 <a href=
"#func-exactly-one">fn:exactly-one</a><br />
&#160;&#160;&#160;&#160;15.3 <a href=
"#union-intersection-except">Equals, Union, Intersection and
Except</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.3.1 <a href=
"#func-deep-equal">fn:deep-equal</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.3.2 <a href=
"#func-union">op:union</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.3.3 <a href=
"#func-intersect">op:intersect</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.3.4 <a href=
"#func-except">op:except</a><br />
&#160;&#160;&#160;&#160;15.4 <a href=
"#aggregate-functions">Aggregate Functions</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.4.1 <a href=
"#func-count">fn:count</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.4.2 <a href=
"#func-avg">fn:avg</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.4.3 <a href=
"#func-max">fn:max</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.4.4 <a href=
"#func-min">fn:min</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.4.5 <a href=
"#func-sum">fn:sum</a><br />
&#160;&#160;&#160;&#160;15.5 <a href=
"#fns-that-generate-sequences">Functions and Operators that
Generate Sequences</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.1 <a href=
"#func-to">op:to</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.2 <a href=
"#func-id">fn:id</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.3 <a href=
"#func-idref">fn:idref</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.4 <a href=
"#func-doc">fn:doc</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.5 <a href=
"#func-doc-available">fn:doc-available</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;15.5.6 <a href=
"#func-collection">fn:collection</a><br />
16 <a href="#context">Context Functions</a><br />
&#160;&#160;&#160;&#160;16.1 <a href=
"#func-position">fn:position</a><br />
&#160;&#160;&#160;&#160;16.2 <a href="#func-last">fn:last</a><br />
&#160;&#160;&#160;&#160;16.3 <a href=
"#func-current-dateTime">fn:current-dateTime</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;16.3.1 <a href=
"#func-current-dateTime-examples">Examples</a><br />
&#160;&#160;&#160;&#160;16.4 <a href=
"#func-current-date">fn:current-date</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;16.4.1 <a href=
"#func-current-date-examples">Examples</a><br />
&#160;&#160;&#160;&#160;16.5 <a href=
"#func-current-time">fn:current-time</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;16.5.1 <a href=
"#func-current-time-examples">Examples</a><br />
&#160;&#160;&#160;&#160;16.6 <a href=
"#func-implicit-timezone">fn:implicit-timezone</a><br />
&#160;&#160;&#160;&#160;16.7 <a href=
"#func-default-collation">fn:default-collation</a><br />
&#160;&#160;&#160;&#160;16.8 <a href=
"#func-static-base-uri">fn:static-base-uri</a><br />
17 <a href="#casting">Casting</a><br />
&#160;&#160;&#160;&#160;17.1 <a href=
"#casting-from-primitive-to-primitive">Casting from primitive types
to primitive types</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.1 <a href=
"#casting-from-strings">Casting from xs:string and
xs:untypedAtomic</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.2 <a href=
"#casting-to-string">Casting to xs:string and
xs:untypedAtomic</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.3 <a href=
"#casting-to-numerics">Casting to numeric types</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.4 <a href=
"#casting-to-durations">Casting to duration types</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.5 <a href=
"#casting-to-datetimes">Casting to date and time types</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.6 <a href=
"#casting-boolean">Casting to xs:boolean</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.7 <a href=
"#casting-to-binary">Casting to xs:base64Binary and
xs:hexBinary</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.1.8 <a href=
"#casting-to-anyuri">Casting to xs:anyURI</a><br />
&#160;&#160;&#160;&#160;17.2 <a href=
"#casting-to-derived-types">Casting to derived types</a><br />
&#160;&#160;&#160;&#160;17.3 <a href=
"#casting-from-derived-to-parent">Casting from derived types to
parent types</a><br />
&#160;&#160;&#160;&#160;17.4 <a href=
"#casting-within-branch">Casting within a branch of the type
hierarchy</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;17.4.1 <a href=
"#casting-to-ENTITY">Casting to xs:ENTITY</a><br />
&#160;&#160;&#160;&#160;17.5 <a href=
"#casting-across-hierarchy">Casting across the type
hierarchy</a><br /></p>
<h3><a name="appendices" id="appendices"></a>Appendices</h3>
<p class="toc">A <a href="#biblio">References</a><br />
&#160;&#160;&#160;&#160;A.1 <a href="#normative-biblio">Normative
References</a><br />
&#160;&#160;&#160;&#160;A.2 <a href=
"#non-normative-biblio">Non-normative References</a><br />
B <a href="#changelog">Change Log for this Version of the
Document</a><br />
C <a href="#error-summary">Error Summary</a><br />
D <a href="#xpath1-compatibility">Compatibility with XPath 1.0</a>
(Non-Normative)<br />
E <a href="#examples">Illustrative User-written Functions</a>
(Non-Normative)<br />
&#160;&#160;&#160;&#160;E.1 <a href=
"#if-empty-if-absent">eg:if-empty and eg:if-absent</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E.1.1 <a href=
"#if-empty">eg:if-empty</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E.1.2 <a href=
"#if-absent">eg:if-absent</a><br />
&#160;&#160;&#160;&#160;E.2 <a href=
"#union-intersect-except-on-values">union, intersect and except on
sequences of values</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E.2.1 <a href=
"#value-union">eg:value-union</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E.2.2 <a href=
"#value-intersect">eg:value-intersect</a><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E.2.3 <a href=
"#value-except">eg:value-except</a><br />
&#160;&#160;&#160;&#160;E.3 <a href=
"#index-of-node">eg:index-of-node</a><br />
&#160;&#160;&#160;&#160;E.4 <a href=
"#string-pad">eg:string-pad</a><br />
&#160;&#160;&#160;&#160;E.5 <a href=
"#func-distinct-nodes-stable">eg:distinct-nodes-stable</a><br />
F <a href="#impl-def">Checklist of Implementation-Defined
Features</a> (Non-Normative)<br />
G <a href="#quickref">Function and Operator Quick Reference</a>
(Non-Normative)<br />
&#160;&#160;&#160;&#160;G.1 <a href="#quickref-section">Functions
and Operators by Section</a><br />
&#160;&#160;&#160;&#160;G.2 <a href="#quickref-alpha">Functions and
Operators Alphabetically</a><br /></p>
</div>
<hr />
<div class="body">
<div class="div1">
<h2><a name="intro" id="intro"></a>1 Introduction</h2>
<p>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 <a href="#xpath20">[XML Path Language (XPath)
2.0]</a>, <a href="#xquery">[XQuery 1.0: An XML Query Language]</a>
and <a href="#xslt20">[XSL Transformations (XSLT) Version
2.0]</a>.</p>
<p>This document defines constructor functions and functions that
take typed values as arguments. Some of the functions define the
semantics of operators discussed in <a href="#xquery">[XQuery 1.0:
An XML Query Language]</a>.</p>
<p><a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> defines a number of primitive and derived datatypes,
collectively known as built-in datatypes. This document defines
functions and operations on these datatypes as well as the
datatypes defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> of the <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a>. These
functions and operations are defined for use in <a href=
"#xpath20">[XML Path Language (XPath) 2.0]</a>, <a href=
"#xquery">[XQuery 1.0: An XML Query Language]</a> and <a href=
"#xslt20">[XSL Transformations (XSLT) Version 2.0]</a> and related
XML standards. This document also discusses functions and operators
on nodes and node sequences as defined in the <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a> for
use in <a href="#xpath20">[XML Path Language (XPath) 2.0]</a>,
<a href="#xquery">[XQuery 1.0: An XML Query Language]</a> and
<a href="#xslt20">[XSL Transformations (XSLT) Version 2.0]</a> and
other related XML standards.</p>
<p>References to specific sections of some of the above documents
are indicated by cross-document links in this document. Each such
link consists of a pointer to a specific section followed a
superscript specifying the linked document. The superscripts have
the following meanings: 'XQ' <a href="#xquery">[XQuery 1.0: An XML
Query Language]</a>, 'XT' <a href="#xslt20">[XSL Transformations
(XSLT) Version 2.0]</a>, 'XP' <a href="#xpath20">[XML Path Language
(XPath) 2.0]</a>, 'DM' <a href="#xpath-datamodel">[XQuery 1.0 and
XPath 2.0 Data Model]</a> and 'FS' <a href=
"#xquery-semantics">[XQuery 1.0 and XPath 2.0 Formal
Semantics]</a>.</p>
<div class="div2">
<h3><a name="conformance" id="conformance"></a>1.1 Conformance</h3>
<p>The Functions and Operators specification is intended primarily
as a component that can be used by other specifications. Therefore,
Functions and Operators relies on specifications that use it (such
as <a href="#xpath20">[XML Path Language (XPath) 2.0]</a>, <a href=
"#xslt20">[XSL Transformations (XSLT) Version 2.0]</a> and <a href=
"#xquery">[XQuery 1.0: An XML Query Language]</a>) to specify
conformance criteria for their respective environments.</p>
<p>Authors of conformance criteria for the use of the Functions and
Operators should pay particular attention to the following
features:</p>
<ul>
<li>
<p>It is <a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> which version of Unicode is supported, but it
is recommended that the most recent version of Unicode be used.</p>
</li>
<li>
<p>Support for XML 1.0 and XML 1.1 by the datatypes used in
Functions and Operators.</p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>At the time of writing there is no published version of XML
Schema that references the XML 1.1 specifications. This means that
datatypes such as <code>xs:NCName</code> and <code>xs:ID</code> are
constrained by the XML 1.0 rules. Authors of conformance
requirements for the use of Functions and Operators should state
clearly the implications for conformance of any changes to the
rules in later versions of XML Schema.</p>
</div>
</div>
<div class="div2">
<h3><a name="namespace-prefixes" id="namespace-prefixes"></a>1.2
Namespaces and Prefixes</h3>
<p>The functions and operators discussed in this document are
contained in one of three namespaces (see <a href=
"#REC-xml-names">[Namespaces in XML]</a>) and referenced using an
<code>xs:QName</code>. The datatypes and constructor functions for
the built-in datatypes defined in <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> and in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> of <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a> and
discussed in <a href="#constructor-functions"><b>5 Constructor
Functions</b></a> are in the XML Schema namespace,
<code>http://www.w3.org/2001/XMLSchema</code>, and named in this
document using the <code>xs</code> prefix. The namespace prefix
used in this document for functions that are available to users is
<code>fn</code>. Operator functions are named with the prefix
<code>op</code>.</p>
<p>This document uses the prefix <code>err</code> to represent the
namespace URI <code>http://www.w3.org/2005/xqt-errors</code>, which
is the namespace for all XPath and XQuery error codes and messages.
This namespace prefix is not predeclared and its use in this
document is not normative.</p>
<p>The namespace prefix used for the functions, datatypes and
errors can vary, as long as the prefix is bound to the correct
URI.</p>
<p>The URIs of the namespaces and the default prefixes associated
with them are:</p>
<ul>
<li>
<p><code>http://www.w3.org/2001/XMLSchema</code> for constructors
-- associated with <code>xs</code>.</p>
</li>
<li>
<p><code>http://www.w3.org/2005/xpath-functions</code> for
functions -- associated with <code>fn</code>.</p>
</li>
<li>
<p><code>http://www.w3.org/2005/xqt-errors</code> -- associated
with <code>err</code>.</p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The namespace URI associated with the <code>err</code> prefix is
not expected to change from one version of this document to
another. The contents of this namespace may be extended to allow
additional errors to be returned.</p>
</div>
<p>The functions defined with an <code>fn</code> prefix are
callable by the user. Functions defined with the <code>op</code>
prefix are described here to underpin the definitions of the
operators in <a href="#xpath20">[XML Path Language (XPath)
2.0]</a>, <a href="#xquery">[XQuery 1.0: An XML Query Language]</a>
and <a href="#xslt20">[XSL Transformations (XSLT) Version 2.0]</a>.
These functions are not available directly to users, and there is
no requirement that implementations should actually provide these
functions. For this reason, no namespace is associated with the
<code>op</code> prefix. For example, multiplication is generally
associated with the <code>*</code> operator, but it is described as
a function in this document:</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-multiply</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">numeric</code></div>
</div>
</div>
<div class="div2">
<h3><a name="func-overloading" id="func-overloading"></a>1.3
Function Overloading</h3>
<p>In general, the specifications named above do not support
function overloading in the sense that functions that have multiple
signatures with the same name and the same number of parameters are
not supported. Consequently, there are no such overloaded functions
in this document except for legacy <a href="#xpath">[XML Path
Language (XPath) Version 1.0]</a> functions such as <a href=
"#func-string"><code>fn:string()</code></a>, which accepts a single
parameter of a variety of types. In addition, it should be noted
that the functions defined in <a href="#numeric-functions"><b>6
Functions and Operators on Numerics</b></a> that accept
<code>numeric</code> parameters accept arguments of type
<code>xs:integer</code>, <code>xs:decimal</code>,
<code>xs:float</code> or <code>xs:double</code>. See <a href=
"#func-signatures"><b>1.4 Function Signatures and
Descriptions</b></a>. Operators such as "+" may be overloaded. This
document does define some functions with more than one signature
with the same name and different number of parameters. User-defined
functions with more than one signature with the same name and
different number of parameters are also supported.</p>
</div>
<div class="div2">
<h3><a name="func-signatures" id="func-signatures"></a>1.4 Function
Signatures and Descriptions</h3>
<p>Each function is defined by specifying its signature, a
description of the return type and each of the parameters and its
semantics. For many functions, examples are included to illustrate
their use.</p>
<p>Each function's signature is presented in a form like this:</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:function-name</code>(<code class=
"arg">$parameter-name</code><code class=
"as">&#160;as&#160;</code><code class="type">parameter-type</code>,
<span class="varargs">...</span>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">return-type</code></div>
</div>
<p>In this notation, <b>function-name</b>, in bold-face, 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
parameter list: "<code>()</code>"; otherwise, the name is followed
by a parenthesized list of parameter declarations, each declaration
specifies the static type of the parameter, in italics, and a
descriptive, but non-normative, name. If there are two or more
parameter declarations, they are separated by a comma. The
<em><code>return-type</code></em> , also in italics, specifies the
static type of the value returned by the function. The dynamic type
returned by the function is the same as its static type or derived
from the static type. All parameter types and return types are
specified using the SequenceType notation defined in <a href=
"http://www.w3.org/TR/xpath20/#id-sequencetype-syntax">Section
2.5.3 SequenceType Syntax</a><sup><small>XP</small></sup>.</p>
<p>In some cases the word " <code>numeric</code> " is used in
function signatures as a shorthand to indicate the four numeric
types: <code>xs:integer</code>, <code>xs:decimal</code>,
<code>xs:float</code> and <code>xs:double</code>. For example, a
function with the signature</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:numeric-function</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">...</code></div>
</div>
represents the following four function signatures:
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:numeric-function</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:integer</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">...</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:numeric-function</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:decimal</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">...</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:numeric-function</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:float</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">...</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:numeric-function</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">...</code></div>
</div>
<p>For most functions there is an initial paragraph describing what
the function does followed by semantic rules. These rules are meant
to be followed in the order that they appear in this document.</p>
<p>In some cases, the static type returned by a function depends on
the type(s) of its argument(s). These special functions are
indicated by using <em><b>bold italics</b></em> for the return
type. The semantic rules specifying the type of the value returned
are documented in the function definition. The rules are described
more formally in <a href=
"http://www.w3.org/TR/xquery-semantics/#function_rules">Section 7.2
Standard functions with specific static typing
rules</a><sup><small>FS</small></sup>.</p>
<p>The function name is a <code>QName</code> as defined in <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
and must adhere to its syntactic conventions. Following <a href=
"#xpath">[XML Path Language (XPath) Version 1.0]</a>, function
names are composed of English words separated by hyphens,"-". If a
function name contains a <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a> datatype name, it may have
intercapitalized spelling and is used in the function name as such.
For example, <a href=
"#func-timezone-from-dateTime"><code>fn:timezone-from-dateTime</code></a>.</p>
<p>Rules for passing parameters to operators are described in the
relevant sections of <a href="#xquery">[XQuery 1.0: An XML Query
Language]</a> and <a href="#xpath20">[XML Path Language (XPath)
2.0]</a>. For example, the rules for passing parameters to
arithmetic operators are described in <a href=
"http://www.w3.org/TR/xpath20/#id-arithmetic">Section 3.4
Arithmetic Expressions</a><sup><small>XP</small></sup>.
Specifically, rules for parameters of type
<code>xs:untypedAtomic</code> and the empty sequence are specified
in this section.</p>
<p>As is customary, the parameter type name indicates that the
function or operator accepts arguments of that type, or types
derived from it, in that position. This is called <em>subtype
substitution</em> (See <a href=
"http://www.w3.org/TR/xpath20/#id-sequencetype-matching">Section
2.5.4 SequenceType Matching</a><sup><small>XP</small></sup>). In
addition, numeric type instances and instances of type
<code>xs:anyURI</code> can be promoted to produce an argument of
the required type. (See <a href=
"http://www.w3.org/TR/xpath20/#promotion">Section B.1 Type
Promotion</a><sup><small>XP</small></sup>).</p>
<ol class="enumar">
<li>
<p><em>Subtype Substitution</em>: A derived type may substitute for
its base type. In particular, <code>xs:integer</code> may be used
where <code>xs:decimal</code> is expected.</p>
</li>
<li>
<p><em>Numeric Type Promotion</em>: <code>xs:decimal</code> may be
promoted to <code>xs:float</code> or <code>xs:double</code>.
Promotion to <code>xs:double</code> should be done directly, not
via <code>xs:float</code>, to avoid loss of precision.</p>
</li>
<li>
<p><em>anyURI Type Promotion</em>: A value of type
<code>xs:anyURI</code> can be promoted to the type
<code>xs:string</code>.</p>
</li>
</ol>
<p>Some functions accept a single value or the empty sequence as an
argument and some may return a single value or the empty sequence.
This is indicated in the function signature by following the
parameter or return type name with a question mark:
"<code>?</code>", indicating that either a single value or the
empty sequence must appear. See below.</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:function-name</code>(<code class=
"arg">$parameter-name</code><code class=
"as">&#160;as&#160;</code><code class=
"type">parameter-type?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">return-type?</code></div>
</div>
<p>Note that this function signature is different from a signature
in which the parameter is omitted. See, for example, the two
signatures for <a href="#func-string"><code>fn:string()</code></a>.
In the first signature, the parameter is omitted and the argument
defaults to the context item, referred to as ".". In the second
signature, the argument must be present but may be the empty
sequence, referred to as "()."</p>
<p>Some functions accept a sequence of zero or more values as an
argument. This is indicated by following the name of type of the
items in the sequence with <code>*</code>. The sequence may contain
zero or more items of the named type. For example, the function
below accepts a sequence of <code>xs:double</code> and returns a
<code>xs:double</code> or the empty sequence.</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:median</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:double*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double?</code></div>
</div>
</div>
<div class="div2">
<h3><a name="namespace-terminology" id=
"namespace-terminology"></a>1.5 Namespace Terminology</h3>
<p>This document uses the phrase "namespace URI" to identify the
concept identified in <a href="#REC-xml-names">[Namespaces in
XML]</a> as "namespace name", and the phrase "local name" to
identify the concept identified in <a href=
"#REC-xml-names">[Namespaces in XML]</a> as "local part".</p>
<p>It also uses the term "expanded-QName" defined below.</p>
<dl>
<dt class="label"><span class="termdef"><a name="expanded-Qname"
id="expanded-Qname"></a>[Definition]
<b>Expanded-QName</b></span></dt>
<dd>
<p>An expanded-QName is a pair of values consisting of a namespace
URI and a local name. They belong to the value space of the
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> datatype <code>xs:QName</code>. When this document
refers to <code>xs:QName</code> we always mean the value space,
i.e. a namespace URI, local name pair (and not the lexical space
referring to constructs of the form prefix:local-name).</p>
</dd>
</dl>
</div>
<div class="div2">
<h3><a name="datatypes" id="datatypes"></a>1.6 Type Hierarchy</h3>
<p>The diagram below shows the types for which functions are
defined in this document. These include the built-in types defined
by <a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> (shown on the right) as well as types defined in
<a href="#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data
Model]</a> (shown on the left). Solid lines connect a base datatype
above to a derived datatype.<code>xs:IDREFS</code>,
<code>xs:NMTOKENS</code>, <code>xs:ENTITIES</code> and
<code>user-defined list and union types</code> are special types in
that these types are lists or unions rather than true subtypes.
Dashed lines connect a union type above with its component types
below.</p>
<img src="type-hierarchy.png" alt="Type hierarchy graphic" />
<p>The information in the above diagram is reproduced below in
tabular form. For ease of presentation the information is divided
into three tables. The first table shows the top three layers of
the hierarchy starting at <code>xs:anyType</code>. The second table
shows the types derived from <code>xs:anyAtomicType</code>. The
third table shows the types defined in <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a></p>
<p>Each type whose name is indented is derived from the type whose
name appears nearest above it with one less level of
indentation.</p>
<table class="hierarchy" summary="Type summary" border="0">
<tbody>
<tr>
<td class="castOther" align="left" valign="middle">xs:anyType</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">user-defined
complex types</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:untyped</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:anySimpleType</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">user-defined
list and union types</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:IDREFS</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:NMTOKENS</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:ENTITIES</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:anyAtomicType</td>
</tr>
</tbody>
</table>
<p>The table below shows the datatypes derived from
<code>xs:anyAtomicType</code>. This includes all the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
built-in datatypes as well as the two totally ordered subtypes of
duration defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup>.</p>
<p>Each type whose name is indented is derived from the type whose
name appears nearest above it with one less level of
indentation.</p>
<table class="hierarchy" summary="Type summary" border="0">
<tbody>
<tr>
<td class="castOther" align="left" valign="middle">
xs:untypedAtomic</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:dateTime</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:date</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:time</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:duration</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:yearMonthDuration</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:dayTimeDuration</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:float</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:double</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:decimal</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:integer</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:nonPositiveInteger</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:negativeInteger</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:long</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:int</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:short</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:byte</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:nonNegativeInteger</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:unsignedLong</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:unsignedInt</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:unsignedShort</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:unsignedByte</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:positiveInteger</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">
xs:gYearMonth</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:gYear</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">
xs:gMonthDay</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:gDay</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:gMonth</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:string</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:normalizedString</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:token</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:language</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:NMTOKEN</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:Name</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:NCName</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:ID</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:IDREF</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:ENTITY</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:boolean</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">
xs:base64Binary</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">
xs:hexBinary</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:anyURI</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:QName</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:NOTATION</td>
</tr>
</tbody>
</table>
<p>The table below shows the type hierarchy for the types
introduced in <a href="#xpath-datamodel">[XQuery 1.0 and XPath 2.0
Data Model]</a>. For these types, each type whose name is indented
is a component of the union type whose name appears nearest above
with one less level of indentation.</p>
<table class="hierarchy" summary="Type summary" border="0">
<tbody>
<tr>
<td class="castOther" align="left" valign="middle">item</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:anyAtomicType</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">node</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">attribute</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">user-defined
attribute types</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">comment</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">document</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">user-defined
document types</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">element</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">user-defined
element types</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
processing-instruction</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">text</td>
</tr>
</tbody>
</table>
</div>
<div class="div2">
<h3><a name="terminology" id="terminology"></a>1.7 Terminology</h3>
<p>The terminology used to describe the functions and operators on
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> is defined in the body of this specification. The
terms defined in the following list are used in building those
definitions:</p>
<dl>
<dt class="label"><span class="termdef"><a name="compatibility" id=
"compatibility"></a>[Definition] <b>for
compatibility</b></span></dt>
<dd>
<p>A feature of this specification included to ensure that
implementations that use this feature remain compatible with
<a href="#xpath">[XML Path Language (XPath) Version 1.0]</a></p>
</dd>
<dt class="label"><span class="termdef"><a name="may" id=
"may"></a>[Definition] <b>may</b></span></dt>
<dd>
<p>Conforming documents and processors are permitted to, but need
not, behave as described.</p>
</dd>
<dt class="label"><span class="termdef"><a name="must" id=
"must"></a>[Definition] <b>must</b></span></dt>
<dd>
<p>Conforming documents and processors are required to behave as
described; otherwise, they are either non-conformant or else in
error.</p>
</dd>
<dt class="label"><span class="termdef"><a name=
"implementation-defined" id=
"implementation-defined"></a>[Definition]
<b>implementation-defined</b></span></dt>
<dd>
<p>Possibly differing between implementations, but specified and
documented by the implementor for each particular
implementation.</p>
</dd>
<dt class="label"><span class="termdef"><a name=
"implementation-dependent" id=
"implementation-dependent"></a>[Definition]
<b>implementation-dependent</b></span></dt>
<dd>
<p>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.</p>
</dd>
<dt class="label"><span class="termdef"><a name="execution-scope"
id="execution-scope"></a>[Definition] <b>execution
scope</b></span></dt>
<dd>
<p>The scope over which any two calls on a function would be
executed. In XSLT, it applies to any two calls on the function
executed during the same transformation. In XQuery, it applies to
any two calls executed during the evaluation of a top-level
expression i.e. an expression not contained in any other
expression. In other contexts, the scope is specified by the host
environment that invokes the function library.</p>
</dd>
<dt class="label"><span class="termdef"><a name="stable" id=
"stable"></a>[Definition] <b>stable</b></span></dt>
<dd>
<p>Most of the functions in the core library have the property that
calling the same function twice within an <a title=
"execution scope" class="termref" href=
"#execution-scope"><span class="arrow">·</span>execution
scope<span class="arrow">·</span></a> with the same arguments
returns the same result: these functions are said to be
<b>stable</b>. This category includes a number of functions such as
<a href="#func-doc"><code>fn:doc()</code></a>, <a href=
"#func-collection"><code>fn:collection()</code></a>, <a href=
"#func-current-dateTime"><code>fn:current-dateTime()</code></a>,
<a href="#func-current-date"><code>fn:current-date</code></a> and
<a href="#func-current-time"><code>fn:current-time()</code></a>
whose result depends on the external environment. Where the
function returns nodes, stability means that the returned nodes are
identical, not merely equal and are returned in the same order.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>in the case of <a href=
"#func-collection"><code>fn:collection()</code></a> and <a href=
"#func-doc"><code>fn:doc()</code></a>, the requirement for
stability may be relaxed: see the function definitions for
details.</p>
</div>
<p>Some other functions, for example <a href=
"#func-position"><code>fn:position()</code></a> and <a href=
"#func-last"><code>fn:last()</code></a>, depend on the dynamic
context and may, therefore, produce different results each time
they are called. These functions are said to be
<b>contextual</b>.</p>
</dd>
<dt class="label"><span class="termdef"><a name="uri" id=
"uri"></a>[Definition] <b>URI and URI reference</b></span></dt>
<dd>
<p>Within this specification, the term "URI" refers to Universal
Resource Identifiers as defined in <a href="#rfc3986">[RFC
3986]</a> and extended in <a href="#rfc3987">[RFC 3987]</a> with a
new name "IRI". The term "URI Reference", unless otherwise stated,
refers to a string in the lexical space of the
<code>xs:anyURI</code> datatype as defined in <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>.
Note that this means, in practice, that where this specification
requires a "URI Reference", an IRI as defined in <a href=
"#rfc3987">[RFC 3987]</a> will be accepted, provided that other
relevant specifications also permit an IRI. The term URI has been
retained in preference to IRI to avoid introducing new names for
concepts such as "Base URI" that are defined or referenced across
the whole family of XML specifications. Note also that the
definition of <code>xs:anyURI</code> is a wider definition than the
definition in <a href="#rfc3987">[RFC 3987]</a>; for example it
does not require non-ASCII characters to be escaped.</p>
</dd>
</dl>
</div>
</div>
<div class="div1">
<h2><a name="accessors" id="accessors"></a>2 Accessors</h2>
<p>Accessors and their semantics are described in <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a>. Some
of these accessors are exposed to the user through the functions
described below.</p>
<table summary="Function summary" border="1" width="80%">
<col width="25%" span="1" />
<col width="25%" span="1" />
<col width="25%" span="1" />
<col width="25%" span="1" />
<thead>
<tr>
<th>Function</th>
<th>Accessor</th>
<th>Accepts</th>
<th>Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-node-name"><code>fn:node-name</code></a></td>
<td><code>node-name</code></td>
<td>an optional node</td>
<td>zero or one <code>xs:QName</code></td>
</tr>
<tr>
<td><a href="#func-nilled"><code>fn:nilled</code></a></td>
<td><code>nilled</code></td>
<td>a node</td>
<td>an optional <code>xs:boolean</code></td>
</tr>
<tr>
<td><a href="#func-string"><code>fn:string</code></a></td>
<td><code>string-value</code></td>
<td>an optional item or no argument</td>
<td><code>xs:string</code></td>
</tr>
<tr>
<td><a href="#func-data"><code>fn:data</code></a></td>
<td><code>typed-value</code></td>
<td>zero or more items</td>
<td>a sequence of atomic values</td>
</tr>
<tr>
<td><a href="#func-base-uri"><code>fn:base-uri</code></a></td>
<td><code>base-uri</code></td>
<td>an optional node or no argument</td>
<td>zero or one <code>xs:anyURI</code></td>
</tr>
<tr>
<td><a href=
"#func-document-uri"><code>fn:document-uri</code></a></td>
<td><code>document-uri</code></td>
<td>an optional node</td>
<td>zero or one <code>xs:anyURI</code></td>
</tr>
</tbody>
</table>
<div class="div2">
<h3><a name="func-node-name" id="func-node-name"></a>2.1
fn:node-name</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:node-name</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:QName?</code></div>
</div>
<p>Summary: Returns an expanded-QName for node kinds that can have
names. For other kinds of nodes it returns the empty sequence. If
<code>$arg</code> is the empty sequence, the empty sequence is
returned.</p>
</div>
<div class="div2">
<h3><a name="func-nilled" id="func-nilled"></a>2.2 fn:nilled</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:nilled</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean?</code></div>
</div>
<p>Summary: Returns an <code>xs:boolean</code> indicating whether
the argument node is "nilled". If the argument is not an element
node, returns the empty sequence. If the argument is the empty
sequence, returns the empty sequence.</p>
</div>
<div class="div2">
<h3><a name="func-string" id="func-string"></a>2.3 fn:string</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:string</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto"><code class=
"function">fn:string</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the value of <code>$arg</code> represented as a
<code>xs:string</code>. If no argument is supplied, the context
item (<code>.</code>) is used as the default argument. The behavior
of the function if the argument is omitted is exactly the same as
if the context item had been passed as the argument.</p>
<p>If the context item is undefined, error [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup> is
raised.</p>
<p>If <code>$arg</code> is the empty sequence, the zero-length
string is returned.</p>
<p>If <code>$arg</code> is a node, the function returns the
string-value of the node, as obtained using the
<code>dm:string-value</code> accessor defined in the <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-string-value">Section
5.13 string-value Accessor</a><sup><small>DM</small></sup>.</p>
<p>If <code>$arg</code> is an atomic value, then the function
returns the same string as is returned by the expression "
<code>$arg</code> cast as <code>xs:string</code> " (see <a href=
"#casting"><b>17 Casting</b></a>).</p>
</div>
<div class="div2">
<h3><a name="func-data" id="func-data"></a>2.4 fn:data</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:data</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType*</code></div>
</div>
<p>Summary: <code>fn:data</code> takes a sequence of items and
returns a sequence of atomic values.</p>
<p>The result of <code>fn:data</code> is the sequence of atomic
values produced by applying the following rules to each item in
<code>$arg</code>:</p>
<ul>
<li>
<p>If the item is an atomic value, it is returned.</p>
</li>
<li>
<p>If the item is a node:</p>
<ul>
<li>
<p>If the node does not have a typed value an error is raised
[<a href="#ERRFOTY0012" title="err:FOTY0012">err:FOTY0012</a>].</p>
</li>
<li>
<p>Otherwise, <code>fn:data()</code> returns the typed value of the
node as defined by the accessor function
<code>dm:typed-value</code> in <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-typed-value">Section 5.15
typed-value Accessor</a><sup><small>DM</small></sup>.</p>
</li>
</ul>
</li>
</ul>
</div>
<div class="div2">
<h3><a name="func-base-uri" id="func-base-uri"></a>2.5
fn:base-uri</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:base-uri</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:base-uri</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<p>Summary: Returns the value of the base-uri URI property for
<code>$arg</code> as defined by the accessor function
<code>dm:base-uri()</code> for that kind of node in <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-base-uri">Section 5.2
base-uri Accessor</a><sup><small>DM</small></sup>. If
<code>$arg</code> is not specified, the behavior is identical to
calling the function with the context item (<code>.</code>) as
argument. The following errors may be raised: if the context item
is undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned.</p>
<p>Document, element and processing-instruction nodes have a
base-uri property which may be empty. The base-uri property of all
other node types is the empty sequence. The value of the base-uri
property is returned if it exists and is not empty. Otherwise, if
the node has a parent, the value of <code>dm:base-uri()</code>
applied to its parent is returned, recursively. If the node does
not have a parent, or if the recursive ascent up the ancestor chain
encounters a node whose base-uri property is empty and it does not
have a parent, the empty sequence is returned.</p>
<p>See also <a href=
"#func-static-base-uri"><code>fn:static-base-uri</code></a>.</p>
</div>
<div class="div2">
<h3><a name="func-document-uri" id="func-document-uri"></a>2.6
fn:document-uri</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:document-uri</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<p>Summary: Returns the value of the document-uri property for
<code>$arg</code> as defined by the <code>dm:document-uri</code>
accessor function defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#DocumentNodeAccessors">Section
6.1.2 Accessors</a><sup><small>DM</small></sup>.</p>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned.</p>
<p>Returns the empty sequence if the node is not a document node.
Otherwise, returns the value of the <code>dm:document-uri</code>
accessor of the document node.</p>
<p>In the case of a document node <code>$D</code> returned by the
<a href="#func-doc"><code>fn:doc</code></a> function, or a document
node at the root of a tree containing a node returned by the
<a href="#func-collection"><code>fn:collection</code></a> function,
it will always be true that either <code>fn:document-uri($D)</code>
returns the empty sequence, or that the following expression is
true: <a href=
"#func-doc"><code>fn:doc(fn:document-uri($D))</code></a> is
<code>$D</code>. It is implementation-defined whether this
guarantee also holds for document nodes obtained by other means,
for example a document node passed as the initial context node of a
query or transformation.</p>
</div>
</div>
<div class="div1">
<h2><a name="func-error" id="func-error"></a>3 The Error
Function</h2>
<p>In this document, as well as in <a href="#xquery">[XQuery 1.0:
An XML Query Language]</a>, <a href="#xpath20">[XML Path Language
(XPath) 2.0]</a>, and <a href="#xquery-semantics">[XQuery 1.0 and
XPath 2.0 Formal Semantics]</a>, the phrase "an error is raised" is
used. Raising an error is equivalent to invoking the
<code>fn:error</code> function defined in this section with the
provided error code.</p>
<p>The above phrase is normally accompanied by specification of a
specific error, to wit: "an error is raised [<em>error code</em>]".
Each error defined in this document is identified by an
<code>xs:QName</code> that is in the
<code>http://www.w3.org/2005/xqt-errors</code> namespace,
represented in this document by the <code>err</code> prefix. It is
this <code>xs:QName</code> that is actually passed as an argument
to the <code>fn:error</code> function invocation. Invocation of
this function raises an error. For a more detailed treatment of
error handing, see <a href=
"http://www.w3.org/TR/xpath20/#id-handling-dynamic">Section 2.3.3
Handling Dynamic Errors</a><sup><small>XP</small></sup> and
<a href="http://www.w3.org/TR/xquery-semantics/#sec_fnerror">Section
7.2.9 The fn:error function</a><sup><small>FS</small></sup>.</p>
<p>The <code>fn:error</code> function is a general function that
may be invoked as above but may also be invoked from <a href=
"#xquery">[XQuery 1.0: An XML Query Language]</a> or <a href=
"#xpath20">[XML Path Language (XPath) 2.0]</a> applications with,
for example, an <code>xs:QName</code> argument.</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:error</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">none</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:error</code>(<code class=
"arg">$error</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:QName</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">none</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:error</code>(<code class=
"arg">$error</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:QName?</code>,
<code class="arg">$description</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">none</code></div>
</div>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:error</code>(</td>
<td valign="baseline"><code class="arg">$error</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:QName?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$description</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$error-object</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">none</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: The <code>fn:error</code> function raises an error.
While this function never returns a value, an error is returned to
the external processing environment as an <code>xs:anyURI</code> or
an <code>xs:QName</code>. The error <code>xs:anyURI</code> is
derived from the error <code>xs:QName</code>. An error
<code>xs:QName</code> with namespace URI NS and local part LP will
be returned as the <code>xs:anyURI</code> NS#LP. The method by
which the <code>xs:anyURI</code> or <code>xs:QName</code> is
returned to the external processing environment is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>If an invocation provides <code>$description</code> and
<code>$error-object</code>, then these values may also be returned
to the external processing environment. The method by which these
values are provided to the external environment is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The value of the <code>$description</code> parameter may need to
be localized.</p>
</div>
<p>Note that "none" is a special type defined in <a href=
"#xquery-semantics">[XQuery 1.0 and XPath 2.0 Formal Semantics]</a>
and is not available to the user. It indicates that the function
never returns and ensures that it has the correct static type.</p>
<p>If <code>fn:error</code> is invoked with no arguments, then its
behavior is the same as the invocation of the following
expression:</p>
<div class="exampleInner">
<pre>
fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))
</pre></div>
<p>If the first argument in the third or fourth signature is the
empty sequence it is assumed to be the <code>xs:QName</code>
constructed by:</p>
<div class="exampleInner">
<pre>
fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')
</pre></div>
<div class="div2">
<h3><a name="func-error-examples" id="func-error-examples"></a>3.1
Examples</h3>
<ul>
<li>
<p><code>fn:error()</code> returns
<code>http://www.w3.org/2005/xqt-errors#FOER0000</code> (or the
corresponding <code>xs:QName</code>) to the external processing
environment.</p>
</li>
<li>
<p><code>fn:error(fn:QName('http://www.example.com/HR',
'myerr:toohighsal'), 'Does not apply because salary is too
high')</code> returns
<code>http://www.example.com/HR#toohighsal</code> and the
<code>xs:string</code> <code>"Does not apply because salary is too
high"</code> (or the corresponding <code>xs:QName</code>) to the
external processing environment.</p>
</li>
</ul>
</div>
</div>
<div class="div1">
<h2><a name="func-trace" id="func-trace"></a>4 The Trace
Function</h2>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:trace</code>(<code class=
"arg">$value</code><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,
<code class="arg">$label</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
</div>
<p>Summary: Provides an execution trace intended to be used in
debugging queries.</p>
<p>The input <code>$value</code> is returned, unchanged, as the
result of the function. In addition, the inputs
<code>$value</code>, converted to an <code>xs:string</code>, and
<code>$label</code> may be directed to a trace data set. The
destination of the trace output is <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. The format of the trace output is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>. The ordering of output from invocations of
the <code>fn:trace()</code> function is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="div2">
<h3><a name="func-trace-examples" id="func-trace-examples"></a>4.1
Examples</h3>
<ul>
<li>
<p>Consider a situation in which a user wants to investigate the
actual value passed to a function. Assume that in a particular
execution, <code>$v</code> is an <code>xs:decimal</code> with value
<code>124.84</code>. Writing <code>fn:trace($v, 'the value of $v
is:')</code> will put the strings <code>"124.84"</code> and
<code>"the value of $v is:"</code> in the trace data set in
implementation dependent order.</p>
</li>
</ul>
</div>
</div>
<div class="div1">
<h2><a name="constructor-functions" id=
"constructor-functions"></a>5 Constructor Functions</h2>
<div class="div2">
<h3><a name="constructor-functions-for-xsd-types" id=
"constructor-functions-for-xsd-types"></a>5.1 Constructor Functions
for XML Schema Built-in Types</h3>
<p>Every built-in atomic type that is defined in <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>,
except <code>xs:anyAtomicType</code> and <code>xs:NOTATION</code>,
has an associated constructor function.
<code>xs:untypedAtomic</code>, defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> and the two derived types
<code>xs:yearMonthDuration</code> and
<code>xs:dayTimeDuration</code> defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> also have associated
constructor functions.</p>
<p>A constructor function is not defined for
<code>xs:anyAtomicType</code> as there are no atomic values with
type annotation <code>xs:anyAtomicType</code> at runtime, although
this can be a statically inferred type. A constructor function is
not defined for <code>xs:NOTATION</code> since it is defined as an
abstract type in <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a>. If the static context (See <a href=
"http://www.w3.org/TR/xpath20/#static_context">Section 2.1.1 Static
Context</a><sup><small>XP</small></sup>) contains a type derived
from <code>xs:NOTATION</code> then a constructor function is
defined for it. See <a href=
"#constructor-functions-for-user-defined-types"><b>5.4 Constructor
Functions for User-Defined Types</b></a>.</p>
<p>The form of the constructor function for a type
<em>prefix:TYPE</em> is:</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">prefix:TYPE</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">prefix:TYPE?</code></div>
</div>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned. For example, the signature of the constructor function
corresponding to the <code>xs:unsignedInt</code> type defined in
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> is:</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">xs:unsignedInt</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:unsignedInt?</code></div>
</div>
<p>Invoking the constructor function
<code>xs:unsignedInt(12)</code> returns the
<code>xs:unsignedInt</code> value 12. Another invocation of that
constructor function that returns the same
<code>xs:unsignedInt</code> value is
<code>xs:unsignedInt("12")</code>. The same result would also be
returned if the constructor function were to be invoked with a node
that had a typed value equal to the <code>xs:unsignedInt</code> 12.
The standard features described in <a href=
"http://www.w3.org/TR/xpath20/#id-atomization">Section 2.4.2
Atomization</a><sup><small>XP</small></sup> would 'atomize' the
node to extract its typed value and then call the constructor with
that value. If the value passed to a constructor is illegal for the
datatype to be constructed, an error is raised [<a href=
"#ERRFORG0001" title="err:FORG0001">err:FORG0001</a>].</p>
<p>The semantics of the constructor function "
<code>xs:TYPE(arg)</code> " are identical to the semantics of "
<code>arg</code> cast as <code>xs:TYPE?</code> ". See <a href=
"#casting"><b>17 Casting</b></a>.</p>
<p>If 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.</p>
<p>Special rules apply to constructor functions for
<code>xs:QName</code> and types derived from <code>xs:QName</code>
and <code>xs:NOTATION</code>. See <a href=
"#constructor-qname-notation"><b>5.3 Constructor Functions for
xs:QName and xs:NOTATION</b></a>.</p>
<p>The following constructor functions for the built-in types are
supported:</p>
<ul>
<li>
<div class="proto"><code class=
"function">xs:string</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:boolean</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:decimal</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:float</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:float?</code></div>
<p>Implementations <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> return negative zero for
<code>xs:float("-0.0E0")</code>. <a href="#xmlschema-2">[XML Schema
Part 2: Datatypes Second Edition]</a> does not distinguish between
the values positive zero and negative zero.</p>
</li>
<li>
<div class="proto"><code class=
"function">xs:double</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double?</code></div>
<p>Implementations <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> return negative zero for
<code>xs:double("-0.0E0").</code> <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> does not distinguish
between the values positive zero and negative zero.</p>
</li>
<li>
<div class="proto"><code class=
"function">xs:duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:duration?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:time</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:date</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:gYearMonth</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:gYearMonth?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:gYear</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:gYear?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:gMonthDay</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:gMonthDay?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:gDay</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:gDay?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:gMonth</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:gMonth?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:hexBinary</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:hexBinary?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:base64Binary</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:base64Binary?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:anyURI</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:QName</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:QName?</code></div>
<p>See <a href="#constructor-qname-notation"><b>5.3 Constructor
Functions for xs:QName and xs:NOTATION</b></a> for special
rules.</p>
</li>
</ul>
<ul>
<li>
<div class="proto"><code class=
"function">xs:normalizedString</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:normalizedString?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:token</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:token?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:language</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:language?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:NMTOKEN</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:NMTOKEN?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:Name</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:Name?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:NCName</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:NCName?</code></div>
</li>
<li>
<div class="proto"><code class="function">xs:ID</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:ID?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:IDREF</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:IDREF?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:ENTITY</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:ENTITY?</code></div>
<p>See <a href="#casting-to-ENTITY"><b>17.4.1 Casting to
xs:ENTITY</b></a> for rules related to constructing values of type
<code>xs:ENTITY</code> and types derived from it.</p>
</li>
<li>
<div class="proto"><code class=
"function">xs:integer</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:nonPositiveInteger</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:nonPositiveInteger?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:negativeInteger</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:negativeInteger?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:long</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:long?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:int</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:int?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:short</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:short?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:byte</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:byte?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:nonNegativeInteger</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:nonNegativeInteger?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:unsignedLong</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:unsignedLong?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:unsignedInt</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:unsignedInt?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:unsignedShort</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:unsignedShort?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:unsignedByte</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:unsignedByte?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:positiveInteger</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:positiveInteger?</code></div>
</li>
</ul>
<ul>
<li>
<div class="proto"><code class=
"function">xs:yearMonthDuration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:yearMonthDuration?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:dayTimeDuration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></div>
</li>
<li>
<div class="proto"><code class=
"function">xs:untypedAtomic</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:untypedAtomic?</code></div>
</li>
</ul>
</div>
<div class="div2">
<h3><a name="func-dateTime" id="func-dateTime"></a>5.2 A Special
Constructor Function for xs:dateTime</h3>
<p>A special constructor function is provided for constructing a
<code>xs:dateTime</code> value from a <code>xs:date</code> value
and a <code>xs:time</code> value.</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:dateTime</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:date?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime?</code></div>
</div>
<p>The result <code>xs:dateTime</code> has a date component whose
value is equal to <code>$arg1</code> and a time component whose
value is equal to <code>$arg2</code>. The result is the empty
sequence if either of the parameters is the empty sequence.</p>
<p>The timezone of the result is computed as follows:</p>
<ul>
<li>
<p>If neither argument has a timezone, the result has no
timezone.</p>
</li>
<li>
<p>If exactly one of the arguments has a timezone, or if both
arguments have the same timezone, the result has this timezone.</p>
</li>
<li>
<p>If the two arguments have different timezones, an error is
raised:[<a href="#ERRFORG0008" title=
"err:FORG0008">err:FORG0008</a>]</p>
</li>
</ul>
<div class="div3">
<h4><a name="func-dateTime-examples" id=
"func-dateTime-examples"></a>5.2.1 Examples</h4>
<ul>
<li>
<p><code>fn:dateTime(xs:date("1999-12-31"),
xs:time("12:00:00"))</code> returns
<code>xs:dateTime("1999-12-31T12:00:00").</code></p>
</li>
<li>
<p><code>fn:dateTime(xs:date("1999-12-31"),
xs:time("24:00:00"))</code> returns
<code>xs:dateTime("1999-12-31T00:00:00")</code> because
<code>"24:00:00"</code> is an alternate lexical form for
<code>"00:00:00".</code></p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="constructor-qname-notation" id=
"constructor-qname-notation"></a>5.3 Constructor Functions for
xs:QName and xs:NOTATION</h3>
<p>Special rules apply to constructor functions for the types
<code>xs:QName</code> and <code>xs:NOTATION</code>, for two
reasons:</p>
<ul>
<li>
<p>The lexical representation of these types uses namespace
prefixes, whose meaning is context-dependent.</p>
</li>
<li>
<p>Values cannot belong directly to the type
<code>xs:NOTATION</code>, only to its subtypes.</p>
</li>
</ul>
<p>These constraints result in the following restrictions:</p>
<ul>
<li>
<p>Conversion from an <code>xs:string</code> to a value of type
<code>xs:QName</code>, a type derived from <code>xs:QName</code> or
a type derived from <code>xs:NOTATION</code> is permitted only if
the <code>xs:string</code> is written as a string literal. This
applies whether the conversion is expressed using a constructor
function or using the "cast as" syntax. Such a conversion can be
regarded as a pseudo-function, which is always evaluated
statically. It is also permitted for these constructors and casts
to take a dynamically-supplied argument in the normal manner, but
as the casting table (see <a href=
"#casting-from-primitive-to-primitive"><b>17.1 Casting from
primitive types to primitive types</b></a>) indicates, the only
arguments that are supported in this case are values of type
<code>xs:QName</code> or <code>xs:NOTATION</code> respectively.</p>
</li>
<li>
<p>There is no constructor function for <code>xs:NOTATION</code>.
Constructors are defined, however, for <code>xs:QName</code>, for
types derived from <code>xs:QName</code>, and for types derived
from <code>xs:NOTATION</code>.</p>
</li>
</ul>
<p>When converting from an <code>xs:string</code>, the prefix
within the lexical <code>xs:QName</code> supplied as the argument
is resolved to a namespace URI using the statically known
namespaces from the static context. If the lexical
<code>xs:QName</code> has no prefix, the namespace URI of the
resulting expanded-QName is the default element/type namespace from
the static context. Components of the static context are discussed
in <a href="http://www.w3.org/TR/xpath20/#static_context">Section
2.1.1 Static Context</a><sup><small>XP</small></sup>. A static
error is raised [<a href="#ERRFONS0004" title=
"err:FONS0004">err:FONS0004</a>] if the prefix is not bound in the
static context. As described in <a href=
"http://www.w3.org/TR/xpath-datamodel/#terminology">Section 2.1
Terminology</a><sup><small>DM</small></sup>, the supplied prefix is
retained as part of the expanded-QName value.</p>
</div>
<div class="div2">
<h3><a name="constructor-functions-for-user-defined-types" id=
"constructor-functions-for-user-defined-types"></a>5.4 Constructor
Functions for User-Defined Types</h3>
<p>For every atomic type in the static context (See <a href=
"http://www.w3.org/TR/xpath20/#static_context">Section 2.1.1 Static
Context</a><sup><small>XP</small></sup>) that is derived from a
primitive type, there is a constructor function (whose name is the
same as the name of the type) whose effect is to create a value of
that type from the supplied argument. The rules for constructing
user-defined types are defined in the same way as the rules for
constructing built-in derived types discussed in <a href=
"#constructor-functions-for-xsd-types"><b>5.1 Constructor Functions
for XML Schema Built-in Types</b></a>.</p>
<p>Special rules apply to constructor functions for types derived
from <code>xs:QName</code> and <code>xs:NOTATION</code>. See
<a href="#constructor-qname-notation"><b>5.3 Constructor Functions
for xs:QName and xs:NOTATION</b></a>.</p>
<p>Consider a situation where the static context contains a type
called <code>hatSize</code> defined in a schema whose target
namespace is bound to the prefix <code>my</code>. In such a case
the constructor function:</p>
<div class="exampleInner">
<div class="proto"><code class=
"function">my:hatSize</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">my:hatSize?</code></div>
</div>
<p>is available to users.</p>
<p>To construct an instance of an atomic type that is not in a
namespace, it is necessary to use a cast expression or undeclare
the default function namespace. For example, if the user-defined
type <code>apple</code> is derived from <code>xs:integer</code> but
is not in a namespace, an instance of this type can be constructed
as follows using a cast expression (this requires that the default
element/type namespace is no namespace):</p>
<div class="exampleInner">
<pre>
17 cast as apple
</pre></div>
<p>The following shows the use of the constructor function:</p>
<div class="exampleInner">
<pre>
declare default function namespace ""; apple(17)
</pre></div>
</div>
</div>
<div class="div1">
<h2><a name="numeric-functions" id="numeric-functions"></a>6
Functions and Operators on Numerics</h2>
<p>This section discusses arithmetic operators on the numeric
datatypes defined in <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a>. It uses an approach that permits
lightweight implementation whenever possible.</p>
<div class="div2">
<h3><a name="numeric-types" id="numeric-types"></a>6.1 Numeric
Types</h3>
<p>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 indentation.</p>
<table class="hierarchy" summary="Numeric types" border="0" width=
"288">
<tbody>
<tr>
<td class="castOther" align="left" valign="middle">xs:decimal</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:integer</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:float</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle">xs:double</td>
</tr>
</tbody>
</table>
<p>They also apply to types derived by restriction from the above
types.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This specification uses <a href="#ieee754">[IEEE 754-1985]</a>
arithmetic for <code>xs:float</code> and <code>xs:double</code>
values. This differs from <a href="#xmlschema-2">[XML Schema Part
2: Datatypes Second Edition]</a> which defines <code>NaN</code> as
being equal to itself and defines only a single zero in the value
space while <a href="#ieee754">[IEEE 754-1985]</a> arithmetic
treats <code>NaN</code> as unequal to all other values including
itself and can produce distinct results of positive zero and
negative zero. (These are two different machine representations for
the same <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a> value.) The text accompanying several functions
discusses behaviour for both positive and negative zero inputs and
outputs in the interest of alignment with <a href="#ieee754">[IEEE
754-1985]</a>.</p>
</div>
</div>
<div class="div2">
<h3><a name="op.numeric" id="op.numeric"></a>6.2 Operators on
Numeric Values</h3>
<p>The following functions define the semantics of operators
defined in <a href="#xquery">[XQuery 1.0: An XML Query
Language]</a> and <a href="#xpath20">[XML Path Language (XPath)
2.0]</a> on these numeric types.</p>
<table summary="Operator summary" border="1">
<thead>
<tr>
<th>Operators</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-numeric-add"><code>op:numeric-add</code></a></td>
<td>Addition</td>
</tr>
<tr>
<td><a href=
"#func-numeric-subtract"><code>op:numeric-subtract</code></a></td>
<td>Subtraction</td>
</tr>
<tr>
<td><a href=
"#func-numeric-multiply"><code>op:numeric-multiply</code></a></td>
<td>Multiplication</td>
</tr>
<tr>
<td><a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a></td>
<td>Division</td>
</tr>
<tr>
<td><a href=
"#func-numeric-integer-divide"><code>op:numeric-integer-divide</code></a></td>
<td>Integer division</td>
</tr>
<tr>
<td><a href=
"#func-numeric-mod"><code>op:numeric-mod</code></a></td>
<td>Modulus</td>
</tr>
<tr>
<td><a href=
"#func-numeric-unary-plus"><code>op:numeric-unary-plus</code></a></td>
<td>Unary plus</td>
</tr>
<tr>
<td><a href=
"#func-numeric-unary-minus"><code>op:numeric-unary-minus</code></a></td>
<td>Unary minus (negation)</td>
</tr>
</tbody>
</table>
<p>The parameters and return types for the above operators are the
basic numeric types: <code>xs:integer</code>,
<code>xs:decimal</code>, <code>xs:float</code> and
<code>xs:double</code>, and types derived from them. The word
"<code>numeric</code>" in function signatures signifies these four
types. For simplicity, each operator is defined to operate on
operands of the same type and return the same type. The exceptions
are <a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a>, which
returns an <code>xs:decimal</code> if called with two
<code>xs:integer</code> operands and <a href=
"#func-numeric-integer-divide"><code>op:numeric-integer-divide</code></a>
which always returns an <code>xs:integer</code>.</p>
<p>If the two operands are not of the same type, <em>subtype
substitution</em> and <em>numeric type promotion</em> are used to
obtain two operands of the same type. <a href=
"http://www.w3.org/TR/xpath20/#promotion">Section B.1 Type
Promotion</a><sup><small>XP</small></sup> and <a href=
"http://www.w3.org/TR/xpath20/#mapping">Section B.2 Operator
Mapping</a><sup><small>XP</small></sup> describe the semantics of
these operations in detail.</p>
<p>The result type of operations depends on their argument
datatypes and is defined in the following table:</p>
<table summary="Function/operator summary" border="1">
<col width="50%" span="1" />
<col width="50%" span="1" />
<thead>
<tr>
<th>Operator</th>
<th>Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>op:operation(xs:integer, xs:integer)</code></td>
<td><code>xs:integer</code> (except for <a href=
"#func-numeric-divide"><code>op:numeric-divide(integer,
integer)</code></a>, which returns <code>xs:decimal</code>)</td>
</tr>
<tr>
<td><code>op:operation(xs:decimal, xs:decimal)</code></td>
<td><code>xs:decimal</code></td>
</tr>
<tr>
<td><code>op:operation(xs:float, xs:float)</code></td>
<td><code>xs:float</code></td>
</tr>
<tr>
<td><code>op:operation(xs:double, xs:double)</code></td>
<td><code>xs:double</code></td>
</tr>
<tr>
<td><code>op:operation(xs:integer)</code></td>
<td><code>xs:integer</code></td>
</tr>
<tr>
<td><code>op:operation(xs:decimal)</code></td>
<td><code>xs:decimal</code></td>
</tr>
<tr>
<td><code>op:operation(xs:float)</code></td>
<td><code>xs:float</code></td>
</tr>
<tr>
<td><code>op:operation(xs:double)</code></td>
<td><code>xs:double</code></td>
</tr>
</tbody>
</table>
<p>These rules define any operation on any pair of arithmetic
types. Consider the following example:</p>
<div class="exampleInner">
<pre>
op:operation(xs:int, xs:double) =&gt; op:operation(xs:double, xs:double)
</pre></div>
<p>For this operation, <code>xs:int</code> must be converted to
<code>xs:double</code>. This can be done, since by the rules above:
<code>xs:int</code> can be substituted for <code>xs:integer</code>,
<code>xs:integer</code> can be substituted for
<code>xs:decimal</code>, <code>xs:decimal</code> can be promoted to
<code>xs:double</code>. As far as possible, the promotions should
be done in a single step. Specifically, when an
<code>xs:decimal</code> is promoted to an <code>xs:double</code>,
it should not be converted to an <code>xs:float</code> and then to
<code>xs:double</code>, as this risks loss of precision.</p>
<p>As another example, a user may define <code>height</code> as a
derived type of <code>xs:integer</code> with a minimum value of 20
and a maximum value of 100. He may then derive
<code>fenceHeight</code> using an enumeration to restrict the
permitted set of values to, say, 36, 48 and 60.</p>
<div class="exampleInner">
<pre>
op:operation(fenceHeight, xs:integer) =&gt; op:operation(xs:integer, xs:integer)
</pre></div>
<p><code>fenceHeight</code> can be substituted for its base type
<code>height</code> and <code>height</code> can be substituted for
its base type <code>xs:integer</code>.</p>
<p>On overflow and underflow situations during arithmetic
operations conforming implementations <a title="must" class=
"termref" href="#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> behave as follows:</p>
<ul>
<li>
<p>For <code>xs:float</code> and <code>xs:double</code> operations,
overflow behavior <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> be conformant with <a href="#ieee754">[IEEE
754-1985]</a>. This specification allows the following options:</p>
<ul>
<li>
<p>Raising an error [<a href="#ERRFOAR0002" title=
"err:FOAR0002">err:FOAR0002</a>] via an overflow trap.</p>
</li>
<li>
<p>Returning <code>INF</code> or <code>-INF</code>.</p>
</li>
<li>
<p>Returning the largest (positive or negative) non-infinite
number.</p>
</li>
</ul>
</li>
<li>
<p>For <code>xs:float</code> and <code>xs:double</code> operations,
underflow behavior <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> be conformant with <a href="#ieee754">[IEEE
754-1985]</a>. This specification allows the following options:</p>
<ul>
<li>
<p>Raising an error [<a href="#ERRFOAR0002" title=
"err:FOAR0002">err:FOAR0002</a>] via an underflow trap.</p>
</li>
<li>
<p>Returning <code>0.0E0</code> or <code>+/- 2**Emin</code> or a
denormalized value; where <code>Emin</code> is the smallest
possible <code>xs:float</code> or <code>xs:double</code>
exponent.</p>
</li>
</ul>
</li>
<li>
<p>For <code>xs:decimal</code> operations, overflow behavior
<a title="must" class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> raise an error
[<a href="#ERRFOAR0002" title="err:FOAR0002">err:FOAR0002</a>]. On
underflow, <code>0.0</code> must be returned.</p>
</li>
<li>
<p>For <code>xs:integer</code> operations, implementations that
support limited-precision integer operations <a title="must" class=
"termref" href="#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> select from the following options:</p>
<ul>
<li>
<p>They <a title="may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> choose to
always raise an error [<a href="#ERRFOAR0002" title=
"err:FOAR0002">err:FOAR0002</a>].</p>
</li>
<li>
<p>They <a title="may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> provide an
<a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> mechanism that allows users to choose between
raising an error and returning a result that is modulo the largest
representable integer value. See <a href="#ISO10967">[ISO
10967]</a>.</p>
</li>
</ul>
</li>
</ul>
<p>The functions <a href=
"#func-numeric-add"><code>op:numeric-add</code></a>, <a href=
"#func-numeric-subtract"><code>op:numeric-subtract</code></a>,
<a href=
"#func-numeric-multiply"><code>op:numeric-multiply</code></a>,
<a href="#func-numeric-divide"><code>op:numeric-divide</code></a>,
<a href=
"#func-numeric-integer-divide"><code>op:numeric-integer-divide</code></a>
and <a href="#func-numeric-mod"><code>op:numeric-mod</code></a> are
each defined for pairs of numeric operands, each of which has the
same type:<code>xs:integer</code>, <code>xs:decimal</code>,
<code>xs:float</code>, or <code>xs:double</code>. The functions
<a href=
"#func-numeric-unary-plus"><code>op:numeric-unary-plus</code></a>
and <a href=
"#func-numeric-unary-minus"><code>op:numeric-unary-minus</code></a>
are defined for a single operand whose type is one of those same
numeric types.</p>
<p>For <code>xs:float</code> and <code>xs:double</code> arguments,
if either argument is <code>NaN</code>, the result is
<code>NaN</code>.</p>
<p>For <code>xs:decimal</code> values the number of digits of
precision returned by the numeric operators is <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. If the number of digits in the result exceeds
the number of digits that the implementation supports, the result
is truncated or rounded in an <a title="implementation-defined"
class="termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> manner.</p>
<div class="div3">
<h4><a name="func-numeric-add" id="func-numeric-add"></a>6.2.1
op:numeric-add</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-add</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the "+" operator and returns the arithmetic
sum of its operands: (<code>$arg1 + $arg2</code>).</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>For <code>xs:float</code> or <code>xs:double</code> values, if
one of the operands is a zero or a finite number and the other is
<code>INF</code> or <code>-INF</code>, <code>INF</code> or
<code>-INF</code> is returned. If both operands are
<code>INF</code>, <code>INF</code> is returned. If both operands
are <code>-INF</code>, <code>-INF</code> is returned. If one of the
operands is <code>INF</code> and the other is <code>-INF</code>,
<code>NaN</code> is returned.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-subtract" id=
"func-numeric-subtract"></a>6.2.2 op:numeric-subtract</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-subtract</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the "-" operator and returns the arithmetic
difference of its operands: (<code>$arg1 - $arg2</code>).</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>For <code>xs:float</code> or <code>xs:double</code> values, if
one of the operands is a zero or a finite number and the other is
<code>INF</code> or <code>-INF</code>, an infinity of the
appropriate sign is returned. If both operands are <code>INF</code>
or <code>-INF</code>, <code>NaN</code> is returned. If one of the
operands is <code>INF</code> and the other is <code>-INF</code>, an
infinity of the appropriate sign is returned.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-multiply" id=
"func-numeric-multiply"></a>6.2.3 op:numeric-multiply</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-multiply</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the "*" operator and returns the arithmetic
product of its operands: (<code>$arg1 * $arg2</code>).</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>For <code>xs:float</code> or <code>xs:double</code> values, if
one of the operands is a zero and the other is an infinity,
<code>NaN</code> is returned. If one of the operands is a non-zero
number and the other is an infinity, an infinity with the
appropriate sign is returned.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-divide" id=
"func-numeric-divide"></a>6.2.4 op:numeric-divide</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-divide</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the "div" operator and returns the arithmetic
quotient of its operands: (<code>$arg1 div $arg2</code>).</p>
<p>As a special case, if the types of both <code>$arg1</code> and
<code>$arg2</code> are <code>xs:integer</code>, then the return
type is <code>xs:decimal</code>.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>For <code>xs:decimal</code> and <code>xs:integer</code>
operands, if the divisor is (positive or negative) zero, an error
is raised [<a href="#ERRFOAR0001" title=
"err:FOAR0001">err:FOAR0001</a>]. For <code>xs:float</code> and
<code>xs:double</code> operands, floating point division is
performed as specified in <a href="#ieee754">[IEEE
754-1985]</a>.</p>
<p>For <code>xs:float</code> or <code>xs:double</code> values, a
positive number divided by positive zero returns <code>INF</code>.
A negative number divided by positive zero returns
<code>-INF</code>. Division by negative zero returns
<code>-INF</code> and <code>INF</code>, respectively. Positive or
negative zero divided by positive or negative zero returns
<code>NaN</code>. Also, <code>INF</code> or <code>-INF</code>
divided by <code>INF</code> or <code>-INF</code> returns
<code>NaN</code>.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-integer-divide" id=
"func-numeric-integer-divide"></a>6.2.5
op:numeric-integer-divide</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-integer-divide</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<p>Summary: This function backs up the "idiv" operator and performs
an integer division: that is, it divides the first argument by the
second, and returns the integer obtained by truncating the
fractional part of the result. The division is performed so that
the sign of the fractional part is the same as the sign of the
dividend.</p>
<p>If the dividend, <code>$arg1</code>, is not evenly divided by
the divisor, <code>$arg2</code>, then the quotient is the
<code>xs:integer</code> value obtained, ignoring (truncating) any
remainder that results from the division (that is, no rounding is
performed). Thus, the semantics " <code>$a idiv $b</code> " are
equivalent to " <code>($a div $b) cast as xs:integer</code> "
except for error situations.</p>
<p>If the divisor is (positive or negative) zero, then an error is
raised [<a href="#ERRFOAR0001" title=
"err:FOAR0001">err:FOAR0001</a>]. If either operand is
<code>NaN</code> or if <code>$arg1</code> is <code>INF</code> or
<code>-INF</code> then an error is raised [<a href="#ERRFOAR0002"
title="err:FOAR0002">err:FOAR0002</a>].</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The semantics of this function are different from integer
division as defined in programming languages such as Java and
C++.</p>
</div>
<div class="div4">
<h5><a name="func-numeric-integer-divide-examples" id=
"func-numeric-integer-divide-examples"></a>6.2.5.1 Examples</h5>
<ul>
<li>
<p><code>op:numeric-integer-divide(10,3)</code> returns
<code>3</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(3,-2)</code> returns
<code>-1</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(-3,2)</code> returns
<code>-1</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(-3,-2)</code> returns
<code>1</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(9.0,3)</code> returns
<code>3</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(-3.5,3)</code> returns
<code>-1</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(3.0,4)</code> returns
<code>0</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(3.1E1,6)</code> returns
<code>5</code></p>
</li>
<li>
<p><code>op:numeric-integer-divide(3.1E1,7)</code> returns
<code>4</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-mod" id="func-numeric-mod"></a>6.2.6
op:numeric-mod</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-mod</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the "mod" operator. Informally, this function
returns the remainder resulting from dividing <code>$arg1</code>,
the dividend, by <code>$arg2</code>, the divisor. The operation
<code>a mod b</code> for operands that are <code>xs:integer</code>
or <code>xs:decimal</code>, or types derived from them, produces a
result such that <code>(a idiv b)*b+(a mod b)</code> is equal to
<code>a</code> and the magnitude of the result is always less than
the magnitude of <code>b</code>. This identity holds even in the
special case that the dividend is the negative integer of largest
possible magnitude for its type and the divisor is -1 (the
remainder is 0). It follows from this rule that the sign of the
result is the sign of the dividend.</p>
<p>For <code>xs:integer</code> and <code>xs:decimal</code>
operands, if <code>$arg2</code> is zero, then an error is raised
[<a href="#ERRFOAR0001" title="err:FOAR0001">err:FOAR0001</a>].</p>
<p>For <code>xs:float</code> and <code>xs:double</code> operands
the following rules apply:</p>
<ul>
<li>
<p>If either operand is <code>NaN</code>, the result is
<code>NaN</code>.</p>
</li>
<li>
<p>If the dividend is positive or negative infinity, or the divisor
is positive or negative zero (0), or both, the result is
<code>NaN</code>.</p>
</li>
<li>
<p>If the dividend is finite and the divisor is an infinity, the
result equals the dividend.</p>
</li>
<li>
<p>If the dividend is positive or negative zero and the divisor is
finite, the result is the same as the dividend.</p>
</li>
<li>
<p>In the remaining cases, where neither positive or negative
infinity, nor positive or negative zero, nor <code>NaN</code> is
involved, the result obeys <code>(a idiv b)*b+(a mod b)</code> =
<code>a</code>. Division is truncating division, analogous to
integer division, not <a href="#ieee754">[IEEE 754-1985]</a>
rounding division i.e. additional digits are truncated, not rounded
to the required precision.</p>
</li>
</ul>
<div class="div4">
<h5><a name="func-numeric-mod-examples" id=
"func-numeric-mod-examples"></a>6.2.6.1 Examples</h5>
<ul>
<li>
<p><code>op:numeric-mod(10,3)</code> returns <code>1</code>.</p>
</li>
<li>
<p><code>op:numeric-mod(6,-2)</code> returns <code>0</code>.</p>
</li>
<li>
<p><code>op:numeric-mod(4.5,1.2)</code> returns
<code>0.9</code>.</p>
</li>
<li>
<p><code>op:numeric-mod(1.23E2, 0.6E1)</code> returns
<code>3.0E0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-numeric-unary-plus" id=
"func-numeric-unary-plus"></a>6.2.7 op:numeric-unary-plus</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-unary-plus</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the unary "+" operator and returns its operand
with the sign unchanged: (+ <code>$arg</code>). Semantically, this
operation performs no operation.</p>
</div>
<div class="div3">
<h4><a name="func-numeric-unary-minus" id=
"func-numeric-unary-minus"></a>6.2.8 op:numeric-unary-minus</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-unary-minus</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric</code></div>
</div>
<p>Summary: Backs up the unary "-" operator and returns its operand
with the sign reversed: (- <code>$arg</code>). If <code>$arg</code>
is positive, its negative is returned; if it is negative, its
positive is returned.</p>
<p>For <code>xs:integer</code> and <code>xs:decimal</code>
arguments, <code>0</code> and <code>0.0</code> return
<code>0</code> and <code>0.0</code>, respectively. For
<code>xs:float</code> and <code>xs:double</code> arguments,
<code>NaN</code> returns <code>NaN</code>, <code>0.0E0</code>
returns <code>-0.0E0</code> and vice versa. <code>INF</code>
returns <code>-INF</code>. <code>-INF</code> returns
<code>INF</code>.</p>
</div>
</div>
<div class="div2">
<h3><a name="comp.numeric" id="comp.numeric"></a>6.3 Comparison
Operators on Numeric Values</h3>
<p>This specification defines 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 as described above in <a href=
"#op.numeric"><b>6.2 Operators on Numeric Values</b></a>. Each
comparison operator returns a boolean value. If either, or both,
operands are <code>NaN</code>, <code>false</code> is returned.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-numeric-equal"><code>op:numeric-equal</code></a></td>
<td>Equality comparison</td>
</tr>
<tr>
<td><a href=
"#func-numeric-less-than"><code>op:numeric-less-than</code></a></td>
<td>Less-than comparison</td>
</tr>
<tr>
<td><a href=
"#func-numeric-greater-than"><code>op:numeric-greater-than</code></a></td>
<td>Greater-than comparison</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-numeric-equal" id="func-numeric-equal"></a>6.3.1
op:numeric-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns true if and only if the value of
<code>$arg1</code> is equal to the value of <code>$arg2</code>. For
<code>xs:float</code> and <code>xs:double</code> values, positive
zero and negative zero compare equal. <code>INF</code> equals
<code>INF</code> and <code>-INF</code> equals <code>-INF</code>.
<code>NaN</code> does not equal itself.</p>
<p>This function backs up the "eq", "ne", "le" and "ge" operators
on numeric values.</p>
</div>
<div class="div3">
<h4><a name="func-numeric-less-than" id=
"func-numeric-less-than"></a>6.3.2 op:numeric-less-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-less-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is less than <code>$arg2</code>. For
<code>xs:float</code> and <code>xs:double</code> values, positive
infinity is greater than all other non-<code>NaN</code> values;
negative infinity is less than all other non-<code>NaN</code>
values. If <code>$arg1</code> or <code>$arg2</code> is
<code>NaN</code>, the function returns <code>false</code>.</p>
<p>This function backs up the "lt" and "le" operators on numeric
values.</p>
</div>
<div class="div3">
<h4><a name="func-numeric-greater-than" id=
"func-numeric-greater-than"></a>6.3.3 op:numeric-greater-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:numeric-greater-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">numeric</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is greater than <code>$arg2</code>. For
<code>xs:float</code> and <code>xs:double</code> values, positive
infinity is greater than all other non-<code>NaN</code> values;
negative infinity is less than all other non-<code>NaN</code>
values. If <code>$arg1</code> or <code>$arg2</code> is
<code>NaN</code>, the function returns <code>false</code>.</p>
<p>This function backs up the "gt" and "ge" operators on numeric
values.</p>
</div>
</div>
<div class="div2">
<h3><a name="numeric-value-functions" id=
"numeric-value-functions"></a>6.4 Functions on Numeric Values</h3>
<p>The following functions are defined on numeric types. Each
function returns a value of the same type as the type of its
argument.</p>
<ul>
<li>
<p>If the argument is the empty sequence, the empty sequence is
returned.</p>
</li>
<li>
<p>For <code>xs:float</code> and <code>xs:double</code> arguments,
if the argument is "NaN", "NaN" is returned.</p>
</li>
<li>
<p>Except for <a href="#func-abs"><code>fn:abs()</code></a>, for
<code>xs:float</code> and <code>xs:double</code> arguments, if the
argument is positive or negative infinity, positive or negative
infinity is returned.</p>
</li>
</ul>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-abs"><code>fn:abs</code></a></td>
<td>Returns the absolute value of the argument.</td>
</tr>
<tr>
<td><a href="#func-ceiling"><code>fn:ceiling</code></a></td>
<td>Returns the smallest number with no fractional part that is
greater than or equal to the argument.</td>
</tr>
<tr>
<td><a href="#func-floor"><code>fn:floor</code></a></td>
<td>Returns the largest number with no fractional part that is less
than or equal to the argument.</td>
</tr>
<tr>
<td><a href="#func-round"><code>fn:round</code></a></td>
<td>Rounds to the nearest number with no fractional part.</td>
</tr>
<tr>
<td><a href=
"#func-round-half-to-even"><code>fn:round-half-to-even</code></a></td>
<td>Takes a number and a precision and returns a number rounded to
the given precision. If the fractional part is exactly half, the
result is the number whose least significant digit is even.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-abs" id="func-abs"></a>6.4.1 fn:abs</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:abs</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<p>Summary: Returns the absolute value of <code>$arg</code>. If
<code>$arg</code> is negative returns <code>-$arg</code> otherwise
returns <code>$arg</code>. If type of <code>$arg</code> is one of
the four numeric types <code>xs:float</code>,
<code>xs:double</code>, <code>xs:decimal</code> or
<code>xs:integer</code> the type of the result is the same as the
type of <code>$arg</code>. If the type of <code>$arg</code> is a
type derived from one of the numeric types, the result is an
instance of the base numeric type.</p>
<p>For <code>xs:float</code> and <code>xs:double</code> arguments,
if the argument is positive zero or negative zero, then positive
zero is returned. If the argument is positive or negative infinity,
positive infinity is returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_abs_ceil_floor_round">
Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and
fn:round-half-to-even functions</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-abs-examples" id="func-abs-examples"></a>6.4.1.1
Examples</h5>
<ul>
<li>
<p><code>fn:abs(10.5)</code> returns <code>10.5</code>.</p>
</li>
<li>
<p><code>fn:abs(-10.5)</code> returns <code>10.5</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-ceiling" id="func-ceiling"></a>6.4.2
fn:ceiling</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:ceiling</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<p>Summary: Returns the smallest (closest to negative infinity)
number with no fractional part that is not less than the value of
<code>$arg</code>. If type of <code>$arg</code> is one of the four
numeric types <code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> the type of the
result is the same as the type of <code>$arg</code>. If the type of
<code>$arg</code> is a type derived from one of the numeric types,
the result is an instance of the base numeric type.</p>
<p>For <code>xs:float</code> and <code>xs:double</code> arguments,
if the argument is positive zero, then positive zero is returned.
If the argument is negative zero, then negative zero is returned.
If the argument is less than zero and greater than -1, negative
zero is returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_abs_ceil_floor_round">
Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and
fn:round-half-to-even functions</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-ceiling-examples" id=
"func-ceiling-examples"></a>6.4.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:ceiling(10.5)</code> returns <code>11</code>.</p>
</li>
<li>
<p><code>fn:ceiling(-10.5)</code> returns <code>-10</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-floor" id="func-floor"></a>6.4.3 fn:floor</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:floor</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<p>Summary: Returns the largest (closest to positive infinity)
number with no fractional part that is not greater than the value
of <code>$arg</code>. If type of <code>$arg</code> is one of the
four numeric types <code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> the type of the
result is the same as the type of <code>$arg</code>. If the type of
<code>$arg</code> is a type derived from one of the numeric types,
the result is an instance of the base numeric type.</p>
<p>For <code>float</code> and <code>double</code> arguments, if the
argument is positive zero, then positive zero is returned. If the
argument is negative zero, then negative zero is returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_abs_ceil_floor_round">
Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and
fn:round-half-to-even functions</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-floor-examples" id=
"func-floor-examples"></a>6.4.3.1 Examples</h5>
<ul>
<li>
<p><code>fn:floor(10.5)</code> returns <code>10</code>.</p>
</li>
<li>
<p><code>fn:floor(-10.5)</code> returns <code>-11</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-round" id="func-round"></a>6.4.4 fn:round</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:round</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<p>Summary: Returns the number with no fractional part that is
closest to the argument. If there are two such numbers, then the
one that is closest to positive infinity is returned. If type of
<code>$arg</code> is one of the four numeric types
<code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> the type of the
result is the same as the type of <code>$arg</code>. If the type of
<code>$arg</code> is a type derived from one of the numeric types,
the result is an instance of the base numeric type.</p>
<p>For <code>xs:float</code> and <code>xs:double</code> arguments,
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, then
positive zero is returned. If the argument is negative zero, then
negative zero is returned. If the argument is less than zero, but
greater than or equal to -0.5, then negative zero is returned. In
the cases where positive zero or negative zero is returned,
negative zero or positive zero may be returned as <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
does not distinguish between the values positive zero and negative
zero.</p>
<p>For the last two cases, note that the result is not the same as
<a href="#func-floor"><code>fn:floor(x+0.5)</code></a>.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_abs_ceil_floor_round">
Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and
fn:round-half-to-even functions</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-round-examples" id=
"func-round-examples"></a>6.4.4.1 Examples</h5>
<ul>
<li>
<p><code>fn:round(2.5)</code> returns <code>3.</code></p>
</li>
<li>
<p><code>fn:round(2.4999)</code> returns <code>2</code>.</p>
</li>
<li>
<p><code>fn:round(-2.5)</code> returns <code>-2</code> (not the
possible alternative, <code>-3</code>).</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-round-half-to-even" id=
"func-round-half-to-even"></a>6.4.5 fn:round-half-to-even</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:round-half-to-even</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:round-half-to-even</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>, <code class=
"arg">$precision</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:integer</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</div>
<p>Summary: The value returned is the nearest (that is, numerically
closest) value to <code>$arg</code> that is a multiple of ten to
the power of minus <code>$precision</code>. If two such values are
equally near (e.g. if the fractional part in <code>$arg</code> is
exactly .500...), the function returns the one whose least
significant digit is even.</p>
<p>If the type of <code>$arg</code> is one of the four numeric
types <code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> the type of the
result is the same as the type of <code>$arg</code>. If the type of
<code>$arg</code> is a type derived from one of the numeric types,
the result is an instance of the base numeric type.</p>
<p>The first signature of this function produces the same result as
the second signature with <code>$precision=0</code>.</p>
<p>For arguments of type <code>xs:float</code> and
<code>xs:double</code>, if the argument is <code>NaN</code>,
positive or negative zero, or positive or negative infinity, then
the result is the same as the argument. In all other cases, the
argument is cast to <code>xs:decimal</code>, the function is
applied to this <code>xs:decimal</code> value, and the resulting
<code>xs:decimal</code> is cast back to <code>xs:float</code> or
<code>xs:double</code> as appropriate to form the function result.
If the resulting <code>xs:decimal</code> value is zero, then
positive or negative zero is returned according to the sign of the
original argument.</p>
<p>Note that the process of casting to <code>xs:decimal</code> may
result in an error [<a href="#ERRFOCA0001" title=
"err:FOCA0001">err:FOCA0001</a>].</p>
<p>If <code>$arg</code> is of type <code>xs:float</code> or
<code>xs:double</code>, rounding occurs on the value of the
mantissa computed with exponent = 0.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_abs_ceil_floor_round">
Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and
fn:round-half-to-even functions</a><sup><small>FS</small></sup></p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This function is typically used in financial applications where
the argument is of type <code>xs:decimal</code>. For arguments of
type <code>xs:float</code> and <code>xs:double</code> the results
may be counterintuitive. For example, consider
<code>round-half-to-even(xs:float(150.0150), 2)</code>.</p>
<p>An implementation that supports 18 digits for
<code>xs:decimal</code> will convert the argument to the
<code>xs:decimal</code> 150.014999389... which will then be rounded
to the <code>xs:decimal</code> 150.01 which will be converted back
to the <code>xs:float</code> whose exact value is 150.0099945068...
whereas <code>round-half-to-even(xs:decimal(150.0150), 2)</code>
will result in the <code>xs:decimal</code> whose exact value is
150.02.</p>
</div>
<div class="div4">
<h5><a name="func-round-half-to-even-examples" id=
"func-round-half-to-even-examples"></a>6.4.5.1 Examples</h5>
<ul>
<li>
<p><code>fn:round-half-to-even(0.5)</code> returns
<code>0</code>.</p>
</li>
<li>
<p><code>fn:round-half-to-even(1.5)</code> returns
<code>2</code>.</p>
</li>
<li>
<p><code>fn:round-half-to-even(2.5)</code> returns
<code>2</code>.</p>
</li>
<li>
<p><code>fn:round-half-to-even(3.567812E+3, 2)</code> returns
<code>3567.81E0</code>.</p>
</li>
<li>
<p><code>fn:round-half-to-even(4.7564E-3, 2)</code> returns
<code>0.0E0</code>.</p>
</li>
<li>
<p><code>fn:round-half-to-even(35612.25, -2)</code> returns
<code>35600</code>.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="string-functions" id="string-functions"></a>7
Functions on Strings</h2>
<p>This section discusses functions and operators on the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
<code>xs:string</code> datatype and the datatypes derived from
it.</p>
<div class="div2">
<h3><a name="string-types" id="string-types"></a>7.1 String
Types</h3>
<p>The operators described in this section are defined on the
following types. Each type whose name is indented is derived from
the type whose name appears nearest above with one less level of
indentation.</p>
<table class="hierarchy" summary="Type summary" border="0">
<tbody>
<tr>
<td class="castOther" align="left" valign="middle">xs:string</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">
xs:normalizedString</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:token</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:language</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:NMTOKEN</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:Name</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:NCName</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:ID</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:IDREF</td>
</tr>
<tr>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle"></td>
<td class="castOther" align="left" valign="middle">xs:ENTITY</td>
</tr>
</tbody>
</table>
<p>They also apply to user-defined types derived by restriction
from the above types.</p>
<p>It is <a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> which version of <a href="#Unicode4">[The
Unicode Standard]</a> is supported, but it is recommended that the
most recent version of Unicode be used.</p>
<p>Unless explicitly stated, the <code>xs:string</code> values
returned by the functions in this document are not normalized in
the sense of <a href="#charmod">[Character Model for the World Wide
Web 1.0: Fundamentals]</a>.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>This document uses the term "code point", sometimes spelt
"codepoint" (also known as "character number" or "code position")
to mean a non-negative integer that represents a character in some
encoding. See <a href="#charmod">[Character Model for the World
Wide Web 1.0: Fundamentals]</a>. The use of the word "character" in
this document is in the sense of production [2] of <a href=
"#REC-xml">[Extensible Markup Language (XML) 1.0 Recommendation
(Third Edition)]</a>. <a href="#Unicode4">[The Unicode
Standard]</a>, defines code points that range from #x0000 to
#x10FFFF inclusive and may include code points that have not yet
been assigned to characters.</p>
<p>In functions that involve character counting such as <a href=
"#func-substring"><code>fn:substring</code></a>, <a href=
"#func-string-length"><code>fn:string-length</code></a> and
<a href="#func-translate"><code>fn:translate</code></a>, what is
counted is the number of XML characters in the string (or
equivalently, the number of Unicode code points). Some
implementations may represent a code point above xFFFF using two
16-bit values known as a surrogate. A surrogate counts as one
character, not two.</p>
</div>
</div>
<div class="div2">
<h3><a name="func-assemble-disassemble-string" id=
"func-assemble-disassemble-string"></a>7.2 Functions to Assemble
and Disassemble Strings</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-codepoints-to-string"><code>fn:codepoints-to-string</code></a></td>
<td>Creates an <code>xs:string</code> from a sequence of Unicode
code points.</td>
</tr>
<tr>
<td><a href=
"#func-string-to-codepoints"><code>fn:string-to-codepoints</code></a></td>
<td>Returns the sequence of Unicode code points that constitute an
<code>xs:string</code>.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-codepoints-to-string" id=
"func-codepoints-to-string"></a>7.2.1 fn:codepoints-to-string</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:codepoints-to-string</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:integer*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Creates an <code>xs:string</code> from a sequence of
<a href="#Unicode4">[The Unicode Standard]</a> code points. Returns
the zero-length string if <code>$arg</code> is the empty sequence.
If any of the code points in <code>$arg</code> is not a legal XML
character, an error is raised [<a href="#ERRFOCH0001" title=
"err:FOCH0001">err:FOCH0001</a>].</p>
<div class="div4">
<h5><a name="func-codepoints-to-string-examples" id=
"func-codepoints-to-string-examples"></a>7.2.1.1 Examples</h5>
<ul>
<li>
<p><code>fn:codepoints-to-string((2309, 2358, 2378, 2325))</code>
returns "अशॊक"</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-string-to-codepoints" id=
"func-string-to-codepoints"></a>7.2.2 fn:string-to-codepoints</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:string-to-codepoints</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer*</code></div>
</div>
<p>Summary: Returns the sequence of <a href="#Unicode4">[The
Unicode Standard]</a> code points that constitute an
<code>xs:string</code>. If <code>$arg</code> is a zero-length
string or the empty sequence, the empty sequence is returned.</p>
<div class="div4">
<h5><a name="func-string-to-codepoints-examples" id=
"func-string-to-codepoints-examples"></a>7.2.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:string-to-codepoints("Thérèse")</code> returns the
sequence (84, 104, 233, 114, 232, 115, 101)</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="string-compare" id="string-compare"></a>7.3 Equality
and Comparison of Strings</h3>
<div class="div3">
<h4><a name="collations" id="collations"></a>7.3.1 Collations</h4>
<p>A collation is a specification of the manner in which character
strings are compared and, by extension, ordered. When values whose
type is <code>xs:string</code> or a type derived from
<code>xs:string</code> 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).
The <a href="#charmod">[Character Model for the World Wide Web 1.0:
Fundamentals]</a> 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.</p>
<p>Collations can indicate that two different code points are, in
fact, equal for comparison purposes (e.g., "v" and "w" are
considered equivalent in Swedish). Strings can be compared
codepoint-by-codepoint or in a linguistically appropriate manner,
as defined by the collation.</p>
<p>Some collations, especially those based on the <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a> can be
"tailored" for various purposes. This document does not discuss
such tailoring, nor does it provide a mechanism to perform
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,
<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>,
provides the ability to compare strings based on code point values.
Every implementation of XQuery/XPath must support the collation
based on code point values.</p>
<p>In the ideal case, a collation should treat two strings as equal
if the two strings are identical after Unicode normalization. Thus,
the <a href="#charmod-normalization">[Character Model for the World
Wide Web 1.0: Normalization]</a> recommends that all strings be
subjected to early Unicode normalization and some collations will
raise runtime errors if they encounter strings that are not
properly normalized. However, 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
interoperability of operations on XML documents in general, there
may be collations that operate on unnormalized strings and other
collations that implicitly normalize strings before comparing them.
Applications may choose the kind of collation best suited for their
needs. Note that collations based on the Unicode collation
algorithm implicitly normalize strings before comparison and
produce equivalent results regardless of a string's
normalization.</p>
<p>This specification assumes that collations are named and that
the collation name may be provided as an argument to string
functions. Functions that allow specification of a collation do so
with an argument whose type is <code>xs:string</code> but whose
lexical form must conform to an <code>xs:anyURI</code>. If the
collation is specified using a relative URI, it is assumed to be
relative to the value of the base-uri property in the static
context. This specification also defines the manner in which a
default collation is determined if the collation argument is not
specified in invocations of functions that use a collation but
allow it to be omitted.</p>
<p>This specification does not define whether or not the collation
URI is dereferenced. The collation URI may be an abstract
identifier, or it may refer to an actual resource describing the
collation. If it refers to a resource, this specification does not
define the nature of that resource. One possible candidate is that
the resource is a locale description expressed using the Locale
Data Markup Language: see <a href="#LDML">[Locale Data Markup
Language]</a>.</p>
<p>Functions such as <a href=
"#func-compare"><code>fn:compare</code></a> and <a href=
"#func-max"><code>fn:max</code></a> that compare
<code>xs:string</code> values use a single collation URI to
identify all aspects of the collation rules. This means that any
parameters such as the strength of the collation must be specified
as part of the collation URI. For example, suppose there is a
collation " <code>http://www.example.com/collations/French</code> "
that refers to a French collation that compares on the basis of
base characters. Collations that use the same basic rules, but with
higher strengths, for example, base characters and accents, or base
characters, accents and case, would need to be given different
names, say " <code>http://www.example.com/collations/French1</code>
" and " <code>http://www.example.com/collations/French2</code> ".
Note that some specifications use the term collation to refer to an
algorithm that can be parameterized, but in this specification,
each possible parameterization is considered to be a distinct
collation.</p>
<p>The XQuery/XPath static context includes a provision for a
default collation that can be used for string comparisons and
ordering operations. See the description of the static context in
<a href="http://www.w3.org/TR/xpath20/#static_context">Section
2.1.1 Static Context</a><sup><small>XP</small></sup>. If the
default collation is not specified by the user or the system, the
default collation is the Unicode code point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).</p>
<p>The decision of which collation to use for a given comparison or
ordering function is determined by the following algorithm:</p>
<ol class="enumar">
<li>
<p>If the function specifies an explicit collation, CollationA
(e.g., if the optional collation argument is specified in an
invocation of the <a href=
"#func-compare"><code>fn:compare()</code></a> function), then:</p>
<ul>
<li>
<p>If CollationA is supported by the implementation, then
CollationA is used.</p>
</li>
<li>
<p>Otherwise, an error is raised [<a href="#ERRFOCH0002" title=
"err:FOCH0002">err:FOCH0002</a>].</p>
</li>
</ul>
</li>
<li>
<p>If no collation is explicitly specified for the function and the
default collation in the XQuery/XPath static context is CollationB,
then:</p>
<ul>
<li>
<p>If CollationB is supported by the implementation, then
CollationB is used.</p>
</li>
<li>
<p>Otherwise, an error is raised [<a href="#ERRFOCH0002" title=
"err:FOCH0002">err:FOCH0002</a>].</p>
</li>
</ul>
</li>
</ol>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>XML allows elements to specify the <code>xml:lang</code>
attribute to indicate the language associated with the content of
such an element. This specification does not use
<code>xml:lang</code> to identify the default collation because
using <code>xml:lang</code> does not produce desired effects when
the two strings to be compared have different <code>xml:lang</code>
values or when a string is multilingual.</p>
</div>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-compare"><code>fn:compare</code></a></td>
<td>Returns -1, 0, or 1, depending on whether the value of the
first argument is respectively less than, equal to, or greater than
the value of the second argument, according to the rules of the
collation that is used.</td>
</tr>
<tr>
<td><a href=
"#func-codepoint-equal"><code>fn:codepoint-equal</code></a></td>
<td>Returns <code>true</code> if the two arguments are equal using
the Unicode code point collation.</td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="div3">
<h4><a name="func-compare" id="func-compare"></a>7.3.2
fn:compare</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:compare</code>(<code class=
"arg">$comparand1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$comparand2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:compare</code>(</td>
<td valign="baseline"><code class="arg">$comparand1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$comparand2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns -1, 0, or 1, depending on whether the value of
the <code>$comparand1</code> is respectively less than, equal to,
or greater than the value of <code>$comparand2</code>, according to
the rules of the collation that is used.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>.</p>
<p>If either argument is the empty sequence, the result is the
empty sequence.</p>
<p>This function, invoked with the first signature, backs up the
"eq", "ne", "gt", "lt", "le" and "ge" operators on string
values.</p>
<div class="div4">
<h5><a name="func-compare-examples" id=
"func-compare-examples"></a>7.3.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:compare('abc', 'abc')</code> returns 0.</p>
</li>
<li>
<p><code>fn:compare('Strasse', 'Straße')</code> 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.)</p>
</li>
<li>
<p><code>fn:compare('Strasse', 'Straße', 'deutsch')</code> returns
0 if the collation identified by the relative URI constructed from
the <code>string</code> value "deutsch" includes provisions that
equate "ss" and the (German) character "ß" ("sharp-s"). (Otherwise,
the returned value depends on the semantics of that collation.)</p>
</li>
<li>
<p><code>fn:compare('Strassen', 'Straße')</code> returns 1 if the
default collation includes provisions that treat differences
between "ss" and the (German) character "ß" ("sharp-s") with less
strength than the differences between the base characters, such as
the final "n".</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-codepoint-equal" id=
"func-codepoint-equal"></a>7.3.3 fn:codepoint-equal</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:codepoint-equal</code>(</td>
<td valign="baseline"><code class="arg">$comparand1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$comparand2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> or <code>false</code>
depending on whether the value of <code>$comparand1</code> is equal
to the value of <code>$comparand2</code>, according to the Unicode
code point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).</p>
<p>If either argument is the empty sequence, the result is the
empty sequence.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This function allows <code>xs:anyURI</code> values to be
compared without having to specify the Unicode code point
collation.</p>
</div>
</div>
</div>
<div class="div2">
<h3><a name="string-value-functions" id=
"string-value-functions"></a>7.4 Functions on String Values</h3>
<p>The following functions are defined on values of type
<code>xs:string</code> and types derived from it.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-concat"><code>fn:concat</code></a></td>
<td>Concatenates two or more <code>xs:anyAtomicType</code>
arguments cast to <code>xs:string</code>.</td>
</tr>
<tr>
<td><a href=
"#func-string-join"><code>fn:string-join</code></a></td>
<td>Returns the <code>xs:string</code> produced by concatenating a
sequence of <code>xs:string</code>s using an optional
separator.</td>
</tr>
<tr>
<td><a href="#func-substring"><code>fn:substring</code></a></td>
<td>Returns the <code>xs:string</code> located at a specified place
within an argument <code>xs:string</code>.</td>
</tr>
<tr>
<td><a href=
"#func-string-length"><code>fn:string-length</code></a></td>
<td>Returns the length of the argument.</td>
</tr>
<tr>
<td><a href=
"#func-normalize-space"><code>fn:normalize-space</code></a></td>
<td>Returns the whitespace-normalized value of the argument.</td>
</tr>
<tr>
<td><a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a></td>
<td>Returns the normalized value of the first argument in the
normalization form specified by the second argument.</td>
</tr>
<tr>
<td><a href="#func-upper-case"><code>fn:upper-case</code></a></td>
<td>Returns the upper-cased value of the argument.</td>
</tr>
<tr>
<td><a href="#func-lower-case"><code>fn:lower-case</code></a></td>
<td>Returns the lower-cased value of the argument.</td>
</tr>
<tr>
<td><a href="#func-translate"><code>fn:translate</code></a></td>
<td>Returns the first <code>xs:string</code> argument with
occurrences of characters contained in the second argument replaced
by the character at the corresponding position in the third
argument.</td>
</tr>
<tr>
<td><a href=
"#func-encode-for-uri"><code>fn:encode-for-uri</code></a></td>
<td>Returns the <code>xs:string</code> argument with certain
characters escaped to enable the resulting string to be used as a
path segment in a URI.</td>
</tr>
<tr>
<td><a href="#func-iri-to-uri"><code>fn:iri-to-uri</code></a></td>
<td>Returns the <code>xs:string</code> argument with certain
characters escaped to enable the resulting string to be used as
(part of) a URI.</td>
</tr>
<tr>
<td><a href=
"#func-escape-html-uri"><code>fn:escape-html-uri</code></a></td>
<td>Returns the <code>xs:string</code> argument with certain
characters escaped in the manner that html user agents handle
attribute values that expect URIs.</td>
</tr>
</tbody>
</table>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>When the above operators and functions are applied to datatypes
derived from <code>xs:string</code>, they are guaranteed to return
legal <code>xs:string</code>s, but they might not return a legal
value for the particular subtype to which they were applied.</p>
<p>The strings returned by <a href=
"#func-concat"><code>fn:concat</code></a> and <a href=
"#func-string-join"><code>fn:string-join</code></a> are not
guaranteed to be normalized. But see note in <a href=
"#func-concat"><code>fn:concat</code></a>.</p>
</div>
<div class="div3">
<h4><a name="func-concat" id="func-concat"></a>7.4.1 fn:concat</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:concat</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>,</td>
</tr>
<tr>
<td valign="baseline"><span class="varargs">...</span></td>
<td valign="baseline">)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Accepts two or more <code>xs:anyAtomicType</code>
arguments and casts them to <code>xs:string</code>. Returns the
<code>xs:string</code> that is the concatenation of the values of
its arguments after conversion. If any of the arguments is the
empty sequence, the argument is treated as the zero-length
string.</p>
<p>The <code>fn:concat</code> function is specified to allow an two
or more arguments that are concatenated together. This is the only
function specified in this document that allows a variable number
of arguments. This capability is retained for compatibility with
<a href="#xpath">[XML Path Language (XPath) Version 1.0]</a>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>As mentioned in <a href="#string-types"><b>7.1 String
Types</b></a> Unicode normalization is not automatically applied to
the result of <code>fn:concat</code>. If a normalized result is
required, <a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a> can
be applied to the <code>xs:string</code> returned by
<code>fn:concat</code>. The following XQuery:</p>
<div class="exampleInner">
<pre>
let $v1 := "I plan to go to Mu"
let $v2 := "?nchen in September"
return concat($v1, $v2)
</pre></div>
<p>where the "?" represents either the actual Unicode character
COMBINING DIARESIS (Unicode codepoint U+0308) or "&amp;#x0308;",
will return:</p>
<p>"I plan to go to Mu?nchen in September"</p>
<p>where the "?" represents either the actual Unicode character
COMBINING DIARESIS (Unicode codepoint U+0308) or "&amp;#x0308;". It
is worth noting that the returned value is not normalized in NFC;
however, it is normalized in NFD. .</p>
<p>However, the following XQuery:</p>
<div class="exampleInner">
<pre>
let $v1 := "I plan to go to Mu"
let $v2 := "?nchen in September"
return normalize-unicode(concat($v1, $v2))
</pre></div>
<p>where the "?" represents either the actual Unicode character
COMBINING DIARESIS (Unicode codepoint U+0308) or "&amp;#x0308;",
will return:</p>
<p>"I plan to go to München in September"</p>
<p>This returned result is normalized in NFC.</p>
</div>
<div class="div4">
<h5><a name="func-concat-examples" id=
"func-concat-examples"></a>7.4.1.1 Examples</h5>
<ul>
<li>
<p><code>fn:concat('un', 'grateful')</code> returns "
<code>ungrateful</code> ".</p>
</li>
<li>
<p><code>fn:concat('Thy ', (), 'old ', "groans", "", ' ring', '
yet', ' in', ' my', ' ancient',' ears.')</code> returns " <code>Thy
old groans ring yet in my ancient ears.</code> ".</p>
</li>
<li>
<p><code>fn:concat('Ciao!',())</code> returns " <code>Ciao!</code>
".</p>
</li>
<li>
<p><code>fn:concat('Ingratitude, ', 'thou ', 'marble-hearted', '
fiend!')</code> returns " <code>Ingratitude, thou marble-hearted
fiend!</code> ".</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-string-join" id="func-string-join"></a>7.4.2
fn:string-join</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:string-join</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string*</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns a <code>xs:string</code> created by
concatenating the members of the <code>$arg1</code> sequence using
<code>$arg2</code> as a separator. If the value of
<code>$arg2</code> is the zero-length string, then the members of
<code>$arg1</code> are concatenated without a separator.</p>
<p>If the value of <code>$arg1</code> is the empty sequence, the
zero-length string is returned.</p>
<div class="div4">
<h5><a name="func-string-join-examples" id=
"func-string-join-examples"></a>7.4.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:string-join(('Now', 'is', 'the', 'time', '...'), '
')</code> returns " <code>Now is the time ...</code> ".</p>
</li>
<li>
<p><code>fn:string-join(('Blow, ', 'blow, ', 'thou ', 'winter ',
'wind!'), '')</code> returns " <code>Blow, blow, thou winter
wind!</code> ".</p>
</li>
<li>
<p><code>fn:string-join((), 'separator')</code> returns "".</p>
</li>
<li>
<p>Assume a document:</p>
<div class="exampleInner">
<pre>
&lt;doc&gt;
&lt;chap&gt;
&lt;section&gt;
&lt;/section&gt;
&lt;/chap&gt;
&lt;/doc&gt;
</pre></div>
<p>with the <code>&lt;section&gt;</code> as the context node, the
<a href="#xpath20">[XML Path Language (XPath) 2.0]</a>
expression:</p>
<p><code>fn:string-join(for $n in ancestor-or-self::* return
name($n), '/')</code></p>
<p>returns " <code>doc/chap/section</code> "</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-substring" id="func-substring"></a>7.4.3
fn:substring</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:substring</code>(</td>
<td valign="baseline"><code class="arg">$sourceString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$startingLoc</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring</code>(</td>
<td valign="baseline"><code class="arg">$sourceString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$startingLoc</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:double</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$length</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the portion of the value of
<code>$sourceString</code> beginning at the position indicated by
the value of <code>$startingLoc</code> and continuing for the
number of characters indicated by the value of
<code>$length</code>. The characters returned do not extend beyond
<code>$sourceString</code>. If <code>$startingLoc</code> is zero or
negative, only those characters in positions greater than zero are
returned.</p>
<p>More specifically, the three argument version of the function
returns the characters in <code>$sourceString</code> whose position
<code>$p</code> obeys:</p>
<p><a href="#func-round"><code>fn:round($startingLoc) &lt;= $p &lt;
fn:round($startingLoc) + fn:round($length)</code></a></p>
<p>The two argument version of the function assumes that
<code>$length</code> is infinite and returns the characters in
<code>$sourceString</code> whose position <code>$p</code>
obeys:</p>
<p><a href="#func-round"><code>fn:round($startingLoc) &lt;= $p &lt;
fn:round(INF)</code></a></p>
<p>In the above computations, the rules for <a href=
"#func-numeric-less-than"><code>op:numeric-less-than()</code></a>
and <a href=
"#func-numeric-greater-than"><code>op:numeric-greater-than()</code></a>
apply.</p>
<p>If the value of <code>$sourceString</code> is the empty
sequence, the zero-length string is returned.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The first character of a string is located at position 1, not
position 0.</p>
</div>
<div class="div4">
<h5><a name="func-substring-examples" id=
"func-substring-examples"></a>7.4.3.1 Examples</h5>
<ul>
<li>
<p><code>fn:substring("motor car", 6)</code> returns <code>"
car"</code>.</p>
<p>Characters starting at position 6 to the end of
<code>$sourceString</code> are selected.</p>
</li>
<li>
<p><code>fn:substring("metadata", 4, 3)</code> returns
<code>"ada"</code>.</p>
<p>Characters at positions greater than or equal to 4 and less than
7 are selected.</p>
</li>
<li>
<p><code>fn:substring("12345", 1.5, 2.6)</code> returns
<code>"234"</code>.</p>
<p>Characters at positions greater than or equal to 2 and less than
5 are selected.</p>
</li>
<li>
<p><code>fn:substring("12345", 0, 3)</code> returns
<code>"12"</code>.</p>
<p>Characters at positions greater than or equal to 0 and less than
3 are selected. Since the first position is 1, these are the
characters at positions 1 and 2.</p>
</li>
<li>
<p><code>fn:substring("12345", 5, -3)</code> returns
<code>""</code>.</p>
<p>Characters at positions greater than or equal to 5 and less than
2 are selected.</p>
</li>
<li>
<p><code>fn:substring("12345", -3, 5)</code> returns
<code>"1"</code>.</p>
<p>Characters at positions greater than or equal to -3 and less
than 2 are selected. Since the first position is 1, this is the
character at position 1.</p>
</li>
<li>
<p><code>fn:substring("12345", 0 div 0E0, 3)</code> returns
<code>""</code>.</p>
<p>Since <code>0 div 0E0</code> returns <code>NaN</code>, and
<code>NaN</code> compared to any other number returns
<code>false</code>, no characters are selected.</p>
</li>
<li>
<p><code>fn:substring("12345", 1, 0 div 0E0)</code> returns
<code>""</code>.</p>
<p>As above.</p>
</li>
<li>
<p><code>fn:substring((), 1, 3)</code> returns <code>""</code>.</p>
</li>
<li>
<p><code>fn:substring("12345", -42, 1 div 0E0)</code> returns
<code>"12345"</code>.</p>
<p>Characters at positions greater than or equal to -42 and less
than INF are selected.</p>
</li>
<li>
<p><code>fn:substring("12345", -1 div 0E0, 1 div 0E0)</code>
returns <code>""</code>.</p>
<p>Since <code>-INF + INF</code> returns <code>NaN</code>, no
characters are selected.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-string-length" id="func-string-length"></a>7.4.4
fn:string-length</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:string-length</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:string-length</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> equal to the length
in characters of the value of <code>$arg</code>.</p>
<p>If the value of <code>$arg</code> is the empty sequence, the
<code>xs:integer</code> 0 is returned.</p>
<p>If no argument is supplied, <code>$arg</code> defaults to the
string value (calculated using <a href=
"#func-string"><code>fn:string()</code></a>) of the context item
(<code>.</code>). If no argument is supplied or if the argument is
the context item and the context item is undefined an error is
raised: [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>.</p>
<div class="div4">
<h5><a name="func-string-length-examples" id=
"func-string-length-examples"></a>7.4.4.1 Examples</h5>
<ul>
<li>
<p><code>fn:string-length("Harp not on that string, madam; that is
past.")</code> returns <code>45</code>.</p>
</li>
<li>
<p><code>fn:string-length(())</code> returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-normalize-space" id=
"func-normalize-space"></a>7.4.5 fn:normalize-space</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:normalize-space</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:normalize-space</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the value of <code>$arg</code> with whitespace
normalized by stripping leading and trailing whitespace and
replacing sequences of one or more than one whitespace character
with a single space, <code>#x20</code>.</p>
<p>The whitespace characters are defined in the metasymbol S
(Production 3) of <a href="#REC-xml">[Extensible Markup Language
(XML) 1.0 Recommendation (Third Edition)]</a>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The definition of the metasymbol S (Production 3), is unchanged
in <a href="#xml11">[Extensible Markup Language (XML) 1.1
Recommendation]</a>.</p>
</div>
<p>If the value of <code>$arg</code> is the empty sequence, returns
the zero-length string.</p>
<p>If no argument is supplied, <code>$arg</code> defaults to the
string value (calculated using <a href=
"#func-string"><code>fn:string()</code></a>) of the context item
(<code>.</code>). If no argument is supplied or if the argument is
the context item and the context item is undefined an error is
raised: [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>.</p>
<div class="div4">
<h5><a name="func-normalize-space-examples" id=
"func-normalize-space-examples"></a>7.4.5.1 Examples</h5>
<ul>
<li>
<p><code>fn:normalize-space(" The &#160;wealthy curled darlings of
&#160;&#160;our &#160;nation. ")</code> returns " <code>The wealthy
curled darlings of our nation.</code> ".</p>
</li>
<li>
<p><code>fn:normalize-space(())</code> returns "".</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-normalize-unicode" id=
"func-normalize-unicode"></a>7.4.6 fn:normalize-unicode</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:normalize-unicode</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:normalize-unicode</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class=
"arg">$normalizationForm</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the value of <code>$arg</code> normalized
according to the normalization criteria for a normalization form
identified by the value of <code>$normalizationForm</code>. The
effective value of the <code>$normalizationForm</code> is computed
by removing leading and trailing blanks, if present, and converting
to upper case.</p>
<p>If the value of <code>$arg</code> is the empty sequence, returns
the zero-length string.</p>
<p>See <a href="#charmod-normalization">[Character Model for the
World Wide Web 1.0: Normalization]</a> for a description of the
normalization forms.</p>
<p>If the <code>$normalizationForm</code> is absent, as in the
first format above, it shall be assumed to be "NFC"</p>
<ul>
<li>
<p>If the effective value of <code>$normalizationForm</code> is
"NFC", then the value returned by the function is the value of
<code>$arg</code> in Unicode Normalization Form C (NFC).</p>
</li>
<li>
<p>If the effective value of <code>$normalizationForm</code> is
"NFD", then the value returned by the function is the value of
<code>$arg</code> in Unicode Normalization Form D (NFD).</p>
</li>
<li>
<p>If the effective value of <code>$normalizationForm</code> is
"NFKC", then the value returned by the function is the value of
<code>$arg</code> in Unicode Normalization Form KC (NFKC).</p>
</li>
<li>
<p>If the effective value of <code>$normalizationForm</code> is
"NFKD", then the value returned by the function is the value of
<code>$arg</code> in Unicode Normalization Form KD (NFKD).</p>
</li>
<li>
<p>If the effective value of <code>$normalizationForm</code> is
"FULLY-NORMALIZED", then the value returned by the function is the
value of <code>$arg</code> in the fully normalized form.</p>
</li>
<li>
<p>If the effective value of <code>$normalizationForm</code> is the
zero-length string, no normalization is performed and
<code>$arg</code> is returned.</p>
</li>
</ul>
<p>Conforming implementations <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> support normalization form "NFC" and <a title=
"may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> support
normalization forms "NFD", "NFKC", "NFKD", "FULLY-NORMALIZED". They
<a title="may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> also support
other normalization forms with <a title="implementation-defined"
class="termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> semantics. If the effective value of the
<code>$normalizationForm</code> is other than one of the values
supported by the implementation, then an error is raised [<a href=
"#ERRFOCH0003" title="err:FOCH0003">err:FOCH0003</a>].</p>
</div>
<div class="div3">
<h4><a name="func-upper-case" id="func-upper-case"></a>7.4.7
fn:upper-case</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:upper-case</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the value of <code>$arg</code> after
translating every character to its upper-case correspondent as
defined in the appropriate case mappings section in the Unicode
standard <a href="#Unicode4">[The Unicode Standard]</a>. For
versions of Unicode beginning with the 2.1.8 update, only
locale-insensitive case mappings should be applied. Beginning with
version 3.2.0 (and likely future versions) of Unicode, precise
mappings are described in default case operations, which are full
case mappings in the absence of tailoring for particular languages
and environments. Every lower-case character that does not have an
upper-case correspondent, as well as every upper-case character, is
included in the returned value in its original form.</p>
<p>If the value of <code>$arg</code> is the empty sequence, the
zero-length string is returned.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Case mappings may change the length of a string. In general, the
two functions are not inverses of each other <a href=
"#func-lower-case"><code>fn:lower-case(fn:upper-case($arg))</code></a>
is not guaranteed to return <code>$arg</code>, nor is
<code>fn:upper-case(fn:lower-case($arg))</code>. The Latin small
letter dotless i (as used in Turkish) is perhaps the most prominent
lower-case letter which will not round-trip. The Latin capital
letter i with dot above is the most prominent upper-case letter
which will not round trip; there are others.</p>
<p>These functions may not always be linguistically appropriate
(e.g. Turkish i without dot) or appropriate for the application
(e.g. titlecase). In cases such as Turkish, a simple translation
should be used first.</p>
<p>Results may violate user expectations (in Quebec, for example,
the standard uppercase equivalent of "è" is "È", while in
metropolitan France it is more commonly "E"; only one of these is
supported by the functions as defined).</p>
<p>Many characters of class Ll lack uppercase equivalents in the
Unicode case mapping tables; many characters of class Lu lack
lowercase equivalents.</p>
</div>
<div class="div4">
<h5><a name="func-upper-case-examples" id=
"func-upper-case-examples"></a>7.4.7.1 Examples</h5>
<ul>
<li>
<p><code>fn:upper-case("abCd0")</code> returns
<code>"ABCD0"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-lower-case" id="func-lower-case"></a>7.4.8
fn:lower-case</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:lower-case</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the value of <code>$arg</code> after
translating every character to its lower-case correspondent as
defined in the appropriate case mappings section in the Unicode
standard <a href="#Unicode4">[The Unicode Standard]</a>. For
versions of Unicode beginning with the 2.1.8 update, only
locale-insensitive case mappings should be applied. Beginning with
version 3.2.0 (and likely future versions) of Unicode, precise
mappings are described in default case operations, which are full
case mappings in the absence of tailoring for particular languages
and environments. Every upper-case character that does not have a
lower-case correspondent, as well as every lower-case character, is
included in the returned value in its original form.</p>
<p>If the value of <code>$arg</code> is the empty sequence, the
zero-length string is returned.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Case mappings may change the length of a string. In general, the
two functions are not inverses of each other
<code>fn:lower-case(fn:upper-case($arg))</code> is not guaranteed
to return <code>$arg</code>, nor is <a href=
"#func-upper-case"><code>fn:upper-case(fn:lower-case($arg))</code></a>.
The Latin small letter dotless i (as used in Turkish) is perhaps
the most prominent lower-case letter which will not round-trip. The
Latin capital letter i with dot above is the most prominent
upper-case letter which will not round trip; there are others.</p>
<p>These functions may not always be linguistically appropriate
(e.g. Turkish i without dot) or appropriate for the application
(e.g. titlecase). In cases such as Turkish, a simple translation
should be used first.</p>
<p>Results may violate user expectations (in Quebec, for example,
the standard uppercase equivalent of "è" is "È", while in
metropolitan France it is more commonly "E"; only one of these is
supported by the functions as defined).</p>
<p>Many characters of class Ll lack uppercase equivalents in the
Unicode case mapping tables; many characters of class Lu lack
lowercase equivalents.</p>
</div>
<div class="div4">
<h5><a name="func-lower-case-examples" id=
"func-lower-case-examples"></a>7.4.8.1 Examples</h5>
<ul>
<li>
<p><code>fn:lower-case("ABc!D")</code> returns
<code>"abc!d"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-translate" id="func-translate"></a>7.4.9
fn:translate</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:translate</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$mapString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$transString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the value of <code>$arg</code> modified so that
every character in the value of <code>$arg</code> that occurs at
some position <em>N</em> in the value of <code>$mapString</code>
has been replaced by the character that occurs at position
<em>N</em> in the value of <code>$transString</code>.</p>
<p>If the value of <code>$arg</code> is the empty sequence, the
zero-length string is returned.</p>
<p>Every character in the value of <code>$arg</code> that does not
appear in the value of <code>$mapString</code> is unchanged.</p>
<p>Every character in the value of <code>$arg</code> that appears
at some position <em>M</em> in the value of
<code>$mapString</code>, where the value of
<code>$transString</code> is less than <em>M</em> characters in
length, is omitted from the returned value. If
<code>$mapString</code> is the zero-length string <code>$arg</code>
is returned.</p>
<p>If a character occurs more than once in <code>$mapString</code>,
then the first occurrence determines the replacement character. If
<code>$transString</code> is longer than <code>$mapString</code>,
the excess characters are ignored.</p>
<div class="div4">
<h5><a name="func-translate-examples" id=
"func-translate-examples"></a>7.4.9.1 Examples</h5>
<ul>
<li>
<p><code>fn:translate("bar","abc","ABC")</code> returns
<code>"BAr"</code></p>
</li>
<li>
<p><code>fn:translate("--aaa--","abc-","ABC")</code> returns
<code>"AAA"</code>.</p>
</li>
<li>
<p><code>fn:translate("abcdabc", "abc", "AB")</code> returns
<code>"ABdAB"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-encode-for-uri" id=
"func-encode-for-uri"></a>7.4.10 fn:encode-for-uri</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:encode-for-uri</code>(<code class=
"arg">$uri-part</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: This function encodes reserved characters in an
<code>xs:string</code> that is intended to be used in the path
segment of a URI. It is invertible but not idempotent. This
function applies the URI escaping rules defined in section 2 of
<a href="#rfc3986">[RFC 3986]</a> to the <code>xs:string</code>
supplied as <code>$uri-part</code>. The effect of the function is
to escape reserved characters. Each such character in the string is
replaced with its percent-encoded form as described in <a href=
"#rfc3986">[RFC 3986]</a>.</p>
<p>If <code>$uri-part</code> is the empty sequence, returns the
zero-length string.</p>
<p>All characters are escaped except those identified as
"unreserved" by <a href="#rfc3986">[RFC 3986]</a>, that is the
upper- and lower-case letters A-Z, the digits 0-9, HYPHEN-MINUS
("-"), LOW LINE ("_"), FULL STOP ".", and TILDE "~".</p>
<p>Note that this function escapes URI delimiters and therefore
cannot be used indiscriminately to encode "invalid" characters in a
path segment.</p>
<p>Since <a href="#rfc3986">[RFC 3986]</a> recommends that, for
consistency, URI producers and normalizers should use uppercase
hexadecimal digits for all percent-encodings, this function must
always generate hexadecimal values using the upper-case letters
A-F.</p>
<div class="div4">
<h5><a name="func-encode-for-uri-examples" id=
"func-encode-for-uri-examples"></a>7.4.10.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:encode-for-uri("http://www.example.com/00/Weather/CA/Los%20Angeles#ocean")</code>
returns
<code>"http%3A%2F%2Fwww.example.com%2F00%2FWeather%2FCA%2FLos%2520Angeles%23ocean"</code>.
This is probably not what the user intended because all of the
delimiters have been encoded.</p>
</li>
<li>
<p><code>concat("http://www.example.com/",
encode-for-uri("~bébé"))</code> returns
<code>"http://www.example.com/~b%C3%A9b%C3%A9"</code>.</p>
</li>
<li>
<p><code>concat("http://www.example.com/", encode-for-uri("100%
organic"))</code> returns
<code>"http://www.example.com/100%25%20organic"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-iri-to-uri" id="func-iri-to-uri"></a>7.4.11
fn:iri-to-uri</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:iri-to-uri</code>(<code class=
"arg">$iri</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: This function converts an <code>xs:string</code>
containing an IRI into a URI according to the rules spelled out in
Section 3.1 of <a href="#rfc3987">[RFC 3987]</a>. It is idempotent
but not invertible.</p>
<p>If <code>$iri</code> contains a character that is invalid in an
IRI, such as the space character (see note below), the invalid
character is replaced by its percent-encoded form as described in
<a href="#rfc3986">[RFC 3986]</a> before the conversion is
performed.</p>
<p>If <code>$iri</code> is the empty sequence, returns the
zero-length string.</p>
<p>Since <a href="#rfc3986">[RFC 3986]</a> recommends that, for
consistency, URI producers and normalizers should use uppercase
hexadecimal digits for all percent-encodings, this function must
always generate hexadecimal values using the upper-case letters
A-F.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>This function does not check whether <code>$iri</code> is a
legal IRI. It treats it as an <code>xs:string</code> and operates
on the characters in the <code>xs:string</code>.</p>
<p>The following printable ASCII characters are invalid in an IRI:
"&lt;", "&gt;", " " " (double quote), space, "{", "}", "|", "\",
"^", and "`". Since these characters should not appear in an IRI,
if they do appear in <code>$iri</code> they will be
percent-encoded. In addition, characters outside the range x20-x126
will be percent-encoded because they are invalid in a URI.</p>
<p>Since this function does not escape the PERCENT SIGN "%" and
this character is not allowed in data within a URI, users wishing
to convert character strings, such as file names, that include "%"
to a URI should manually escape "%" by replacing it with "%25".</p>
</div>
<div class="div4">
<h5><a name="func-iri-to-uri-examples" id=
"func-iri-to-uri-examples"></a>7.4.11.1 Examples</h5>
<ul>
<li>
<p><code>fn:iri-to-uri
("http://www.example.com/00/Weather/CA/Los%20Angeles#ocean")</code>
returns
<code>"http://www.example.com/00/Weather/CA/Los%20Angeles#ocean"</code>.</p>
</li>
<li>
<p><code>fn:iri-to-uri ("http://www.example.com/~bébé")</code>
returns <code>"http://www.example.com/~b%C3%A9b%C3%A9"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-escape-html-uri" id=
"func-escape-html-uri"></a>7.4.12 fn:escape-html-uri</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:escape-html-uri</code>(<code class=
"arg">$uri</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: This function escapes all characters except printable
characters of the US-ASCII coded character set, specifically the
octets ranging from 32 to 126 (decimal). The effect of the function
is to escape a URI in the manner html user agents handle attribute
values that expect URIs. Each character in <code>$uri</code> to be
escaped is replaced by an escape sequence, which is formed by
encoding the character as a sequence of octets in UTF-8, and then
representing each of these octets in the form %HH, where HH is the
hexadecimal representation of the octet. This function must always
generate hexadecimal values using the upper-case letters A-F.</p>
<p>If <code>$uri</code> is the empty sequence, returns the
zero-length string.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The behavior of this function corresponds to the recommended
handling of non-ASCII characters in URI attribute values as
described in <a href="#HTML40">[HTML 4.0]</a> Appendix B.2.1.</p>
</div>
<div class="div4">
<h5><a name="func-escape-html-uri-examples" id=
"func-escape-html-uri-examples"></a>7.4.12.1 Examples</h5>
<ul>
<li>
<p><code>fn:escape-html-uri
("http://www.example.com/00/Weather/CA/Los Angeles#ocean")</code>
returns <code>"http://www.example.com/00/Weather/CA/Los
Angeles#ocean"</code>.</p>
</li>
<li>
<p><code>fn:escape-html-uri ("javascript:if
(navigator.browserLanguage == 'fr')
window.open('http://www.example.com/~bébé');") returns
"javascript:if (navigator.browserLanguage == 'fr')
window.open('http://www.example.com/~b%C3%A9b%C3%A9');"</code>.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="substring.functions" id="substring.functions"></a>7.5
Functions Based on Substring Matching</h3>
<p>The functions described in the section examine a string
<code>$arg1</code> to see whether it contains another string
<code>$arg2</code> as a substring. The result depends on whether
<code>$arg2</code> is a substring of <code>$arg1</code>, and if so,
on the range of characters in <code>$arg1</code> which
<code>$arg2</code> matches.</p>
<p>When the Unicode code point collation is used, this simply
involves determining whether <code>$arg1</code> contains a
contiguous sequence of characters whose code points are the same,
one for one, with the code points of the characters in
<code>$arg2</code>.</p>
<p>When a collation is specified, the rules are more complex.</p>
<p>All collations support the capability of deciding whether two
strings are considered equal, and if not, which of the strings
should be regarded as preceding the other. For functions such as
<a href="#func-compare"><code>fn:compare()</code></a>, this is all
that is required. For other functions, such as <a href=
"#func-contains"><code>fn:contains()</code></a>, the collation
needs to support an additional property: it must be able to
decompose the string into a sequence of collation units, each unit
consisting of one or more characters, such that two strings can be
compared by pairwise comparison of these units. ("collation unit"
is equivalent to "collation element" as defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.) The
string <code>$arg1</code> is then considered to contain
<code>$arg2</code> as a substring if the sequence of collation
units corresponding to <code>$arg2</code> is a subsequence of the
sequence of the collation units corresponding to
<code>$arg1</code>. The characters in <code>$arg1</code> that match
are the characters corresponding to these collation units.</p>
<p>This rule may occasionally lead to surprises. For example,
consider a collation that treats "Jaeger" and "Jäger" as equal. It
might do this by treating "ä" as representing two collation units,
in which case the expression <a href=
"#func-contains"><code>fn:contains("Jäger", "eg")</code></a> will
return <code>true</code>. Alternatively, a collation might treat
"ae" as a single collation unit, in which case the expression
<a href="#func-contains"><code>fn:contains("Jaeger",
"eg")</code></a> will return <code>false</code>. The results of
these functions thus depend strongly on the properties of the
collation that is used. In addition, collations may specify that
some collation units should be ignored during matching.</p>
<p>In the definitions below, we say that <code>$arg1</code>
contains <code>$arg2</code> at positions <code>m</code> through
<code>n</code> if the collation units corresponding to characters
in positions <code>m</code> to <code>n</code> of <code>$arg1</code>
are the same as the collation units corresponding to all the
characters of <code>$arg2</code> modulo ignorable collation units.
In the simple case of the Unicode code point collation, the
collation units are the same as the characters of the string. See
<a href="#Unicode-Collations">[Unicode Collation Algorithm]</a> for
a detailed discussion of substring matching.</p>
<p>It is possible to define collations that do not have the ability
to decompose a string into units suitable for substring matching.
An argument to a function defined in this section may be a URI that
identifies a collation that is able to compare two strings, but
that does not have the capability to split the string into
collation units. Such a collation may cause the function to fail,
or to give unexpected results or it may be rejected as an
unsuitable argument. The ability to decompose strings into
collation units is an <a title="implementation-defined" class=
"termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> property of the collation.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-contains"><code>fn:contains</code></a></td>
<td>Indicates whether one <code>xs:string</code> contains another
<code>xs:string</code>. A collation may be specified.</td>
</tr>
<tr>
<td><a href=
"#func-starts-with"><code>fn:starts-with</code></a></td>
<td>Indicates whether the value of one <code>xs:string</code>
begins with the collation units of another <code>xs:string</code>.
A collation may be specified.</td>
</tr>
<tr>
<td><a href="#func-ends-with"><code>fn:ends-with</code></a></td>
<td>Indicates whether the value of one <code>xs:string</code> ends
with the collation units of another <code>xs:string</code>. A
collation may be specified.</td>
</tr>
<tr>
<td><a href=
"#func-substring-before"><code>fn:substring-before</code></a></td>
<td>Returns the collation units of one <code>xs:string</code> that
precede in that <code>xs:string</code> the collation units of
another <code>xs:string</code>. A collation may be specified.</td>
</tr>
<tr>
<td><a href=
"#func-substring-after"><code>fn:substring-after</code></a></td>
<td>Returns the collation units of <code>xs:string</code> that
follow in that <code>xs:string</code> the collation units of
another <code>xs:string</code>. A collation may be specified.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-contains" id="func-contains"></a>7.5.1
fn:contains</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:contains</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:contains</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns an <code>xs:boolean</code> indicating whether
or not the value of <code>$arg1</code> contains (at the beginning,
at the end, or anywhere within) at least one sequence of collation
units that provides a minimal match to the collation units in the
value of <code>$arg2</code>, according to the collation that is
used.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Minimal match" is defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.</p>
</div>
<p>If the value of <code>$arg1</code> or <code>$arg2</code> is the
empty sequence, or contains only ignorable collation units, it is
interpreted as the zero-length string.</p>
<p>If the value of <code>$arg2</code> is the zero-length string,
then the function returns <code>true</code>.</p>
<p>If the value of <code>$arg1</code> is the zero-length string,
the function returns <code>false</code>.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>. If the specified collation does not support
collation units an error <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> be raised [<a href="#ERRFOCH0004" title=
"err:FOCH0004">err:FOCH0004</a>].</p>
<div class="div4">
<h5><a name="func-contains-examples" id=
"func-contains-examples"></a>7.5.1.1 Examples</h5>
<p>CollationA used in these examples is a collation in which both
"-" and "*" are ignorable collation units.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Ignorable collation unit" is equivalent to "ignorable collation
element" in <a href="#Unicode-Collations">[Unicode Collation
Algorithm]</a>.</p>
</div>
<ul>
<li>
<p><code>fn:contains ( "tattoo", "t")</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:contains ( "tattoo", "ttt")</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>fn:contains ( "", ())</code> returns <code>true</code>.
The first rule is applied, followed by the second rule.</p>
</li>
<li>
<p><code>fn:contains ( "abcdefghi", "-d-e-f-", "CollationA")</code>
returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:contains ( "a*b*c*d*e*f*g*h*i*", "d-ef-",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:contains ( "abcd***e---f*--*ghi", "def",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:contains ( (), "--***-*---", "CollationA")</code>
returns <code>true</code>. The second argument contains only
ignorable collation units and is equivalent to the zero-length
string.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-starts-with" id="func-starts-with"></a>7.5.2
fn:starts-with</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:starts-with</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:starts-with</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns an <code>xs:boolean</code> indicating whether
or not the value of <code>$arg1</code> starts with a sequence of
collation units that provides a minimal match to the collation
units of <code>$arg2</code> according to the collation that is
used.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Minimal match" is defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.</p>
</div>
<p>If the value of <code>$arg1</code> or <code>$arg2</code> is the
empty sequence, or contains only ignorable collation units, it is
interpreted as the zero-length string.</p>
<p>If the value of <code>$arg2</code> is the zero-length string,
then the function returns <code>true</code>. If the value of
<code>$arg1</code> is the zero-length string and the value of
<code>$arg2</code> is not the zero-length string, then the function
returns <code>false</code>.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>. If the specified collation does not support
collation units an error <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> be raised [<a href="#ERRFOCH0004" title=
"err:FOCH0004">err:FOCH0004</a>].</p>
<div class="div4">
<h5><a name="func-starts-with-examples" id=
"func-starts-with-examples"></a>7.5.2.1 Examples</h5>
<p>CollationA used in these examples is a collation in which both
"-" and "*" are ignorable collation units.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Ignorable collation unit" is equivalent to "ignorable collation
element" in <a href="#Unicode-Collations">[Unicode Collation
Algorithm]</a>.</p>
</div>
<ul>
<li>
<p><code>fn:starts-with("tattoo", "tat")</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:starts-with ( "tattoo", "att")</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>fn:starts-with ((), ())</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:starts-with ( "abcdefghi", "-a-b-c-",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:starts-with ( "a*b*c*d*e*f*g*h*i*", "a-bc-",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:starts-with ( "abcd***e---f*--*ghi", "abcdef",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:starts-with ( (), "--***-*---", "CollationA")</code>
returns <code>true</code>. The second argument contains only
ignorable collation units and is equivalent to the zero-length
string.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-ends-with" id="func-ends-with"></a>7.5.3
fn:ends-with</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:ends-with</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:ends-with</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns an <code>xs:boolean</code> indicating whether
or not the value of <code>$arg1</code> ends with a sequence of
collation units that provides a minimal match to the collation
units of <code>$arg2</code> according to the collation that is
used.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Minimal match" is defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.</p>
</div>
<p>If the value of <code>$arg1</code> or <code>$arg2</code> is the
empty sequence, or contains only ignorable collation units, it is
interpreted as the zero-length string.</p>
<p>If the value of <code>$arg2</code> is the zero-length string,
then the function returns <code>true</code>. If the value of
<code>$arg1</code> is the zero-length string and the value of
<code>$arg2</code> is not the zero-length string, then the function
returns <code>false</code>.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>. If the specified collation does not support
collation units an error <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> be raised [<a href="#ERRFOCH0004" title=
"err:FOCH0004">err:FOCH0004</a>].</p>
<div class="div4">
<h5><a name="func-ends-with-examples" id=
"func-ends-with-examples"></a>7.5.3.1 Examples</h5>
<p>CollationA used in these examples is a collation in which both
"-" and "*" are ignorable collation units.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Ignorable collation unit" is equivalent to "ignorable collation
element" in <a href="#Unicode-Collations">[Unicode Collation
Algorithm]</a>.</p>
</div>
<ul>
<li>
<p><code>fn:ends-with ( "tattoo", "tattoo")</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:ends-with ( "tattoo", "atto")</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>fn:ends-with ((), ())</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:ends-with ( "abcdefghi", "-g-h-i-",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:ends-with ( "abcd***e---f*--*ghi", "defghi",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:ends-with ( "abcd***e---f*--*ghi", "defghi",
"CollationA")</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:ends-with ( (), "--***-*---", "CollationA")</code>
returns <code>true</code>. The second argument contains only
ignorable collation units and is equivalent to the zero-length
string.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-substring-before" id=
"func-substring-before"></a>7.5.4 fn:substring-before</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:substring-before</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring-before</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the substring of the value of
<code>$arg1</code> that precedes in the value of <code>$arg1</code>
the first occurrence of a sequence of collation units that provides
a minimal match to the collation units of <code>$arg2</code>
according to the collation that is used.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Minimal match" is defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.</p>
</div>
<p>If the value of <code>$arg1</code> or <code>$arg2</code> is the
empty sequence, or contains only ignorable collation units, it is
interpreted as the zero-length string.</p>
<p>If the value of <code>$arg2</code> is the zero-length string,
then the function returns the zero-length string.</p>
<p>If the value of <code>$arg1</code> does not contain a string
that is equal to the value of <code>$arg2</code>, then the function
returns the zero-length string.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a> If the specified collation does not support
collation units an error <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> be raised [<a href="#ERRFOCH0004" title=
"err:FOCH0004">err:FOCH0004</a>].</p>
<div class="div4">
<h5><a name="func-substring-before-example" id=
"func-substring-before-example"></a>7.5.4.1 Examples</h5>
<p>CollationA used in these examples is a collation in which both
"-" and "*" are ignorable collation units.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Ignorable collation unit" is equivalent to "ignorable collation
element" in <a href="#Unicode-Collations">[Unicode Collation
Algorithm]</a>.</p>
</div>
<ul>
<li>
<p><code>fn:substring-before ( "tattoo", "attoo")</code> returns
"<code>t</code>".</p>
</li>
<li>
<p><code>fn:substring-before ( "tattoo", "tatto")</code> returns
"".</p>
</li>
<li>
<p><code>fn:substring-before ((), ())</code> returns "".</p>
</li>
<li>
<p><code>fn:substring-before ( "abcdefghi", "--d-e-",
"CollationA")</code> returns "<code>abc</code>".</p>
</li>
<li>
<p><code>fn:substring-before ( "abc--d-e-fghi", "--d-e-",
"CollationA")</code> returns "<code>abc--</code>".</p>
</li>
<li>
<p><code>fn:substring-before ( "a*b*c*d*e*f*g*h*i*", "***cde",
"CollationA")</code> returns "<code>a*b*</code>".</p>
</li>
<li>
<p><code>fn:substring-before ( "Eureka!", "--***-*---",
"CollationA")</code> returns "". The second argument contains only
ignorable collation units and is equivalent to the zero-length
string.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-substring-after" id=
"func-substring-after"></a>7.5.5 fn:substring-after</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:substring-after</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring-after</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the substring of the value of
<code>$arg1</code> that follows in the value of <code>$arg1</code>
the first occurrence of a sequence of collation units that provides
a minimal match to the collation units of <code>$arg2</code>
according to the collation that is used.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Minimal match" is defined in <a href=
"#Unicode-Collations">[Unicode Collation Algorithm]</a>.</p>
</div>
<p>If the value of <code>$arg1</code> or <code>$arg2</code> is the
empty sequence, or contains only ignorable collation units, it is
interpreted as the zero-length string.</p>
<p>If the value of <code>$arg2</code> is the zero-length string,
then the function returns the value of <code>$arg1</code>.</p>
<p>If the value of <code>$arg1</code> does not contain a string
that is equal to the value of <code>$arg2</code>, then the function
returns the zero-length string.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a> If the specified collation does not support
collation units an error <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> be raised [<a href="#ERRFOCH0004" title=
"err:FOCH0004">err:FOCH0004</a>].</p>
<div class="div4">
<h5><a name="func-substring-after-examples" id=
"func-substring-after-examples"></a>7.5.5.1 Examples</h5>
<p>CollationA used in these examples is a collation in which both
"-" and "*" are ignorable collation units.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>"Ignorable collation unit" is equivalent to "ignorable collation
element" in <a href="#Unicode-Collations">[Unicode Collation
Algorithm]</a>.</p>
</div>
<ul>
<li>
<p><code>fn:substring-after("tattoo", "tat")</code> returns
"<code>too</code>".</p>
</li>
<li>
<p><code>fn:substring-after ( "tattoo", "tattoo")</code> returns
"".</p>
</li>
<li>
<p><code>fn:substring-after ((), ())</code> returns "".</p>
</li>
<li>
<p><code>fn:substring-after ( "abcdefghi", "--d-e-",
"CollationA")</code> returns "<code>fghi</code>".</p>
</li>
<li>
<p><code>fn:substring-after ( "abc--d-e-fghi", "--d-e-",
"CollationA")</code> returns "<code>-fghi</code> ".</p>
</li>
<li>
<p><code>fn:substring-after ( "a*b*c*d*e*f*g*h*i*", "***cde***",
"CollationA")</code> returns "<code>*f*g*h*i*</code>".</p>
</li>
<li>
<p><code>fn:substring-after ( "Eureka!", "--***-*---",
"CollationA")</code> returns "<code>Eureka!</code>". The second
argument contains only ignorable collation units and is equivalent
to the zero-length string.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="string.match" id="string.match"></a>7.6 String
Functions that Use Pattern Matching</h3>
<p>The three functions described in this section make use of a
regular expression syntax for pattern matching. This is described
below.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-matches"><code>fn:matches</code></a></td>
<td>Returns an <code>xs:boolean</code> value that indicates whether
the value of the first argument is matched by the regular
expression that is the value of the second argument.</td>
</tr>
<tr>
<td><a href="#func-replace"><code>fn:replace</code></a></td>
<td>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.</td>
</tr>
<tr>
<td><a href="#func-tokenize"><code>fn:tokenize</code></a></td>
<td>Returns a sequence of one or more <code>xs:string</code>s 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.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="regex-syntax" id="regex-syntax"></a>7.6.1 Regular
Expression Syntax</h4>
<p>The regular expression syntax used by these functions is defined
in terms of the regular expression syntax specified in XML Schema
(see <a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a>), 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 omits some
facilities that are widely-used with languages such as Perl. This
section, therefore, describes extensions to the XML Schema regular
expressions syntax that reinstate these capabilities.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>It is recommended that implementers consult <a href=
"#Unicode-Regex">[Unicode Regular Expressions]</a> for information
on using regular expression processing on Unicode characters.</p>
</div>
<p>The regular expression syntax and semantics are identical to
those defined in <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a> with the following additions:</p>
<ul>
<li>
<p>Two meta-characters, <code>^</code> and <code>$</code> are
added. By default, the meta-character <code>^</code> matches the
start of the entire string, while <code>$</code> matches the end of
the entire string. In multi-line mode, <code>^</code> matches the
start of any line (that is, the start of the entire string, and the
position immediately after a newline character), while
<code>$</code> matches the end of any line (that is, the end of the
entire string, and the position immediately before a newline
character). Newline here means the character <code>#x0A</code>
only.</p>
<p>This means that the production in <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a>:</p>
<p><code>[10] Char ::= [^.\?*+()|#x5B#x5D]</code></p>
<p>is modified to read:</p>
<p><code>[10] Char ::= [^.\?*+{}()|^$#x5B#x5D]</code></p>
<p>The characters <code>#x5B</code> and <code>#x5D</code>
correspond to "<code>[</code>" and "<code>]</code>"
respectively.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The definition of Char (production [10]) in <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
has a known error in which it omits the left brace ("{") and right
brace ("}"). That error is corrected here.</p>
</div>
<p>The following production:</p>
<p><code>[11] charClass ::= charClassEsc | charClassExpr |
WildCardEsc</code></p>
<p>is modified to read:</p>
<p><code>[11] charClass ::= charClassEsc | charClassExpr |
WildCardEsc | "^" | "$"</code></p>
</li>
<li>
<p><em>Reluctant quantifiers</em> are supported. They are indicated
by a " <code>?</code> " following a quantifier. Specifically:</p>
<ul>
<li>
<p><code>X??</code> matches X, once or not at all</p>
</li>
<li>
<p><code>X*?</code> matches X, zero or more times</p>
</li>
<li>
<p><code>X+?</code> matches X, one or more times</p>
</li>
<li>
<p><code>X{n}?</code> matches X, exactly n times</p>
</li>
<li>
<p><code>X{n,}?</code> matches X, at least n times</p>
</li>
<li>
<p><code>X{n,m}?</code> matches X, at least n times, but not more
than m times</p>
</li>
</ul>
<p>The effect of these quantifiers is that the regular expression
matches the <em>shortest</em> possible substring consistent with
the match as a whole succeeding. Without the " <code>?</code> ",
the regular expression matches the <em>longest</em> possible
substring.</p>
<p>To achieve this, the production in <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a>:</p>
<p><code>[4] quantifier ::= [?*+] | ( '{' quantity '}' )</code></p>
<p>is changed to:</p>
<p><code>[4] quantifier ::= ( [?*+] | ( '{' quantity '}' ) )
'?'?</code></p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Reluctant quantifiers have no effect on the results of the
boolean <a href="#func-matches"><code>fn:matches</code></a>
function, since this function is only interested in discovering
whether a match exists, and not where it exists.</p>
</div>
</li>
<li>
<p>Sub-expressions (groups) within the regular expression are
recognized. The regular expression syntax defined by <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
allows a regular expression to contain parenthesized
sub-expressions, but attaches no special significance to them. The
<a href="#func-replace"><code>fn:replace()</code></a> function
described below allows 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
captured substring 1, the second identifies captured substring 2,
and so on. 0 identifies the substring captured by the entire
regular expression. If a sub-expression matches more than one
substring (because it is within a construct that allows
repetition), then only the <em>last</em> substring that it matched
will be captured.</p>
</li>
<li>
<p>Back-references are allowed. The construct <code>\n</code> where
<code>n</code> is a single digit is always recognized as a
back-reference; if this is followed by further digits, these digits
are taken to be part of the back-reference if and only if the
back-reference is preceded by sufficiently many capturing
subexpressions. A back-reference matches the string that was
matched by the <code>n</code>th capturing subexpression within the
regular expression, that is, the parenthesized subexpression whose
opening left parenthesis is the <code>n</code>th unescaped left
parenthesis within the regular expression. The closing right
parenthesis of this subexpression must occur before the
back-reference. For example, the regular expression
<code>('|").*\1</code> matches a sequence of characters delimited
either by an apostrophe at the start and end, or by a quotation
mark at the start and end.</p>
<p>If no string is matched by the <code>n</code>th capturing
subexpression, the back-reference is interpreted as matching a
zero-length string.</p>
<p>Back-references change the following production:</p>
<p><code>[23] charClassEsc ::= ( SingleCharEsc | MultiCharEsc |
catEsc | complEsc )</code></p>
<p>to</p>
<p><code>[23] charClassEsc ::= ( SingleCharEsc | MultiCharEsc |
catEsc | complEsc | backReference )</code></p>
<p><code>[23a] backReference ::= "\" [1-9][0-9]*</code></p>
</li>
<li>
<p>Single character escapes are extended to allow the
<code>$</code> character to be escaped. The following production is
changed:</p>
<p><code>[24]SingleCharEsc ::= '\'
[nrt\|.?*+(){}#x2D#x5B#x5D#x5E]</code></p>
<p>to</p>
<p><code>[24]SingleCharEsc ::= '\'
[nrt\|.?*+(){}$#x2D#x5B#x5D#x5E]</code></p>
</li>
</ul>
<div class="div4">
<h5><a name="flags" id="flags"></a>7.6.1.1 Flags</h5>
<p>All these functions provide an optional parameter,
<code>$flags</code>, to set options for the interpretation of the
regular expression. The parameter accepts a <code>xs:string</code>,
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 characters present that are
not defined here as flags, then an error is raised [<a href=
"#ERRFORX0001" title="err:FORX0001">err:FORX0001</a>].</p>
<p>The following options are defined:</p>
<ul>
<li>
<p><code>s</code>: If present, the match operates in "dot-all"
mode. (Perl calls this the single-line mode.) If the <code>s</code>
flag is not specified, the meta-character <code>.</code> matches
any character except a newline (<code>#x0A</code>) character. In
dot-all mode, the meta-character <code>.</code> matches any
character whatsoever. Suppose the input contains "hello" and
"world" on two lines. This will not be matched by the regular
expression "hello.*world" unless dot-all mode is enabled.</p>
</li>
<li>
<p><code>m</code>: If present, the match operates in multi-line
mode. By default, the meta-character <code>^</code> matches the
start of the entire string, while $ matches the end of the entire
string. In multi-line mode, <code>^</code> matches the start of any
line (that is, the start of the entire string, and the position
immediately after a newline character), while <code>$</code>
matches the end of any line (that is, the end of the entire string,
and the position immediately before a newline character). Newline
here means the character <code>#x0A</code> only.</p>
</li>
<li>
<p><code>i</code>: If present, the match operates in
case-insensitive mode. The detailed rules are as follows. In these
rules, a character C2 is considered to be a <em>case-variant</em>
of another character C1 if the following XPath expression returns
<code>true</code> when the two characters are considered as strings
of length one, and the Unicode codepoint collation is used:</p>
<p><a href="#func-lower-case"><code>fn:lower-case(C1) eq
fn:lower-case(C2)</code></a></p>
<p>or</p>
<p><a href="#func-upper-case"><code>fn:upper-case(C1) eq
fn:upper-case(C2)</code></a></p>
<p>Note that the case-variants of a character under this definition
are always single characters.</p>
<ol class="enumar">
<li>
<p>When a normal character (<code>Char</code>) is used as an atom,
it represents the set containing that character and all its
case-variants. For example, the regular expression "z" will match
both "z" and "Z".</p>
</li>
<li>
<p>A character range (<code>charRange</code>) represents the set
containing all the characters that it would match in the absence of
the "<code>i</code>" flag, together with their case-variants. For
example, the regular expression "[A-Z]" will match all the letters
A-Z and all the letters a-z. It will also match certain other
characters such as <code>#x212A</code> (KELVIN SIGN), since
<a href="#func-lower-case"><code>fn:lower-case("#x212A")</code></a>
is "k".</p>
<p>This rule applies also to a character range used in a character
class subtraction (<code>charClassSub</code>): thus [A-Z-[IO]] will
match characters such as "A", "B", "a", and "b", but will not match
"I", "O", "i", or "o".</p>
<p>The rule also applies to a character range used as part of a
negative character group: thus [^Q] will match every character
except "Q" and "q" (these being the only case-variants of "Q" in
Unicode).</p>
</li>
<li>
<p>A back-reference is compared using case-blind comparison: that
is, each character must either be the same as the corresponding
character of the previously matched string, or must be a
case-variant of that character. For example, the strings "Mum",
"mom", "Dad", and "DUD" all match the regular expression
"([md])[aeiou]\1" when the "<code>i</code>" flag is used.</p>
</li>
<li>
<p>All other constructs are unaffected by the "<code>i</code>"
flag. For example, "\p{Lu}" continues to match upper-case letters
only.</p>
</li>
</ol>
</li>
<li>
<p><code>x</code>: If present, whitespace characters (#x9, #xA, #xD
and #x20) in the regular expression are removed prior to matching
with one exception: whitespace characters within character class
expressions (<code>charClassExpr</code>) are not removed. This flag
can be used, for example, to break up long regular expressions into
readable lines.</p>
<p>Examples:</p>
<p><a href="#func-matches"><code>fn:matches("helloworld", "hello
world", "x")</code></a> returns <code>true</code></p>
<p><a href="#func-matches"><code>fn:matches("helloworld", "hello[
]world", "x")</code></a> returns <code>false</code></p>
<p><a href="#func-matches"><code>fn:matches("hello world", "hello\
sworld", "x")</code></a> returns <code>true</code></p>
<p><a href="#func-matches"><code>fn:matches("hello world", "hello
world", "x")</code></a> returns <code>false</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-matches" id="func-matches"></a>7.6.2
fn:matches</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:matches</code>(<code class=
"arg">$input</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$pattern</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:matches</code>(</td>
<td valign="baseline"><code class="arg">$input</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$pattern</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$flags</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: The function returns <code>true</code> if
<code>$input</code> matches the regular expression supplied as
<code>$pattern</code> as influenced by the value of
<code>$flags</code>, if present; otherwise, it returns
<code>false</code>.</p>
<p>The effect of calling the first version of this function
(omitting the argument <code>$flags</code>) is the same as the
effect of calling the second version with the <code>$flags</code>
argument set to a zero-length string. Flags are defined in <a href=
"#flags"><b>7.6.1.1 Flags</b></a>.</p>
<p>If <code>$input</code> is the empty sequence, it is interpreted
as the zero-length string.</p>
<p>Unless the metacharacters <code>^</code> and <code>$</code> 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).</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This is different from the behavior of patterns in <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>,
where regular expressions are <em>implicitly</em> anchored.</p>
</div>
<p>An error is raised [<a href="#ERRFORX0002" title=
"err:FORX0002">err:FORX0002</a>] if the value of
<code>$pattern</code> is invalid according to the rules described
in section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<p>An error is raised [<a href="#ERRFORX0001" title=
"err:FORX0001">err:FORX0001</a>] if the value of
<code>$flags</code> is invalid according to the rules described in
section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<div class="div4">
<h5><a name="func-matches-examples" id=
"func-matches-examples"></a>7.6.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:matches("abracadabra", "bra")</code> returns true</p>
</li>
<li>
<p><code>fn:matches("abracadabra", "^a.*a$")</code> returns
true</p>
</li>
<li>
<p><code>fn:matches("abracadabra", "^bra")</code> returns false</p>
</li>
</ul>
<p>Given the source document:</p>
<div class="exampleInner">
<pre>
&lt;poem author="Wilhelm Busch"&gt;
Kaum hat dies der Hahn gesehen,
Fängt er auch schon an zu krähen:
«Kikeriki! Kikikerikih!!»
Tak, tak, tak! - da kommen sie.
&lt;/poem&gt;
</pre></div>
<p>the following function calls produce the following results, with
the <code>poem</code> element as the context node:</p>
<ul>
<li>
<p><code>fn:matches(., "Kaum.*krähen")</code> returns
<code>false</code></p>
</li>
<li>
<p><code>fn:matches(., "Kaum.*krähen", "s")</code> returns
<code>true</code></p>
</li>
<li>
<p><code>fn:matches(., "^Kaum.*gesehen,$", "m")</code> returns
<code>true</code></p>
</li>
<li>
<p><code>fn:matches(., "^Kaum.*gesehen,$")</code> returns
<code>false</code></p>
</li>
<li>
<p><code>fn:matches(., "kiki", "i")</code> returns
<code>true</code></p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Regular expression matching is defined on the basis of Unicode
code points; it takes no account of collations.</p>
</div>
</div>
</div>
<div class="div3">
<h4><a name="func-replace" id="func-replace"></a>7.6.3
fn:replace</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:replace</code>(</td>
<td valign="baseline"><code class="arg">$input</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$pattern</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$replacement</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="4"><code class=
"function">fn:replace</code>(</td>
<td valign="baseline"><code class="arg">$input</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$pattern</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$replacement</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$flags</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: The function returns the <code>xs:string</code> that is
obtained by replacing each non-overlapping substring of
<code>$input</code> that matches the given <code>$pattern</code>
with an occurrence of the <code>$replacement</code> string.</p>
<p>The effect of calling the first version of this function
(omitting the argument <code>$flags</code>) is the same as the
effect of calling the second version with the <code>$flags</code>
argument set to a zero-length string. Flags are defined in <a href=
"#flags"><b>7.6.1.1 Flags</b></a>.</p>
<p>The <code>$flags</code> argument is interpreted in the same
manner as for the <a href=
"#func-matches"><code>fn:matches()</code></a> function.</p>
<p>If <code>$input</code> is the empty sequence, it is interpreted
as the zero-length string.</p>
<p>If two overlapping substrings of <code>$input</code> both match
the <code>$pattern</code>, then only the first one (that is, the
one whose first character comes first in the <code>$input</code>
string) is replaced.</p>
<p>Within the <code>$replacement</code> string, a variable
<code>$N</code> may be used to refer to the substring captured by
the Nth parenthesized sub-expression in the regular expression. For
each match of the pattern, these variables are assigned the value
of the content matched by the relevant sub-expression, and the
modified replacement string is then substituted for the characters
in <code>$input</code> that matched the pattern. <code>$0</code>
refers to the substring captured by the regular expression as a
whole.</p>
<p>More specifically, the rules are as follows, where
<code>S</code> is the number of parenthesized sub-expressions in
the regular expression, and <code>N</code> is the decimal number
formed by taking all the digits that consecutively follow the
<code>$</code> character:</p>
<ol class="enumar">
<li>
<p>If <code>N</code>=<code>0</code>, then the variable is replaced
by the substring matched by the regular expression as a whole.</p>
</li>
<li>
<p>If <code>1</code>&lt;=<code>N</code>&lt;=<code>S</code>, then
the variable is replaced by the substring captured by the Nth
parenthesized sub-expression. If the <code>Nth</code> parenthesized
sub-expression was not matched, then the variable is replaced by
the zero-length string.</p>
</li>
<li>
<p>If <code>S</code>&lt;<code>N</code>&lt;=<code>9</code>, then the
variable is replaced by the zero-length string.</p>
</li>
<li>
<p>Otherwise (if <code>N</code>&gt;<code>S</code> and
<code>N</code>&gt;<code>9</code>), the last digit of <code>N</code>
is taken to be a literal character to be included "as is" in the
replacement string, and the rules are reapplied using the number
<code>N</code> formed by stripping off this last digit.</p>
</li>
</ol>
<p>For example, if the replacement string is "<code>$23</code>" and
there are 5 substrings, the result contains the value of the
substring that matches the second sub-expression, followed by the
digit "<code>3</code>".</p>
<p>A literal "<code>$</code>" symbol must be written as
"<code>\$</code>".</p>
<p>A literal "<code>\</code>" symbol must be written as
"<code>\\</code>".</p>
<p>If two alternatives within the pattern both match at the same
position in the <code>$input</code>, then the match that is chosen
is the one matched by the first alternative. For example:</p>
<div class="exampleInner">
<pre>
fn:replace("abcd", "(ab)|(a)", "[1=$1][2=$2]") returns "[1=ab][2=]cd"
</pre></div>
<p>An error is raised [<a href="#ERRFORX0002" title=
"err:FORX0002">err:FORX0002</a>] if the value of
<code>$pattern</code> is invalid according to the rules described
in section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<p>An error is raised [<a href="#ERRFORX0001" title=
"err:FORX0001">err:FORX0001</a>] if the value of
<code>$flags</code> is invalid according to the rules described in
section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<p>An error is raised [<a href="#ERRFORX0003" title=
"err:FORX0003">err:FORX0003</a>] if the pattern matches a
zero-length string, that is, if the expression <a href=
"#func-matches"><code>fn:matches("", $pattern, $flags)</code></a>
returns <code>true</code>. It is not an error, however, if a
captured substring is zero-length.</p>
<p>An error is raised [<a href="#ERRFORX0004" title=
"err:FORX0004">err:FORX0004</a>] if the value of
<code>$replacement</code> contains a "<code>$</code>" character
that is not immediately followed by a digit <code>0-9</code> and
not immediately preceded by a "\".</p>
<p>An error is raised [<a href="#ERRFORX0004" title=
"err:FORX0004">err:FORX0004</a>] if the value of
<code>$replacement</code> contains a "<code>\</code>" character
that is not part of a "<code>\\</code>" pair, unless it is
immediately followed by a "<code>$</code>" character.</p>
<div class="div4">
<h5><a name="func-replace-examples" id=
"func-replace-examples"></a>7.6.3.1 Examples</h5>
<ul>
<li>
<p><code>replace("abracadabra", "bra", "*")</code> returns
<code>"a*cada*"</code></p>
</li>
<li>
<p><code>replace("abracadabra", "a.*a", "*")</code> returns
<code>"*"</code></p>
</li>
<li>
<p><code>replace("abracadabra", "a.*?a", "*")</code> returns
<code>"*c*bra"</code></p>
</li>
<li>
<p><code>replace("abracadabra", "a", "")</code> returns
<code>"brcdbr"</code></p>
</li>
<li>
<p><code>replace("abracadabra", "a(.)", "a$1$1")</code> returns
<code>"abbraccaddabbra"</code></p>
</li>
<li>
<p><code>replace("abracadabra", ".*?", "$1")</code> raises an
error, because the pattern matches the zero-length string</p>
</li>
<li>
<p><code>replace("AAAA", "A+", "b")</code> returns " <code>b</code>
"</p>
</li>
<li>
<p><code>replace("AAAA", "A+?", "b")</code> returns "
<code>bbbb</code> "</p>
</li>
<li>
<p><code>replace("darted", "^(.*?)d(.*)$", "$1c$2")</code> returns
" <code>carted</code> ". The first " <code>d</code> " is
replaced.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-tokenize" id="func-tokenize"></a>7.6.4
fn:tokenize</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:tokenize</code>(<code class=
"arg">$input</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$pattern</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string*</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:tokenize</code>(</td>
<td valign="baseline"><code class="arg">$input</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$pattern</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:string</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$flags</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string*</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: This function breaks the <code>$input</code> string
into a sequence of strings, treating any substring that matches
<code>$pattern</code> as a separator. The separators themselves are
not returned.</p>
<p>The effect of calling the first version of this function
(omitting the argument <code>$flags</code>) is the same as the
effect of calling the second version with the <code>$flags</code>
argument set to a zero-length string. Flags are defined in <a href=
"#flags"><b>7.6.1.1 Flags</b></a>.</p>
<p>The <code>$flags</code> argument is interpreted in the same way
as for the <a href="#func-matches"><code>fn:matches()</code></a>
function.</p>
<p>If <code>$input</code> is the empty sequence, or if
<code>$input</code> is the zero-length string, the result is the
empty sequence.</p>
<p>If the supplied <code>$pattern</code> matches a zero-length
string, that is, if <a href="#func-matches"><code>fn:matches("",
$pattern, $flags)</code></a> returns <code>true</code>, then an
error is raised: [<a href="#ERRFORX0003" title=
"err:FORX0003">err:FORX0003</a>].</p>
<p>If a separator occurs at the start of the <code>$input</code>
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 <code>$input</code> string, or
if two adjacent substrings match the supplied
<code>$pattern</code>.</p>
<p>If two alternatives within the supplied <code>$pattern</code>
both match at the same position in the <code>$input</code> string,
then the match that is chosen is the first. For example:</p>
<div class="exampleInner">
<pre>
fn:tokenize("abracadabra", "(ab)|(a)") returns ("", "r", "c", "d", "r", "")
</pre></div>
<p>An error is raised [<a href="#ERRFORX0002" title=
"err:FORX0002">err:FORX0002</a>] if the value of
<code>$pattern</code> is invalid according to the rules described
in section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<p>An error is raised [<a href="#ERRFORX0001" title=
"err:FORX0001">err:FORX0001</a>] if the value of
<code>$flags</code> is invalid according to the rules described in
section <a href="#regex-syntax"><b>7.6.1 Regular Expression
Syntax</b></a>.</p>
<div class="div4">
<h5><a name="func-tokenize-examples" id=
"func-tokenize-examples"></a>7.6.4.1 Examples</h5>
<ul>
<li>
<p><code>fn:tokenize("The cat sat on the mat", "\s+")</code>
returns <code>("The", "cat", "sat", "on", "the", "mat")</code></p>
</li>
<li>
<p><code>fn:tokenize("1, 15, 24, 50", ",\s*")</code> returns
<code>("1", "15", "24", "50")</code></p>
</li>
<li>
<p><code>fn:tokenize("1,15,,24,50,", ",")</code> returns
<code>("1", "15", "", "24", "50", "")</code></p>
</li>
<li>
<p><code>fn:tokenize("abba", ".?")</code> raises the error
[<a href="#ERRFORX0003" title="err:FORX0003">err:FORX0003</a>].</p>
</li>
<li>
<p><code>fn:tokenize("Some unparsed &lt;br&gt; HTML &lt;BR&gt;
text", "\s*&lt;br&gt;\s*", "i")</code> returns <code>("Some
unparsed", "HTML", "text")</code></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="anyURI-functions" id="anyURI-functions"></a>8
Functions on anyURI</h2>
<p>This section specifies functions that take anyURI as
arguments.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a></td>
<td>Returns an <code>xs:anyURI</code> representing an absolute
<code>xs:anyURI</code> given a base URI and a relative URI.</td>
</tr>
</tbody>
</table>
<div class="div2">
<h3><a name="func-resolve-uri" id="func-resolve-uri"></a>8.1
fn:resolve-uri</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:resolve-uri</code>(<code class=
"arg">$relative</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:resolve-uri</code>(<code class=
"arg">$relative</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$base</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<p>Summary: The purpose of this function is to enable a relative
URI to be resolved against an absolute URI.</p>
<p>The first form of this function resolves <code>$relative</code>
against the value of the base-uri property from the static context.
If the base-uri property is not initialized in the static context
an error is raised [<a href="#ERRFONS0005" title=
"err:FONS0005">err:FONS0005</a>].</p>
<p>If <code>$relative</code> is a relative URI reference, it is
resolved against <code>$base</code>, or the base-uri property from
the static context, using an algorithm such as the ones described
in <a href="#rfc2396">[RFC 2396]</a> or <a href="#rfc3986">[RFC
3986]</a>, and the resulting absolute URI reference is returned. An
error may be raised [<a href="#ERRFORG0009" title=
"err:FORG0009">err:FORG0009</a>] in the resolution process.</p>
<p>If <code>$relative</code> is an absolute URI reference, it is
returned unchanged.</p>
<p>If <code>$relative</code> or <code>$base</code> is not a valid
<code>xs:anyURI</code> an error is raised [<a href="#ERRFORG0002"
title="err:FORG0002">err:FORG0002</a>].</p>
<p>If <code>$relative</code> is the empty sequence, the empty
sequence is returned.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Resolving a URI does not dereference it. This is merely a
syntactic operation on two character strings.</p>
</div>
</div>
</div>
<div class="div1">
<h2><a name="boolean-functions" id="boolean-functions"></a>9
Functions and Operators on Boolean Values</h2>
<p>This section defines functions and operators on the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
boolean datatype.</p>
<div class="div2">
<h3><a name="boolean-constructors" id=
"boolean-constructors"></a>9.1 Additional Boolean Constructor
Functions</h3>
<p>The following additional constructor functions are defined on
the boolean type.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-true"><code>fn:true</code></a></td>
<td>Constructs the xs:boolean value 'true'.</td>
</tr>
<tr>
<td><a href="#func-false"><code>fn:false</code></a></td>
<td>Constructs the xs:boolean value 'false'.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-true" id="func-true"></a>9.1.1 fn:true</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:true</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns the <code>xs:boolean</code> value
<code>true</code>. Equivalent to <code>xs:boolean("1")</code>.</p>
<div class="div4">
<h5><a name="func-true-examples" id=
"func-true-examples"></a>9.1.1.1 Examples</h5>
<ul>
<li>
<p><code>fn:true()</code> returns <code>true</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-false" id="func-false"></a>9.1.2 fn:false</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:false</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns the <code>xs:boolean</code> value
<code>false</code>. Equivalent to <code>xs:boolean("0")</code>.</p>
<div class="div4">
<h5><a name="func-false-examples" id=
"func-false-examples"></a>9.1.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:false()</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="op.boolean" id="op.boolean"></a>9.2 Operators on
Boolean Values</h3>
<p>The following functions define the semantics of operators on
boolean values in <a href="#xquery">[XQuery 1.0: An XML Query
Language]</a> and <a href="#xpath20">[XML Path Language (XPath)
2.0]</a>:</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-boolean-equal"><code>op:boolean-equal</code></a></td>
<td>Equality of <code>xs:boolean</code> values</td>
</tr>
<tr>
<td><a href=
"#func-boolean-less-than"><code>op:boolean-less-than</code></a></td>
<td>A less-than operator on <code>xs:boolean</code> values:
<code>false</code> is less than <code>true</code>.</td>
</tr>
<tr>
<td><a href=
"#func-boolean-greater-than"><code>op:boolean-greater-than</code></a></td>
<td>A greater-than operator on <code>xs:boolean</code> values:
<code>true</code> is greater than <code>false</code>.</td>
</tr>
</tbody>
</table>
<p>The ordering operators <a href=
"#func-boolean-less-than"><code>op:boolean-less-than</code></a> and
<a href=
"#func-boolean-greater-than"><code>op:boolean-greater-than</code></a>
are provided for application purposes and for compatibility with
<a href="#xpath">[XML Path Language (XPath) Version 1.0]</a>. The
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> datatype <code>xs:boolean</code> is not ordered.</p>
<div class="div3">
<h4><a name="func-boolean-equal" id="func-boolean-equal"></a>9.2.1
op:boolean-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:boolean-equal</code>(<code class=
"arg">$value1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:boolean</code>,
<code class="arg">$value2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:boolean</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if both arguments are
<code>true</code> or if both arguments are <code>false</code>.
Returns <code>false</code> if one of the arguments is
<code>true</code> and the other argument is <code>false</code>.</p>
<p>This function backs up the "eq" operator on
<code>xs:boolean</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-boolean-less-than" id=
"func-boolean-less-than"></a>9.2.2 op:boolean-less-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:boolean-less-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:boolean</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:boolean</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if <code>$arg1</code> is
<code>false</code> and <code>$arg2</code> is <code>true</code>.
Otherwise, returns <code>false</code>.</p>
<p>This function backs up the "lt" and "ge" operators on
<code>xs:boolean</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-boolean-greater-than" id=
"func-boolean-greater-than"></a>9.2.3 op:boolean-greater-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:boolean-greater-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:boolean</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:boolean</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if <code>$arg1</code> is
<code>true</code> and <code>$arg2</code> is <code>false</code>.
Otherwise, returns <code>false</code>.</p>
<p>This function backs up the "gt" and "le" operators on
<code>xs:boolean</code> values.</p>
</div>
</div>
<div class="div2">
<h3><a name="boolean-value-functions" id=
"boolean-value-functions"></a>9.3 Functions on Boolean Values</h3>
<p>The following functions are defined on boolean values:</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-not"><code>fn:not</code></a></td>
<td>Inverts the <code>xs:boolean</code> value of the argument.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-not" id="func-not"></a>9.3.1 fn:not</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:not</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: <code>$arg</code> is first reduced to an effective
boolean value by applying the <a href=
"#func-boolean"><code>fn:boolean()</code></a> function. Returns
<code>true</code> if the effective boolean value is
<code>false</code>, and <code>false</code> if the effective boolean
value is <code>true</code>.</p>
<div class="div4">
<h5><a name="func-not-examples" id="func-not-examples"></a>9.3.1.1
Examples</h5>
<ul>
<li>
<p><code>fn:not(fn:true())</code> returns <code>false</code>.</p>
</li>
<li>
<p><code>fn:not("false")</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="durations-dates-times" id=
"durations-dates-times"></a>10 Functions and Operators on
Durations, Dates and Times</h2>
<p>This section discusses operations on the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
date and time types. It also discusses operations on two subtypes
of <code>xs:duration</code> that are defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup>. See <a href=
"#duration-subtypes"><b>10.3 Two Totally Ordered Subtypes of
Duration</b></a>.</p>
<p>See <a href="#Working-With-Timezones">[Working With
Timezones]</a> for a disquisition on working with date and time
values with and without timezones.</p>
<div class="div2">
<h3><a name="duration-date-time-types" id=
"duration-date-time-types"></a>10.1 Duration, Date and Time
Types</h3>
<p>The operators described in this section are defined on the
following date and time types:</p>
<ul>
<li>
<p>xs:dateTime</p>
</li>
<li>
<p>xs:date</p>
</li>
<li>
<p>xs:time</p>
</li>
<li>
<p>xs:gYearMonth</p>
</li>
<li>
<p>xs:gYear</p>
</li>
<li>
<p>xs:gMonthDay</p>
</li>
<li>
<p>xs:gMonth</p>
</li>
<li>
<p>xs:gDay</p>
</li>
</ul>
<p>Note that only equality is defined on
<code>xs:gYearMonth</code>, <code>xs:gYear</code>,
<code>xs:gMonthDay</code>, <code>xs:gMonth</code> and
<code>xs:gDay</code> values.</p>
<p>In addition, operators are defined on:</p>
<ul>
<li>
<p>xs:duration</p>
</li>
</ul>
<p>and on the <a href="#duration-subtypes"><b>10.3 Two Totally
Ordered Subtypes of Duration</b></a>:</p>
<ul>
<li>
<p>xs:yearMonthDuration</p>
</li>
<li>
<p>xs:dayTimeDuration</p>
</li>
</ul>
<p>Note that no ordering relation is defined on
<code>xs:duration</code> values.Two <code>xs:duration</code> values
may however be compared for equality. Operations on durations
(including equality comparison, casting to string, and extraction
of components) all treat the duration as normalized. This means
that the seconds and minutes components will always be less than
60, the hours component less than 24, and the months component less
than 12. Thus, for example, a duration of 120 seconds always gives
the same result as a duration of two minutes.</p>
<div class="div3">
<h4><a name="date-time-duration-conformance" id=
"date-time-duration-conformance"></a>10.1.1 Limits and
Precision</h4>
<p>For a number of the above datatypes <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> extends the basic
<a href="#ISO8601">[ISO 8601]</a> lexical representations, such as
YYYY-MM-DDThh:mm:ss.s for dateTime, by allowing a preceding minus
sign, more than four digits to represent the year field — no
maximum is specified — and an unlimited number of digits for
fractional seconds. Leap seconds are not supported.</p>
<p>All <em>minimally conforming</em> processors <a title="must"
class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> support
positive year values with a minimum of 4 digits (i.e., YYYY) and a
minimum fractional second precision of 1 millisecond or three
digits (i.e., s.sss). However, <em>conforming</em> processors
<a title="may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> set larger
<a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> limits on the maximum number of digits they
support in these two situations. Processors <a title="may" class=
"termref" href="#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> also choose to support the year 0000 and years
with negative values. The results of operations on dates that cross
the year 0000 are <a title="implementation-defined" class="termref"
href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>.</p>
<p>A processor that limits the number of digits in date and time
datatype representations may encounter overflow and underflow
conditions when it tries to execute the functions in <a href=
"#dateTime-arithmetic"><b>10.8 Arithmetic Operators on Durations,
Dates and Times</b></a>. In these situations, the processor
<a title="must" class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> return P0M or
PT0S in case of duration underflow and 00:00:00 in case of time
underflow. It <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> raise an error [<a href="#ERRFODT0001" title=
"err:FODT0001">err:FODT0001</a>] in case of overflow.</p>
<p>The value spaces of the two totally ordered subtypes of
<code>xs:duration</code> described in <a href=
"#duration-subtypes"><b>10.3 Two Totally Ordered Subtypes of
Duration</b></a> are <code>xs:integer</code> months for
<code>xs:yearMonthDuration</code> and <code>xs:decimal</code>
seconds for <code>xs:dayTimeDuration</code>. If a processor limits
the number of digits allowed in the representation of
<code>xs:integer</code> and <code>xs:decimal</code> then overflow
and underflow situations can arise when it tries to execute the
functions in <a href="#duration-arithmetic"><b>10.6 Arithmetic
Operators on Durations</b></a>. In these situations the processor
<a title="must" class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> return zero in
case of numeric underflow and P0M or PT0S in case of duration
underflow. It <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> raise an error [<a href="#ERRFODT0002" title=
"err:FODT0002">err:FODT0002</a>] in case of overflow.</p>
</div>
</div>
<div class="div2">
<h3><a name="date-time-values" id="date-time-values"></a>10.2
Date/time datatype values</h3>
<p>As defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#dates-and-times">Section
3.3.2 Dates and Times</a><sup><small>DM</small></sup>,
<code>xs:dateTime</code>, <code>xs:date</code>,
<code>xs:time</code>, <code>xs:gYearMonth</code>,
<code>xs:gYear</code>, <code>xs:gMonthDay</code>,
<code>xs:gMonth</code>, <code>xs:gDay</code> values, referred to
collectively as date/time values, are represented as seven
components or properties: <code>year</code>, <code>month</code>,
<code>day</code>, <code>hour</code>, <code>minute</code>,
<code>second</code> and <code>timezone</code>. The value of the
first five components are <code>xs:integer</code>s. The value of
the <code>second</code> component is an <code>xs:decimal</code> and
the value of the <code>timezone</code> component is an
<code>xs:dayTimeDuration</code>. For all the date/time datatypes,
the <code>timezone</code> property is optional and may or may not
be present. Depending on the datatype, some of the remaining six
properties must be present and some must be absent. Absent, or
missing, properties are represented by the empty sequence. This
value is referred to as the <em>local</em> value in that the value
is in the given timezone. Before comparing or subtracting
<code>xs:dateTime</code> values, this local value <a title="must"
class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> be translated
or <em>normalized</em> to UTC.</p>
<p>For <code>xs:time</code>, <code>"00:00:00"</code> and
<code>"24:00:00"</code> are alternate lexical forms for the same
value, whose canonical representation is <code>"00:00:00"</code>.
For <code>xs:dateTime</code>, a time component
<code>"24:00:00"</code> translates to <code>"00:00:00"</code> of
the following day.</p>
<div class="div3">
<h4><a name="date-time-lexical-mapping" id=
"date-time-lexical-mapping"></a>10.2.1 Examples</h4>
<ul>
<li>
<p>An <code>xs:dateTime</code> with lexical representation
<code>1999-05-31T05:00:00</code> is represented in the datamodel by
<code>{1999, 5, 31, 5, 0, 0.0, ()}</code>.</p>
</li>
<li>
<p>An <code>xs:dateTime</code> with lexical representation
<code>1999-05-31T13:20:00-05:00</code> is represented by
<code>{1999, 5, 31, 13, 20, 0.0, -PT5H}</code>.</p>
</li>
<li>
<p>An <code>xs:dateTime</code> with lexical representation
<code>1999-12-31T24:00:00</code> is represented by <code>{2000, 1,
1, 0, 0, 0.0, ()}</code>.</p>
</li>
<li>
<p>An <code>xs:date</code> with lexical representation
<code>2005-02-28+8:00</code> is represented by <code>{2005, 2, 28,
(), (), (), PT8H}</code>.</p>
</li>
<li>
<p>An <code>xs:time</code> with lexical representation
<code>24:00:00</code> is represented by <code>{(), (), (), 0, 0, 0,
()}</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="duration-subtypes" id="duration-subtypes"></a>10.3 Two
Totally Ordered Subtypes of Duration</h3>
<p>Two totally ordered subtypes of <code>xs:duration</code> are
defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> specification using the
mechanisms described in <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a> for defining user-defined types.
Additional details about these types is given below.</p>
<div class="div3">
<h4><a name="dt-yearMonthDuration" id=
"dt-yearMonthDuration"></a>10.3.1 xs:yearMonthDuration</h4>
<p>[Definition] <code>xs:yearMonthDuration</code> is derived from
<code>xs:duration</code> by restricting its lexical representation
to contain only the year and month components. The value space of
<code>xs:yearMonthDuration</code> is the set of
<code>xs:integer</code> month values. The year and month components
of <code>xs:yearMonthDuration</code> correspond to the Gregorian
year and month components defined in section 5.5.3.2 of <a href=
"#ISO8601">[ISO 8601]</a>, respectively.</p>
<div class="div4">
<h5><a name="lexical-yearMonthDuration" id=
"lexical-yearMonthDuration"></a>10.3.1.1 Lexical
representation</h5>
<p>The lexical representation for <code>xs:yearMonthDuration</code>
is the <a href="#ISO8601">[ISO 8601]</a> 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 unsigned
<code>xs:integer</code>.</p>
<p>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 <code>xs:yearMonthDuration</code> of 1
year, 2 months, one would write: P1Y2M. One could also indicate a
<code>xs:yearMonthDuration</code> of minus 13 months as: -P13M.</p>
<p>Reduced precision and truncated representations of this format
are allowed provided they conform to the following:</p>
<p>If the number of years or months in any expression equals zero
(0), the number and its corresponding designator <a title="may"
class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> be omitted.
However, at least one number and its designator <a title="must"
class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> be present.
For example, P1347Y and P1347M are allowed; P-1347M is not allowed,
although -P1347M is allowed. P1Y2MT is not allowed. Also, P24YM is
not allowed, nor is PY43M since Y must have at least one preceding
digit and M must have one preceding digit.</p>
</div>
<div class="div4">
<h5><a name="calculating-value-yearMonthDuration" id=
"calculating-value-yearMonthDuration"></a>10.3.1.2 Calculating the
value from the lexical representation</h5>
<p>The value of a <code>xs:yearMonthDuration</code> lexical form is
obtained by multiplying the value of the years component by 12 and
adding the value of the months component. The value is positive or
negative depending on the preceding sign.</p>
</div>
<div class="div4">
<h5><a name="canonical-yearMonthDuration" id=
"canonical-yearMonthDuration"></a>10.3.1.3 Canonical
representation</h5>
<p>The canonical representation of
<code>xs:yearMonthDuration</code> restricts the value of the months
component to <code>xs:integer</code> 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 <code>xs:integer</code> 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. For negative durations, the canonical
form is calculated using the absolute value of the duration and a
negative sign is prepended to it. If a component has the value zero
(0), then the number and the designator for that component
<a title="must" class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> be omitted.
However, if the value is zero (0) months, the canonical form is
"P0M".</p>
</div>
<div class="div4">
<h5><a name="order-yearMonthDuration" id=
"order-yearMonthDuration"></a>10.3.1.4 Order relation on
xs:yearMonthDuration</h5>
<p>Let the function that calculates the value of an
<code>xs:yearMonthDuration</code> in the manner described above be
called V(d). Then for two <code>xs:yearMonthDuration</code> values
x and y, x &gt; y if and only if V(x) &gt; V(y). The order relation
on <code>yearMonthDuration</code> is a total order.</p>
</div>
</div>
<div class="div3">
<h4><a name="dt-dayTimeDuration" id="dt-dayTimeDuration"></a>10.3.2
xs:dayTimeDuration</h4>
<p>[Definition] <code>xs:dayTimeDuration</code> is derived from
<code>xs:duration</code> by restricting its lexical representation
to contain only the days, hours, minutes and seconds components.
The value space of <code>xs:dayTimeDuration</code> is the set of
fractional second values. The components of
<code>xs:dayTimeDuration</code> correspond to the day, hour, minute
and second components defined in Section 5.5.3.2 of <a href=
"#ISO8601">[ISO 8601]</a>, respectively.</p>
<div class="div4">
<h5><a name="lexical-dayTimeDuration" id=
"lexical-dayTimeDuration"></a>10.3.2.1 Lexical representation</h5>
<p>The lexical representation for <code>xs:dayTimeDuration</code>
is the <a href="#ISO8601">[ISO 8601]</a> 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.</p>
<p>The values of the days, hours and minutes components are not
restricted, but allow an arbitrary unsigned
<code>xs:integer</code>. Similarly, the value of the seconds
component allows an arbitrary unsigned <code>xs:decimal</code>. 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 <a href="#ISO8601">[ISO 8601]</a> Date and Time
Formats.</p>
<p>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:</p>
<ul>
<li>
<p>If the number of days, hours, minutes, or seconds in any
expression equals zero (0), the number and its corresponding
designator <a title="may" class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> be omitted.
However, at least one number and its designator <a title="must"
class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> be
present.</p>
</li>
<li>
<p>The seconds part <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> have a decimal fraction.</p>
</li>
<li>
<p>The designator 'T' <a title="must" class="termref" href=
"#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> be absent if and only if all of the time items
are absent. The designator 'P' <a title="must" class="termref"
href="#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> always be present.</p>
</li>
</ul>
<p>For example, P13D, PT47H, P3DT2H, -PT35.89S and P4DT251M are all
allowed. P-134D is not allowed (invalid location of minus sign),
although -P134D is allowed.</p>
</div>
<div class="div4">
<h5><a name="calculating-value-dayTimeDuration" id=
"calculating-value-dayTimeDuration"></a>10.3.2.2 Calculating the
value of a xs:dayTimeDuration from the lexical representation</h5>
<p>The value of a <code>xs:dayTimeDuration</code> lexical form in
fractional seconds is obtained by converting the days, hours,
minutes and seconds value to fractional seconds using the
conversion rules: 24 hours = 1 day, 60 minutes = 1 hour and 60
seconds = 1 minute.</p>
</div>
<div class="div4">
<h5><a name="canonical-dayTimeDuration" id=
"canonical-dayTimeDuration"></a>10.3.2.3 Canonical
representation</h5>
<p>The canonical representation of <code>xs:dayTimeDuration</code>
restricts the value of the hours component to
<code>xs:integer</code> values between 0 and 23, both inclusive;
the value of the minutes component to <code>xs:integer</code>
values between 0 and 59; both inclusive; and the value of the
seconds component to <code>xs:decimal</code> valued from 0.0 to
59.999... (see <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a>, Appendix D).</p>
<p>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 86,400 (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 3,600 (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. For negative
durations, the canonical form is calculated using the absolute
value of the duration and a negative sign is prepended to it. If a
component has the value zero (0) then the number and the designator
for that component must be omitted. However, if all the components
of the lexical form are zero (0), the canonical form is "PT0S".</p>
</div>
<div class="div4">
<h5><a name="order-dayTimeDuration" id=
"order-dayTimeDuration"></a>10.3.2.4 Order relation on
xs:dayTimeDuration</h5>
<p>Let the function that calculates the value of a
<code>xs:dayTimeDuration</code> in the manner described above be
called <em>V(d)</em>. Then for two <code>xs:dayTimeDuration</code>
values <em>x</em> and <em>y, x &gt; y</em> if and only if <em>V(x)
&gt; V(y)</em>. The order relation on
<code>xs:dayTimeDuration</code> is a total order.</p>
</div>
</div>
</div>
<div class="div2">
<h3><a name="comp.duration.datetime" id=
"comp.duration.datetime"></a>10.4 Comparison Operators on Duration,
Date and Time Values</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-yearMonthDuration-less-than"><code>op:yearMonthDuration-less-than</code></a></td>
<td>Less-than comparison on <code>xs:yearMonthDuration</code>
values</td>
</tr>
<tr>
<td><a href=
"#func-yearMonthDuration-greater-than"><code>op:yearMonthDuration-greater-than</code></a></td>
<td>Greater-than comparison on <code>xs:yearMonthDuration</code>
values</td>
</tr>
<tr>
<td><a href=
"#func-dayTimeDuration-less-than"><code>op:dayTimeDuration-less-than</code></a></td>
<td>Less-than comparison on <code>xs:dayTimeDuration</code>
values</td>
</tr>
<tr>
<td><a href=
"#func-dayTimeDuration-greater-than"><code>op:dayTimeDuration-greater-than</code></a></td>
<td>Greater-than comparison on <code>xs:dayTimeDuration</code>
values</td>
</tr>
<tr>
<td><a href=
"#func-duration-equal"><code>op:duration-equal</code></a></td>
<td>Equality comparison on <code>xs:duration</code> values</td>
</tr>
<tr>
<td><a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a></td>
<td>Equality comparison on <code>xs:dateTime</code> values</td>
</tr>
<tr>
<td><a href=
"#func-dateTime-less-than"><code>op:dateTime-less-than</code></a></td>
<td>Less-than comparison on <code>xs:dateTime</code> values</td>
</tr>
<tr>
<td><a href=
"#func-dateTime-greater-than"><code>op:dateTime-greater-than</code></a></td>
<td>Greater-than comparison on <code>xs:dateTime</code> values</td>
</tr>
<tr>
<td><a href="#func-date-equal"><code>op:date-equal</code></a></td>
<td>Equality comparison on <code>xs:date</code> values</td>
</tr>
<tr>
<td><a href=
"#func-date-less-than"><code>op:date-less-than</code></a></td>
<td>Less-than comparison on <code>xs:date</code> values</td>
</tr>
<tr>
<td><a href=
"#func-date-greater-than"><code>op:date-greater-than</code></a></td>
<td>Greater-than comparison on <code>xs:date</code> values</td>
</tr>
<tr>
<td><a href="#func-time-equal"><code>op:time-equal</code></a></td>
<td>Equality comparison on <code>xs:time</code> values</td>
</tr>
<tr>
<td><a href=
"#func-time-less-than"><code>op:time-less-than</code></a></td>
<td>Less-than comparison on <code>xs:time</code> values</td>
</tr>
<tr>
<td><a href=
"#func-time-greater-than"><code>op:time-greater-than</code></a></td>
<td>Greater-than comparison on <code>xs:time</code> values</td>
</tr>
<tr>
<td><a href=
"#func-gYearMonth-equal"><code>op:gYearMonth-equal</code></a></td>
<td>Equality comparison on <code>xs:gYearMonth</code> values</td>
</tr>
<tr>
<td><a href=
"#func-gYear-equal"><code>op:gYear-equal</code></a></td>
<td>Equality comparison on <code>xs:gYear</code> values</td>
</tr>
<tr>
<td><a href=
"#func-gMonthDay-equal"><code>op:gMonthDay-equal</code></a></td>
<td>Equality comparison on <code>xs:gMonthDay</code> values</td>
</tr>
<tr>
<td><a href=
"#func-gMonth-equal"><code>op:gMonth-equal</code></a></td>
<td>Equality comparison on <code>xs:gMonth</code> values</td>
</tr>
<tr>
<td><a href="#func-gDay-equal"><code>op:gDay-equal</code></a></td>
<td>Equality comparison on <code>xs:gDay</code> values</td>
</tr>
</tbody>
</table>
<p>The following comparison operators are defined on the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
date, time and duration datatypes. Each operator takes two operands
of the same type and returns an <code>xs:boolean</code> result. As
discussed in <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a>, the order relation on <code>xs:duration</code>
is not a total order but, rather, a partial order. For this reason,
only equality is defined on <code>xs:duration</code>. A full
complement of comparison and arithmetic functions are defined on
the two subtypes of duration described in <a href=
"#duration-subtypes"><b>10.3 Two Totally Ordered Subtypes of
Duration</b></a> which do have a total order.</p>
<p><a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> also states that the order relation on date and time
datatypes is not a total order but a partial order because these
datatypes may or may not have a timezone. This is handled as
follows. If either operand to a comparison function on date or time
values does not have an (explicit) timezone then, for the purpose
of the operation, an implicit timezone, provided by the dynamic
context <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>, is assumed to be
present as part of the value. This creates a total order for all
date and time values.</p>
<p>An <code>xs:dateTime</code> can be considered to consist of
seven components: <code>year</code>, <code>month</code>,
<code>day</code>, <code>hour</code>, <code>minute</code>,
<code>second</code> and <code>timezone</code>. For
<code>xs:dateTime</code> six components: <code>year</code>,
<code>month</code>, <code>day</code>, <code>hour</code>,
<code>minute</code> and <code>second</code> are required and
<code>timezone</code> is optional. For other date/time values, of
the first six components, some are required and others must be
absent or missing. <code>Timezone</code> is always optional. For
example, for <code>xs:date</code>, the <code>year</code>,
<code>month</code> and <code>day</code> components are required and
<code>hour</code>, <code>minute</code> and <code>second</code>
components must be absent; for <code>xs:time</code> the
<code>hour</code>, <code>minute</code> and <code>second</code>
components are required and <code>year</code>, <code>month</code>
and <code>day</code> are missing; for <code>xs:gDay</code>,
<code>day</code> is required and <code>year</code>,
<code>month</code>, <code>hour</code>, <code>minute</code> and
<code>second</code> are missing.</p>
<p>Values of the date/time datatypes <code>xs:time</code>,
<code>xs:gMonthDay</code>, <code>xs:gMonth</code>, and
<code>xs:gDay</code>, can be considered to represent a sequence of
recurring time instants or time periods. An <code>xs:time</code>
occurs every day. An <code>xs:gMonth</code> occurs every year.
Comparison operators on these datatypes compare the starting
instants of equivalent occurrences in the recurring series. These
<code>xs:dateTime</code> values are calculated as described
below.</p>
<p>Comparison operators on <code>xs:date</code>,
<code>xs:gYearMonth</code> and <code>xs:gYear</code> compare their
starting instants. These <code>xs:dateTime</code> values are
calculated as described below.</p>
<p>The starting instant of an occurrence of a date/time value is an
<code>xs:dateTime</code> calculated by filling in the missing
components of the local value from a reference
<code>xs:dateTime</code>. If the value filled in for a missing day
component exceeds the maximum day value for the month, the last day
of the month is used. Suppose, for example, that the reference
<code>xs:dateTime</code> is <code>1972-12-31T00:00:00</code> and
the <code>xs:date</code> value to be compared is
<code>1993-03-31</code>. Filling in the time components from the
reference <code>xs:dateTime</code> we get
<code>1993-03-31T00:00:00</code> which is the starting instant of
that day. Similarly, if the <code>xs:time</code> value
<code>12:30:00</code> is to be compared, we fill in the missing
components from the reference <code>xs:dateTime</code> and we get
<code>1972-12-31T12:30:00</code> which is the time on that day. For
an <code>xs:gYearMonth</code> value of <code>1976-02</code> we fill
in the missing components, adjust for the last day in the month and
get <code>1976-02-29T00:00:00</code>.</p>
<p>If the <code>xs:time</code> value written as
<code>24:00:00</code> is to be compared, filling in the missing
components gives <code>1972-12-31T00:00:00</code>, because
<code>24:00:00</code> is an alternative representation of
<code>00:00:00</code> (the lexical value <code>"24:00:00"</code> is
converted to the time components {0,0,0} before the missing
components are filled in). This has the consequence that when
ordering <code>xs:time</code> values, <code>24:00:00</code> is
considered to be earlier than <code>23:59:59</code>. However, when
ordering <code>xs:dateTime</code> values, a time component of
<code>24:00:00</code> is considered equivalent to
<code>00:00:00</code> on the following day.</p>
<p>Note that the reference <code>xs:dateTime</code> does not have a
timezone. The <code>timezone</code> component is never filled in
from the reference <code>xs:dateTime</code>. In some cases, if the
date/time value does not have a timezone, the implicit timezone
from the dynamic context is used as the timezone.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This proposal uses the reference <code>xs:dateTime
1972-12-31T00:00:00</code> in the description of the comparison
operators. Implementations are allowed to use other reference
<code>xs:dateTime</code> values as long as they yield the same
results. The reference <code>xs:dateTime</code> used must meet the
following constraints: when it is used to supply components into
<code>xs:gMonthDay</code> values, the year must allow for February
29 and so must be a leap year; when it is used to supply missing
components into <code>xs:gDay</code> values, the month must allow
for 31 days. Different reference <code>xs:dateTime</code> values
may be used for different operators.</p>
</div>
<div class="div3">
<h4><a name="func-yearMonthDuration-less-than" id=
"func-yearMonthDuration-less-than"></a>10.4.1
op:yearMonthDuration-less-than</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:yearMonthDuration-less-than</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is less than <code>$arg2</code>. Returns
<code>false</code> otherwise.</p>
<p>This function backs up the "lt" and "le" operators on
<code>xs:yearMonthDuration</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-yearMonthDuration-greater-than" id=
"func-yearMonthDuration-greater-than"></a>10.4.2
op:yearMonthDuration-greater-than</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:yearMonthDuration-greater-than</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is greater than <code>$arg2</code>. Returns
<code>false</code> otherwise.</p>
<p>This function backs up the "gt" and "ge" operators on
<code>xs:yearMonthDuration</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-dayTimeDuration-less-than" id=
"func-dayTimeDuration-less-than"></a>10.4.3
op:dayTimeDuration-less-than</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:dayTimeDuration-less-than</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is less than <code>$arg2</code>. Returns
<code>false</code> otherwise.</p>
<p>This function backs up the "lt" and "le" operators on
<code>xs:dayTimeDuration</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-dayTimeDuration-greater-than" id=
"func-dayTimeDuration-greater-than"></a>10.4.4
op:dayTimeDuration-greater-than</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:dayTimeDuration-greater-than</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if
<code>$arg1</code> is greater than <code>$arg2</code>. Returns
<code>false</code> otherwise.</p>
<p>This function backs up the "gt" and "ge" operators on
<code>xs:dayTimeDuration</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-duration-equal" id=
"func-duration-equal"></a>10.4.5 op:duration-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:duration-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:duration</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:duration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the
<code>xs:yearMonthDuration</code> and the
<code>xs:dayTimeDuration</code> components of <code>$arg1</code>
and <code>$arg2</code> compare equal respectively. Returns
<code>false</code> otherwise.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:duration</code> values.</p>
<p>Note that this function, like any other, may be applied to
arguments that are derived from the types given in the function
signature, including the two subtypes
<code>xs:dayTimeDuration</code> and
<code>xs:yearMonthDuration</code>. With the exception of the
zero-length duration, no instance of
<code>xs:dayTimeDuration</code> can ever be equal to an instance of
<code>xs:yearMonthDuration</code>.</p>
<p>The semantics of this function are:</p>
<div class="exampleInner">
<pre>
xs:yearMonthDuration($arg1) div xs:yearMonthDuration('P1M') eq
xs:yearMonthDuration($arg2) div xs:yearMonthDuration('P1M')
and
xs:dayTimeDuration($arg1) div xs:dayTimeDuration('PT1S') eq
xs:dayTimeDuration($arg2) div xs:dayTimeDuration('PT1S')
</pre></div>
<p>that is, the function returns <code>true</code> if the months
and seconds values of the two durations are equal.</p>
<div class="div4">
<h5><a name="func-duration-equal-examples" id=
"func-duration-equal-examples"></a>10.4.5.1 Examples</h5>
<ul>
<li>
<p><code>op:duration-equal(xs:duration("P1Y"),
xs:duration("P12M"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:duration("PT24H"),
xs:duration("P1D"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:duration("P1Y"),
xs:duration("P365D"))</code> returns <code>false</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:yearMonthDuration("P0Y"),
xs:dayTimeDuration("PT0D"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:yearMonthDuration("P1Y"),
xs:dayTimeDuration("PT365D"))</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:yearMonthDuration("P2Y"),
xs:yearMonthDuration("P24M"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:dayTimeDuration("PT10D"),
xs:dayTimeDuration("PT240H"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:duration("P2Y0M0DT0H0M0S"),
xs:yearMonthDuration("P24M"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:duration-equal(xs:duration("P0Y0M10D"),
xs:dayTimeDuration("PT240H"))</code> returns <code>true</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-dateTime-equal" id=
"func-dateTime-equal"></a>10.4.6 op:dateTime-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:dateTime-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:dateTime</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> is equal to the value of <code>$arg2</code>
according to the algorithm defined in section 3.2.7.4 of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
"Order relation on dateTime" for <code>xs:dateTime</code> values
with timezones. Returns <code>false</code> otherwise.</p>
<p>This function backs up the "eq", "ne", "le" and "ge" operators
on <code>xs:dateTime</code> values.</p>
<div class="div4">
<h5><a name="func-dateTime-equal-examples" id=
"func-dateTime-equal-examples"></a>10.4.6.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>.</p>
<ul>
<li>
<p>
<code>op:dateTime-equal(xs:dateTime("2002-04-02T12:00:00-01:00"),
xs:dateTime("2002-04-02T17:00:00+04:00"))</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:dateTime-equal(xs:dateTime("2002-04-02T12:00:00"),
xs:dateTime("2002-04-02T23:00:00+06:00"))</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:dateTime-equal(xs:dateTime("2002-04-02T12:00:00"),
xs:dateTime("2002-04-02T17:00:00"))</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>op:dateTime-equal(xs:dateTime("2002-04-02T12:00:00"),
xs:dateTime("2002-04-02T12:00:00"))</code> returns
<code>true</code>.</p>
</li>
<li>
<p>
<code>op:dateTime-equal(xs:dateTime("2002-04-02T23:00:00-04:00"),
xs:dateTime("2002-04-03T02:00:00-01:00"))</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:dateTime-equal(xs:dateTime("1999-12-31T24:00:00"),
xs:dateTime("2000-01-01T00:00:00"))</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:dateTime-equal(xs:dateTime("2005-04-04T24:00:00"),
xs:dateTime("2005-04-04T00:00:00"))</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-dateTime-less-than" id=
"func-dateTime-less-than"></a>10.4.7 op:dateTime-less-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:dateTime-less-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:dateTime</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> is less than the value of <code>$arg2</code>
according to the algorithm defined in section 3.2.7.4 of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
"Order relation on dateTime" for <code>xs:dateTime</code> values
with timezones. Returns <code>false</code> otherwise.</p>
<p>This function backs up the "lt" and "le" operators on
<code>xs:dateTime</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-dateTime-greater-than" id=
"func-dateTime-greater-than"></a>10.4.8
op:dateTime-greater-than</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:dateTime-greater-than</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> is greater than the value of <code>$arg2</code>
according to the algorithm defined in section 3.2.7.4 of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
"Order relation on dateTime" for <code>xs:dateTime</code> values
with timezones. Returns <code>false</code> otherwise.</p>
<p>This function backs up the "gt" and "ge" operators on
<code>xs:dateTime</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-date-equal" id="func-date-equal"></a>10.4.9
op:date-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:date-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:date</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the starting
instant of <code>$arg1</code> is equal to starting instant of
<code>$arg2</code>. Returns <code>false</code> otherwise.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at time <code>00:00:00</code> on that
date.</p>
<p>The two starting instants are compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq", "ne", "le" and "ge" operators
on <code>xs:date</code> values.</p>
<div class="div4">
<h5><a name="func-date-equal-examples" id=
"func-date-equal-examples"></a>10.4.9.1 Examples</h5>
<ul>
<li>
<p><code>op:date-equal(xs:date("2004-12-25Z"),
xs:date("2004-12-25+07:00"))</code> returns <code>false</code>. The
starting instants are
<code>xs:dateTime("2004-12-25T00:00:00Z")</code> and
<code>xs:dateTime("2004-12-25T00:00:00+07:00")</code>. These are
normalized to <code>xs:dateTime("2004-12-25T00:00:00Z")</code> and
<code>xs:dateTime("2004-12-24T17:00:00Z")</code>.</p>
</li>
<li>
<p><code>op:date-equal(xs:date("2004-12-25-12:00"),
xs:date("2004-12-26+12:00"))</code> returns <code>true</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-date-less-than" id=
"func-date-less-than"></a>10.4.10 op:date-less-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:date-less-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:date</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the starting
instant of <code>$arg1</code> is less than the starting instant of
<code>$arg2</code>. Returns <code>false</code> otherwise.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at time <code>00:00:00</code> on that
date.</p>
<p>The two starting instants are compared using <a href=
"#func-dateTime-less-than"><code>op:dateTime-less-than</code></a>.</p>
<p>This function backs up the "lt" and "le" operators on
<code>xs:date</code> values.</p>
<div class="div4">
<h5><a name="func-date-less-than-examples" id=
"func-date-less-than-examples"></a>10.4.10.1 Examples</h5>
<ul>
<li>
<p><code>op:date-less-than(xs:date("2004-12-25Z"),
xs:date("2004-12-25-05:00"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:date-less-than(xs:date("2004-12-25-12:00"),
xs:date("2004-12-26+12:00"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-date-greater-than" id=
"func-date-greater-than"></a>10.4.11 op:date-greater-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:date-greater-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:date</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the starting
instant of <code>$arg1</code> is greater than the starting instant
of <code>$arg2</code>. Returns <code>false</code> otherwise.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at time <code>00:00:00</code> on that
date.</p>
<p>The two starting instants are compared using <a href=
"#func-dateTime-greater-than"><code>op:dateTime-greater-than</code></a>.</p>
<p>This function backs up the "gt" and "ge" operators on
<code>xs:date</code> values.</p>
<div class="div4">
<h5><a name="date-greater-than-examples" id=
"date-greater-than-examples"></a>10.4.11.1 Examples</h5>
<ul>
<li>
<p><code>op:date-greater-than(xs:date("2004-12-25Z"),
xs:date("2004-12-25+07:00"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:date-greater-than(xs:date("2004-12-25-12:00"),
xs:date("2004-12-26+12:00"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-time-equal" id="func-time-equal"></a>10.4.12
op:time-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:time-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:time</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> converted to an <code>xs:dateTime</code> using
the date components from the reference <code>xs:dateTime</code> is
equal to the value of <code>$arg2</code> converted to an
<code>xs:dateTime</code> using the date components from the same
reference <code>xs:dateTime</code>. Returns <code>false</code>
otherwise.</p>
<p>The two <code>xs:dateTime</code> values are compared using
<a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq", "ne", "le" and "ge" operators
on <code>xs:time</code> values.</p>
<div class="div4">
<h5><a name="func-time-equals-examples" id=
"func-time-equals-examples"></a>10.4.12.1 Examples</h5>
<p>Assume that the date components from the reference
<code>xs:dateTime</code> correspond to <code>1972-12-31</code>.</p>
<ul>
<li>
<p><code>op:time-equal(xs:time("08:00:00+09:00"),
xs:time("17:00:00-06:00"))</code> returns <code>false</code>. The
<code>xs:dateTime</code>s calculated using the reference date
components are <code>1972-12-31T08:00:00+09:00</code> and
<code>1972-12-31T17:00:00-06:00</code>. These normalize to
<code>1972-12-30T23:00:00Z</code> and
<code>1972-12-31T23:00:00</code>.</p>
</li>
<li>
<p><code>op:time-equal(xs:time("21:30:00+10:30"),
xs:time("06:00:00-05:00"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:time-equal(xs:time("24:00:00+01:00"),
xs:time("00:00:00+01:00"))</code> returns <code>true</code>. This
not the result one might expect. For <code>xs:dateTime</code>
values, a time of <code>24:00:00</code> is equivalent to
<code>00:00:00</code> on the following day. For
<code>xs:time</code>, the normalization from <code>24:00:00</code>
to <code>00:00:00</code> happens before the <code>xs:time</code> is
converted into an <code>xs:dateTime</code> for the purpose of the
equality comparison. For <code>xs:time</code>, any operation on
<code>24:00:00</code> produces the same result as the same
operation on <code>00:00:00</code> because these are two different
lexical representations of the same value.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-time-less-than" id=
"func-time-less-than"></a>10.4.13 op:time-less-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:time-less-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:time</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> converted to an <code>xs:dateTime</code> using
the date components from the reference <code>xs:dateTime</code> is
less than the normalized value of <code>$arg2</code> converted to
an <code>xs:dateTime</code> using the date components from the same
reference <code>xs:dateTime</code>. Returns <code>false</code>
otherwise.</p>
<p>The two <code>xs:dateTime</code> values are compared using
<a href=
"#func-dateTime-less-than"><code>op:dateTime-less-than</code></a>.</p>
<p>This function backs up the "lt" and "le" operators on
<code>xs:time</code> values.</p>
<div class="div4">
<h5><a name="func-time-less-than-examples" id=
"func-time-less-than-examples"></a>10.4.13.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>.</p>
<ul>
<li>
<p><code>op:time-less-than(xs:time("12:00:00"),
xs:time("23:00:00+06:00"))</code> returns <code>false</code>.</p>
</li>
<li>
<p><code>op:time-less-than(xs:time("11:00:00"),
xs:time("17:00:00Z"))</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>op:time-less-than(xs:time("23:59:59"),
xs:time("24:00:00"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-time-greater-than" id=
"func-time-greater-than"></a>10.4.14 op:time-greater-than</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:time-greater-than</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:time</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the value of
<code>$arg1</code> converted to an <code>xs:dateTime</code> using
the date components from the reference <code>xs:dateTime</code> is
greater than the value of <code>$arg2</code> converted to an
<code>xs:dateTime</code> using the date components from the same
reference <code>xs:dateTime</code>. Returns <code>false</code>
otherwise.</p>
<p>The two <code>xs:dateTime</code> values are compared using
<a href=
"#func-dateTime-greater-than"><code>op:dateTime-greater-than</code></a>.</p>
<p>This function backs up the "gt" and "ge" operators on
<code>xs:time</code> values.</p>
<div class="div4">
<h5><a name="func-time-greater-than-examples" id=
"func-time-greater-than-examples"></a>10.4.14.1 Examples</h5>
<ul>
<li>
<p><code>op:time-greater-than(xs:time("08:00:00+09:00"),
xs:time("17:00:00-06:00"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-gYearMonth-equal" id=
"func-gYearMonth-equal"></a>10.4.15 op:gYearMonth-equal</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:gYearMonth-equal</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gYearMonth</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gYearMonth</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if and only if the
<code>xs:dateTime</code>s representing the starting instants of
<code>$arg1</code> and <code>$arg2</code> compare equal. The
starting instants of <code>$arg1</code> and <code>$arg2</code> are
calculated by adding the missing components of <code>$arg1</code>
and <code>$arg2</code> from the <code>xs:dateTime</code> template
<code>xxxx-xx-ddT00:00:00</code> where <code>dd</code> represents
the last day of the <code>month</code> component in
<code>$arg1</code> or <code>$arg2</code>. Returns
<code>false</code> otherwise.</p>
<p>The two <code>xs:dateTime</code> values representing the
starting instants of <code>$arg1</code> and <code>$arg2</code> are
compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:gYearMonth</code> values.</p>
<div class="div4">
<h5><a name="func-gYearMonth-equal-examples" id=
"func-gYearMonth-equal-examples"></a>10.4.15.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>.</p>
<ul>
<li>
<p><code>op:gYearMonth-equal(xs:gYearMonth("1976-02"),
xs:gYearMonth("1976-03Z"))</code> returns <code>false</code>. The
starting instants are <code>1972-02-29T00:00:00-05:00</code> and
<code>1972-03-31T00:00:00Z</code>, respectively.</p>
</li>
<li>
<p><code>op:gYearMonth-equal(xs:gYearMonth("1976-03"),
xs:gYearMonth("1976-03Z"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-gYear-equal" id="func-gYear-equal"></a>10.4.16
op:gYear-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:gYear-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:gYear</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gYear</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the
<code>xs:dateTime</code>s representing the starting instants of
<code>$arg1</code> and <code>$arg2</code> compare equal. The
starting instants of <code>$arg1</code> and <code>$arg2</code> are
calculated by adding the missing components of <code>$arg1</code>
and <code>$arg2</code> from a <code>xs:dateTime</code> template
such as <code>xxxx-01-01T00:00:00</code>. Returns
<code>false</code> otherwise.</p>
<p>The two <code>xs:dateTime</code> values representing the
starting instants of <code>$arg1</code> and <code>$arg2</code> are
compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:gYear</code> values.</p>
<div class="div4">
<h5><a name="func-gYear-equal-examples" id=
"func-gYear-equal-examples"></a>10.4.16.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>. Assume, also, that the
<code>xs:dateTime</code> template is
<code>xxxx-01-01T00:00:00</code>.</p>
<ul>
<li>
<p><code>op:gYear-equal(xs:gYear("2005-12:00"),
xs:gYear("2005+12:00"))</code> returns <code>false</code>. The
starting instants are <code>2005-01-01T00:00:00-12:00</code> and
<code>2005-01-01T00:00:00+12:00</code>, respectively, and normalize
to <code>2005-01-015T12:00:00Z</code> and
<code>2004-12-31T12:00:00Z</code>.</p>
</li>
<li>
<p><code>op:gYear-equal(xs:gYear("1976-05:00"),
xs:gYear("1976"))</code> returns <code>true</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-gMonthDay-equal" id=
"func-gMonthDay-equal"></a>10.4.17 op:gMonthDay-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:gMonthDay-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:gMonthDay</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gMonthDay</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Summary: Returns <code>true</code> if and only if the
<code>xs:dateTime</code>s representing the starting instants of
equivalent occurrences of <code>$arg1</code> and <code>$arg2</code>
compare equal. The starting instants of equivalent occurrences of
<code>$arg1</code> and <code>$arg2</code> are calculated by adding
the missing components of <code>$arg1</code> and <code>$arg2</code>
from an <code>xs:dateTime</code> template such as
<code>1972-xx-xxT00:00:00</code>. Returns <code>false</code>
otherwise.</p>
<p>The two <code>xs:dateTime</code> values representing the
starting instants of equivalent occurrences of <code>$arg1</code>
and <code>$arg2</code> are compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:gMonthDay</code> values.</p>
<div class="div4">
<h5><a name="func-gMonthDay-equal-examples" id=
"func-gMonthDay-equal-examples"></a>10.4.17.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>. Assume, also, that the
<code>xs:dateTime</code> template is
<code>1976-xx-xxT00:00:00</code>.</p>
<ul>
<li>
<p><code>op:gMonthDay-equal(xs:gMonthDay("--12-25-14:00"),
xs:gMonthDay("--12-26+10:00"))</code> returns <code>true</code>.
The starting instants are <code>1976-12-25T00:00:00-14:00</code>
and <code>1976-12-26T00:00:00+10:00</code>, respectively, and
normalize to <code>1976-12-25T14:00:00Z</code> and
<code>1976-12-25T14:00:00Z</code>.</p>
</li>
<li>
<p><code>op:gMonthDay-equal(xs:gMonthDay("--12-25"),
xs:gMonthDay("--12-26Z"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-gMonth-equal" id="func-gMonth-equal"></a>10.4.18
op:gMonth-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:gMonth-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:gMonth</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gMonth</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the
<code>xs:dateTime</code>s representing the starting instants of
equivalent occurrences of <code>$arg1</code> and <code>$arg2</code>
compare equal. The starting instants of equivalent occurrences of
<code>$arg1</code> and <code>$arg2</code> are calculated by adding
the missing components of <code>$arg1</code> and <code>$arg2</code>
from an <code>xs:dateTime</code> template such as
<code>1972-xx-ddT00:00:00</code> where <code>dd</code> represents
the last day of the month component in <code>$arg1</code> or
<code>$arg2</code>. Returns <code>false</code> otherwise.</p>
<p>The two <code>xs:dateTime</code> values representing the
starting instants of equivalent occurrences of <code>$arg1</code>
and <code>$arg2</code> are compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:gMonth</code> values.</p>
<div class="div4">
<h5><a name="func-gMonth-equal-examples" id=
"func-gMonth-equal-examples"></a>10.4.18.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>. Assume, also, that the
<code>xs:dateTime</code> template is
<code>1972-xx-29T00:00:00</code>.</p>
<ul>
<li>
<p><code>op:gMonth-equal(xs:gMonth("--12-14:00"),
xs:gMonth("--12+10:00")</code> returns <code>false</code>. The
starting instants are <code>1972-12-29T00:00:00-14:00</code> and
<code>1972-12-29T00:00:00+10:00</code>, respectively, and normalize
to <code>1972-12-29T14:00:00Z</code> and
<code>1972-12-28T14:00:00Z</code>.</p>
</li>
<li>
<p><code>op:gMonth-equal(xs:gMonth("--12"),
xs:gMonth("--12Z"))</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-gDay-equal" id="func-gDay-equal"></a>10.4.19
op:gDay-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:gDay-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:gDay</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:gDay</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if and only if the
<code>xs:dateTime</code>s representing the starting instants of
equivalent occurrences of <code>$arg1</code> and <code>$arg2</code>
compare equal. The starting instants of equivalent occurrences of
<code>$arg1</code> and <code>$arg2</code> are calculated by adding
the missing components of <code>$arg1</code> and <code>$arg2</code>
from an <code>xs:dateTime</code> template such as
<code>1972-12-xxT00:00:00</code>. Returns <code>false</code>
otherwise.</p>
<p>The two <code>xs:dateTime</code> values representing the
starting instants of equivalent occurrences of <code>$arg1</code>
and <code>$arg2</code> are compared using <a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:gDay</code> values.</p>
<div class="div4">
<h5><a name="func-gDay-equal-examples" id=
"func-gDay-equal-examples"></a>10.4.19.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>. Assume, also, that the
<code>xs:dateTime</code> template is
<code>1976-12-xxT00:00:00</code>.</p>
<ul>
<li>
<p><code>op:gDay-equal(xs:gDay("---25-14:00"),
xs:gDay("---25+10:00"))</code> returns <code>false</code>. The
starting instants are <code>1972-12-25T00:00:00-14:00</code> and
<code>1972-12-25T00:00:00+10:00</code>, respectively, and normalize
to <code>1972-12-25T14:00:00Z</code> and
<code>1972-12-24T14:00:00Z</code>.</p>
</li>
<li>
<p><code>op:gDay-equal(xs:gDay("---12"), xs:gDay("---12Z"))</code>
returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="component-extraction-functions" id=
"component-extraction-functions"></a>10.5 Component Extraction
Functions on Durations, Dates and Times</h3>
<p>The duration, date and time datatypes may be considered to be
composite datatypes in that they contain distinct properties or
components. The extraction functions specified below extract a
single component from a duration, date or time value. For the
date/time datatypes the local value is used. For
<code>xs:duration</code> and its subtypes, including the two
subtypes <code>xs:yearMonthDuration</code> and
<code>xs:dayTimeDuration</code>, the components are normalized:
this means that the seconds and minutes components will always be
less than 60, the hours component less than 24, and the months
component less than 12.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-years-from-duration"><code>fn:years-from-duration</code></a></td>
<td>Returns the year component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-months-from-duration"><code>fn:months-from-duration</code></a></td>
<td>Returns the months component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-days-from-duration"><code>fn:days-from-duration</code></a></td>
<td>Returns the days component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-hours-from-duration"><code>fn:hours-from-duration</code></a></td>
<td>Returns the hours component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-minutes-from-duration"><code>fn:minutes-from-duration</code></a></td>
<td>Returns the minutes component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-seconds-from-duration"><code>fn:seconds-from-duration</code></a></td>
<td>Returns the seconds component of an <code>xs:duration</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-year-from-dateTime"><code>fn:year-from-dateTime</code></a></td>
<td>Returns the year from an <code>xs:dateTime</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-month-from-dateTime"><code>fn:month-from-dateTime</code></a></td>
<td>Returns the month from an <code>xs:dateTime</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-day-from-dateTime"><code>fn:day-from-dateTime</code></a></td>
<td>Returns the day from an <code>xs:dateTime</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-hours-from-dateTime"><code>fn:hours-from-dateTime</code></a></td>
<td>Returns the hours from an <code>xs:dateTime</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-minutes-from-dateTime"><code>fn:minutes-from-dateTime</code></a></td>
<td>Returns the minutes from an <code>xs:dateTime</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-seconds-from-dateTime"><code>fn:seconds-from-dateTime</code></a></td>
<td>Returns the seconds from an <code>xs:dateTime</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-timezone-from-dateTime"><code>fn:timezone-from-dateTime</code></a></td>
<td>Returns the timezone from an <code>xs:dateTime</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-year-from-date"><code>fn:year-from-date</code></a></td>
<td>Returns the year from an <code>xs:date</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-month-from-date"><code>fn:month-from-date</code></a></td>
<td>Returns the month from an <code>xs:date</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-day-from-date"><code>fn:day-from-date</code></a></td>
<td>Returns the day from an <code>xs:date</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-timezone-from-date"><code>fn:timezone-from-date</code></a></td>
<td>Returns the timezone from an <code>xs:date</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-hours-from-time"><code>fn:hours-from-time</code></a></td>
<td>Returns the hours from an <code>xs:time</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-minutes-from-time"><code>fn:minutes-from-time</code></a></td>
<td>Returns the minutes from an <code>xs:time</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-seconds-from-time"><code>fn:seconds-from-time</code></a></td>
<td>Returns the seconds from an <code>xs:time</code> value.</td>
</tr>
<tr>
<td><a href=
"#func-timezone-from-time"><code>fn:timezone-from-time</code></a></td>
<td>Returns the timezone from an <code>xs:time</code> value.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-years-from-duration" id=
"func-years-from-duration"></a>10.5.1 fn:years-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:years-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
years component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:yearMonthDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the years component as described
in <a href="#canonical-yearMonthDuration"><b>10.3.1.3 Canonical
representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:dayTimeDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-years-from-duration-examples" id=
"func-years-from-duration-examples"></a>10.5.1.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:years-from-duration(xs:yearMonthDuration("P20Y15M"))</code>
returns <code>21</code>.</p>
</li>
<li>
<p>
<code>fn:years-from-duration(xs:yearMonthDuration("-P15M"))</code>
returns <code>-1</code>.</p>
</li>
<li>
<p>
<code>fn:years-from-duration(xs:dayTimeDuration("-P2DT15H"))</code>
returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-months-from-duration" id=
"func-months-from-duration"></a>10.5.2 fn:months-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:months-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
months component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:yearMonthDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the months component as described
in <a href="#canonical-yearMonthDuration"><b>10.3.1.3 Canonical
representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:dayTimeDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-months-from-duration-examples" id=
"func-months-from-duration-examples"></a>10.5.2.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:months-from-duration(xs:yearMonthDuration("P20Y15M"))</code>
returns <code>3</code>.</p>
</li>
<li>
<p>
<code>fn:months-from-duration(xs:yearMonthDuration("-P20Y18M"))</code>
returns <code>-6</code>.</p>
</li>
<li>
<p>
<code>fn:months-from-duration(xs:dayTimeDuration("-P2DT15H0M0S"))</code>
returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-days-from-duration" id=
"func-days-from-duration"></a>10.5.3 fn:days-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:days-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
days component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:dayTimeDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the days component as described
in <a href="#canonical-dayTimeDuration"><b>10.3.2.3 Canonical
representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:yearMonthDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-days-from-duration-examples" id=
"func-days-from-duration-examples"></a>10.5.3.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:days-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
returns <code>3</code>.</p>
</li>
<li>
<p>
<code>fn:days-from-duration(xs:dayTimeDuration("P3DT55H"))</code>
returns <code>5</code>.</p>
</li>
<li>
<p>
<code>fn:days-from-duration(xs:yearMonthDuration("P3Y5M"))</code>
returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-hours-from-duration" id=
"func-hours-from-duration"></a>10.5.4 fn:hours-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:hours-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
hours component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:dayTimeDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the hours component as described
in <a href="#canonical-dayTimeDuration"><b>10.3.2.3 Canonical
representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:yearMonthDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-hours-from-duration-examples" id=
"func-hours-from-duration-examples"></a>10.5.4.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:hours-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
returns <code>10</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-duration(xs:dayTimeDuration("P3DT12H32M12S"))</code>
returns <code>12</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-duration(xs:dayTimeDuration("PT123H"))</code>
returns <code>3</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-duration(xs:dayTimeDuration("-P3DT10H"))</code>
returns <code>-10</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-minutes-from-duration" id=
"func-minutes-from-duration"></a>10.5.5
fn:minutes-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:minutes-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
minutes component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:dayTimeDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the minutes component as
described in <a href="#canonical-dayTimeDuration"><b>10.3.2.3
Canonical representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:yearMonthDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-minutes-from-duration-examples" id=
"func-minutes-from-duration-examples"></a>10.5.5.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:minutes-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
returns <code>0</code>.</p>
</li>
<li>
<p>
<code>fn:minutes-from-duration(xs:dayTimeDuration("-P5DT12H30M"))</code>
returns <code>-30</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-seconds-from-duration" id=
"func-seconds-from-duration"></a>10.5.6
fn:seconds-from-duration</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:seconds-from-duration</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:duration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal?</code></div>
</div>
<p>Summary: Returns an <code>xs:decimal</code> representing the
seconds component in the value of <code>$arg</code>. The result is
obtained by casting <code>$arg</code> to an
<code>xs:dayTimeDuration</code> (see <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration
types</b></a>) and then computing the seconds component as
described in <a href="#canonical-dayTimeDuration"><b>10.3.2.3
Canonical representation</b></a>.</p>
<p>The result may be negative.</p>
<p>If <code>$arg</code> is an <code>xs:yearMonthDuration</code>
returns 0.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-seconds-from-duration-examples" id=
"func-seconds-from-duration-examples"></a>10.5.6.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:seconds-from-duration(xs:dayTimeDuration("P3DT10H12.5S"))</code>
returns <code>12.5</code>.</p>
</li>
<li>
<p>
<code>fn:seconds-from-duration(xs:dayTimeDuration("-P256S"))</code>
returns <code>-16.0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-year-from-dateTime" id=
"func-year-from-dateTime"></a>10.5.7 fn:year-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:year-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
year component in the localized value of <code>$arg</code>. The
result may be negative.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-year-from-dateTime-examples" id=
"func-year-from-dateTime-examples"></a>10.5.7.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns <code>1999</code>.</p>
</li>
<li>
<p>
<code>fn:year-from-dateTime(xs:dateTime("1999-05-31T21:30:00-05:00"))</code>
returns <code>1999</code>.</p>
</li>
<li>
<p>
<code>fn:year-from-dateTime(xs:dateTime("1999-12-31T19:20:00"))</code>
returns <code>1999</code>.</p>
</li>
<li>
<p>
<code>fn:year-from-dateTime(xs:dateTime("1999-12-31T24:00:00"))</code>
returns <code>2000</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-month-from-dateTime" id=
"func-month-from-dateTime"></a>10.5.8 fn:month-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:month-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 1 and 12,
both inclusive, representing the month component in the localized
value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-month-from-dateTime-examples" id=
"func-month-from-dateTime-examples"></a>10.5.8.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns <code>5</code>.</p>
</li>
<li>
<p>
<code>fn:month-from-dateTime(xs:dateTime("1999-12-31T19:20:00-05:00"))</code>
returns <code>12</code>.</p>
</li>
<li>
<p>
<code>fn:month-from-dateTime(fn:adjust-dateTime-to-timezone(xs:dateTime("1999-12-31T19:20:00-05:00"),
xs:dayTimeDuration("PT0S")))</code> returns <code>1</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-day-from-dateTime" id=
"func-day-from-dateTime"></a>10.5.9 fn:day-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:day-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 1 and 31,
both inclusive, representing the day component in the localized
value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-day-from-dateTime-examples" id=
"func-day-from-dateTime-examples"></a>10.5.9.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:day-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns <code>31</code>.</p>
</li>
<li>
<p>
<code>fn:day-from-dateTime(xs:dateTime("1999-12-31T20:00:00-05:00"))</code>
returns <code>31</code>.</p>
</li>
<li>
<p>
<code>fn:day-from-dateTime(fn:adjust-dateTime-to-timezone(xs:dateTime("1999-12-31T19:20:00-05:00"),
xs:dayTimeDuration("PT0S")))</code> returns <code>1</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-hours-from-dateTime" id=
"func-hours-from-dateTime"></a>10.5.10 fn:hours-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:hours-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 0 and 23,
both inclusive, representing the hours component in the localized
value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-hours-from-dateTime-examples" id=
"func-hours-from-dateTime-examples"></a>10.5.10.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:hours-from-dateTime(xs:dateTime("1999-05-31T08:20:00-05:00"))</code>
returns <code>8</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T21:20:00-05:00"))</code>
returns <code>21</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-dateTime(fn:adjust-dateTime-to-timezone(xs:dateTime("1999-12-31T21:20:00-05:00"),
xs:dayTimeDuration("PT0S")))</code> returns <code>2</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T12:00:00"))</code>
returns <code>12</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T24:00:00"))</code>
returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-minutes-from-dateTime" id=
"func-minutes-from-dateTime"></a>10.5.11
fn:minutes-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:minutes-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> value between 0 and
59, both inclusive, representing the minute component in the
localized value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-minutes-from-dateTime-examples" id=
"func-minutes-from-dateTime-examples"></a>10.5.11.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns <code>20</code> .</p>
</li>
<li>
<p>
<code>fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:30:00+05:30"))</code>
returns <code>30</code> .</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-seconds-from-dateTime" id=
"func-seconds-from-dateTime"></a>10.5.12
fn:seconds-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:seconds-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal?</code></div>
</div>
<p>Summary: Returns an <code>xs:decimal</code> value greater than
or equal to zero and less than 60, representing the seconds and
fractional seconds in the localized value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-seconds-from-dateTime-examples" id=
"func-seconds-from-dateTime-examples"></a>10.5.12.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns <code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-timezone-from-dateTime" id=
"func-timezone-from-dateTime"></a>10.5.13
fn:timezone-from-dateTime</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:timezone-from-dateTime</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></div>
</div>
<p>Summary: Returns the timezone component of <code>$arg</code> if
any. If <code>$arg</code> has a timezone component, then the result
is an <code>xs:dayTimeDuration</code> that indicates deviation from
UTC; its value may range from +14:00 to -14:00 hours, both
inclusive. Otherwise, the result is the empty sequence.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-timezone-from-dateTime-examples" id=
"func-timezone-from-dateTime-examples"></a>10.5.13.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:timezone-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
returns the <code>xs:dayTimeDuration</code> whose value is
<code>-PT5H</code>.</p>
</li>
<li>
<p>
<code>fn:timezone-from-dateTime(xs:dateTime("2000-06-12T13:20:00Z"))</code>
returns the <code>xs:dayTimeDuration</code> whose value is
<code>PT0S</code>.</p>
</li>
<li>
<p>
<code>fn:timezone-from-dateTime(xs:dateTime("2004-08-27T00:00:00"))</code>
returns <code>()</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-year-from-date" id=
"func-year-from-date"></a>10.5.14 fn:year-from-date</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:year-from-date</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:date?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> representing the
year in the localized value of <code>$arg</code>. The value may be
negative.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-year-from-date-examples" id=
"func-year-from-date-examples"></a>10.5.14.1 Examples</h5>
<ul>
<li>
<p><code>fn:year-from-date(xs:date("1999-05-31"))</code> returns
<code>1999</code>.</p>
</li>
<li>
<p><code>fn:year-from-date(xs:date("2000-01-01+05:00"))</code>
returns <code>2000</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-month-from-date" id=
"func-month-from-date"></a>10.5.15 fn:month-from-date</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:month-from-date</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:date?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 1 and 12,
both inclusive, representing the month component in the localized
value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-month-from-date-examples" id=
"func-month-from-date-examples"></a>10.5.15.1 Examples</h5>
<ul>
<li>
<p><code>fn:month-from-date(xs:date("1999-05-31-05:00"))</code>
returns <code>5</code> .</p>
</li>
<li>
<p><code>fn:month-from-date(xs:date("2000-01-01+05:00"))</code>
returns <code>1</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-day-from-date" id=
"func-day-from-date"></a>10.5.16 fn:day-from-date</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:day-from-date</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:date?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 1 and 31,
both inclusive, representing the day component in the localized
value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-day-from-date-examples" id=
"func-day-from-date-examples"></a>10.5.16.1 Examples</h5>
<ul>
<li>
<p><code>fn:day-from-date(xs:date("1999-05-31-05:00"))</code>
returns <code>31</code>.</p>
</li>
<li>
<p><code>fn:day-from-date(xs:date("2000-01-01+05:00"))</code>
returns <code>1</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-timezone-from-date" id=
"func-timezone-from-date"></a>10.5.17 fn:timezone-from-date</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:timezone-from-date</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:date?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></div>
</div>
<p>Summary: Returns the timezone component of <code>$arg</code> if
any. If <code>$arg</code> has a timezone component, then the result
is an <code>xs:dayTimeDuration</code> that indicates deviation from
UTC; its value may range from +14:00 to -14:00 hours, both
inclusive. Otherwise, the result is the empty sequence.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-timezone-from-date-examples" id=
"func-timezone-from-date-examples"></a>10.5.17.1 Examples</h5>
<ul>
<li>
<p><code>fn:timezone-from-date(xs:date("1999-05-31-05:00"))</code>
returns the <code>xs:dayTimeDuration</code> whose value is
<code>-PT5H</code>.</p>
</li>
<li>
<p><code>fn:timezone-from-date(xs:date("2000-06-12Z"))</code>
returns the <code>xs:dayTimeDuration</code> with value
<code>PT0S</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-hours-from-time" id=
"func-hours-from-time"></a>10.5.18 fn:hours-from-time</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:hours-from-time</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> between 0 and 23,
both inclusive, representing the value of the hours component in
the localized value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-hours-from-time-examples" id=
"func-hours-from-time-examples"></a>10.5.18.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>.</p>
<ul>
<li>
<p><code>fn:hours-from-time(xs:time("11:23:00"))</code> returns
<code>11</code>.</p>
</li>
<li>
<p><code>fn:hours-from-time(xs:time("21:23:00"))</code> returns
<code>21</code>.</p>
</li>
<li>
<p><code>fn:hours-from-time(xs:time("01:23:00+05:00"))</code>
returns <code>1</code>.</p>
</li>
<li>
<p>
<code>fn:hours-from-time(fn:adjust-time-to-timezone(xs:time("01:23:00+05:00"),
xs:dayTimeDuration("PT0S")))</code> returns <code>20</code>.</p>
</li>
<li>
<p><code>fn:hours-from-time(xs:time("24:00:00"))</code> returns
<code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-minutes-from-time" id=
"func-minutes-from-time"></a>10.5.19 fn:minutes-from-time</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:minutes-from-time</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</div>
<p>Summary: Returns an <code>xs:integer</code> value between 0 and
59, both inclusive, representing the value of the minutes component
in the localized value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-minutes-from-time-examples" id=
"func-minutes-from-time-examples"></a>10.5.19.1 Examples</h5>
<ul>
<li>
<p><code>fn:minutes-from-time(xs:time("13:00:00Z"))</code> returns
<code>0</code> .</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-seconds-from-time" id=
"func-seconds-from-time"></a>10.5.20 fn:seconds-from-time</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:seconds-from-time</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal?</code></div>
</div>
<p>Summary: Returns an <code>xs:decimal</code> value greater than
or equal to zero and less than 60, representing the seconds and
fractional seconds in the localized value of <code>$arg</code>.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-seconds-from-time-examples" id=
"func-seconds-from-time-examples"></a>10.5.20.1 Examples</h5>
<ul>
<li>
<p><code>fn:seconds-from-time(xs:time("13:20:10.5"))</code> returns
<code>10.5</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-timezone-from-time" id=
"func-timezone-from-time"></a>10.5.21 fn:timezone-from-time</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:timezone-from-time</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></div>
</div>
<p>Summary: Returns the timezone component of <code>$arg</code> if
any. If <code>$arg</code> has a timezone component, then the result
is an <code>xs:dayTimeDuration</code> that indicates deviation from
UTC; its value may range from +14:00 to -14:00 hours, both
inclusive. Otherwise, the result is the empty sequence.</p>
<p>If <code>$arg</code> is the empty sequence, returns the empty
sequence.</p>
<div class="div4">
<h5><a name="func-timezone-from-time-examples" id=
"func-timezone-from-time-examples"></a>10.5.21.1 Examples</h5>
<ul>
<li>
<p><code>fn:timezone-from-time(xs:time("13:20:00-05:00"))</code>
returns <code>xs:dayTimeDuration</code> whose value is
<code>-PT5H</code>.</p>
</li>
<li>
<p><code>fn:timezone-from-time(xs:time("13:20:00"))</code> returns
<code>()</code>.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="duration-arithmetic" id="duration-arithmetic"></a>10.6
Arithmetic Operators on Durations</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-add-yearMonthDurations"><code>op:add-yearMonthDurations</code></a></td>
<td>Adds two <code>xs:yearMonthDuration</code>s. Returns an
<code>xs:yearMonthDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-yearMonthDurations"><code>op:subtract-yearMonthDurations</code></a></td>
<td>Subtracts one <code>xs:yearMonthDuration</code> from another.
Returns an <code>xs:yearMonthDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-multiply-yearMonthDuration"><code>op:multiply-yearMonthDuration</code></a></td>
<td>Multiplies a <code>xs:yearMonthDuration</code> by an
<code>xs:double</code>. Returns an
<code>xs:yearMonthDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-divide-yearMonthDuration"><code>op:divide-yearMonthDuration</code></a></td>
<td>Divides an <code>xs:yearMonthDuration</code> by an
<code>xs:double</code>. Returns an
<code>xs:yearMonthDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-divide-yearMonthDuration-by-yearMonthDuration"><code>op:divide-yearMonthDuration-by-yearMonthDuration</code></a></td>
<td>Divides an <code>xs:yearMonthDuration</code> by an
<code>xs:yearMonthDuration</code>. Returns an
<code>xs:decimal</code>.</td>
</tr>
<tr>
<td><a href=
"#func-add-dayTimeDurations"><code>op:add-dayTimeDurations</code></a></td>
<td>Adds two <code>xs:dayTimeDurations</code>. Returns an
<code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-dayTimeDurations"><code>op:subtract-dayTimeDurations</code></a></td>
<td>Subtracts one <code>xs:dayTimeDuration</code> from another.
Returns an <code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-multiply-dayTimeDuration"><code>op:multiply-dayTimeDuration</code></a></td>
<td>Multiplies an <code>xs:dayTimeDuration</code> by a
<code>xs:double</code>. Returns an
<code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-divide-dayTimeDuration"><code>op:divide-dayTimeDuration</code></a></td>
<td>Divides an <code>xs:dayTimeDuration</code> by an
<code>xs:double</code>. Returns an
<code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-divide-dayTimeDuration-by-dayTimeDuration"><code>op:divide-dayTimeDuration-by-dayTimeDuration</code></a></td>
<td>Divides an <code>xs:dayTimeDuration</code> by an
<code>xs:dayTimeDuration</code>. Returns an
<code>xs:decimal</code>.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-add-yearMonthDurations" id=
"func-add-yearMonthDurations"></a>10.6.1
op:add-yearMonthDurations</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-yearMonthDurations</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:yearMonthDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of adding the value of
<code>$arg1</code> to the value of <code>$arg2</code>. Backs up the
"+" operator on <code>xs:yearMonthDuration</code> values.</p>
<div class="div4">
<h5><a name="func-add-yearMonthDurations-examples" id=
"func-add-yearMonthDurations-examples"></a>10.6.1.1 Examples</h5>
<ul>
<li>
<p><code>op:add-yearMonthDurations(xs:yearMonthDuration("P2Y11M"),
xs:yearMonthDuration("P3Y3M"))</code> returns a
<code>xs:yearMonthDuration</code> value corresponding to 6 years
and 2 months.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-yearMonthDurations" id=
"func-subtract-yearMonthDurations"></a>10.6.2
op:subtract-yearMonthDurations</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-yearMonthDurations</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:yearMonthDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of subtracting the value of
<code>$arg2</code> from the value of <code>$arg1</code>. Backs up
the "-" operator on <code>xs:yearMonthDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-yearMonthDurations-examples" id=
"func-subtract-yearMonthDurations-examples"></a>10.6.2.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-yearMonthDurations(xs:yearMonthDuration("P2Y11M"),
xs:yearMonthDuration("P3Y3M"))</code> returns a
<code>xs:yearMonthDuration</code> value corresponding to negative 4
months.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-multiply-yearMonthDuration" id=
"func-multiply-yearMonthDuration"></a>10.6.3
op:multiply-yearMonthDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:multiply-yearMonthDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:yearMonthDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of multiplying the value of
<code>$arg1</code> by <code>$arg2</code>. The result is rounded to
the nearest month. For a value <em>v</em>, 0 &lt;= <em>v</em> &lt;
0.5 rounds to 0; 0.5 &lt;= <em>v</em> &lt; 1.0 rounds to 1.</p>
<p>If <code>$arg2</code> is positive or negative zero, the result
is a zero-length duration. If <code>$arg2</code> is positive or
negative infinity, the result overflows and is handled as discussed
in <a href="#date-time-duration-conformance"><b>10.1.1 Limits and
Precision</b></a>. If <code>$arg2</code> is <code>NaN</code> an
error is raised [<a href="#ERRFOCA0005" title=
"err:FOCA0005">err:FOCA0005</a>]</p>
<p>Backs up the "*" operator on <code>xs:yearMonthDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-multiply-yearMonthDurations-examples" id=
"func-multiply-yearMonthDurations-examples"></a>10.6.3.1
Examples</h5>
<ul>
<li>
<p>
<code>op:multiply-yearMonthDuration(xs:yearMonthDuration("P2Y11M"),
2.3)</code> returns a <code>xs:yearMonthDuration</code> value
corresponding to 6 years and 9 months.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-divide-yearMonthDuration" id=
"func-divide-yearMonthDuration"></a>10.6.4
op:divide-yearMonthDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:divide-yearMonthDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:yearMonthDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of dividing the value of
<code>$arg1</code> by <code>$arg2</code>. The result is rounded to
the nearest month. For a value <em>v</em>, 0 &lt;= <em>v</em> &lt;
0.5 rounds to 0; 0.5 &lt;= <em>v</em> &lt; 1.0 rounds to 1.</p>
<p>If <code>$arg2</code> is positive or negative infinity, the
result is a zero-length duration. If <code>$arg2</code> is positive
or negative zero, the result overflows and is handled as discussed
in <a href="#date-time-duration-conformance"><b>10.1.1 Limits and
Precision</b></a>. If <code>$arg2</code> is <code>NaN</code> an
error is raised [<a href="#ERRFOCA0005" title=
"err:FOCA0005">err:FOCA0005</a>]</p>
<p>Backs up the "div" operator on <code>xs:yearMonthDuration</code>
and numeric values.</p>
<div class="div4">
<h5><a name="func-divide-yearMonthDurations-examples" id=
"func-divide-yearMonthDurations-examples"></a>10.6.4.1
Examples</h5>
<ul>
<li>
<p>
<code>op:divide-yearMonthDuration(xs:yearMonthDuration("P2Y11M"),
1.5)</code> returns a <code>xs:yearMonthDuration</code> value
corresponding to 1 year and 11 months.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-divide-yearMonthDuration-by-yearMonthDuration"
id="func-divide-yearMonthDuration-by-yearMonthDuration"></a>10.6.5
op:divide-yearMonthDuration-by-yearMonthDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:divide-yearMonthDuration-by-yearMonthDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of dividing the value of
<code>$arg1</code> by <code>$arg2</code>. Since the values of both
operands are integers, the semantics of the division is identical
to <a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a> with
<code>xs:integer</code> operands.</p>
<p>Backs up the "div" operator on <code>xs:yearMonthDuration</code>
values.</p>
<div class="div4">
<h5><a name=
"func-divide-yearMonthDuration-by-yearMonthDuration-examples" id=
"func-divide-yearMonthDuration-by-yearMonthDuration-examples"></a>10.6.5.1
Examples</h5>
<ul>
<li>
<p>
<code>op:divide-yearMonthDuration-by-yearMonthDuration(xs:yearMonthDuration("P3Y4M"),
xs:yearMonthDuration("-P1Y4M"))</code> returns
<code>-2.5</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-dayTimeDurations" id=
"func-add-dayTimeDurations"></a>10.6.6 op:add-dayTimeDurations</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-dayTimeDurations</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of adding the value of
<code>$arg1</code> to the value of <code>$arg2</code>. Backs up the
"+" operator on <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-add-dayTimeDurations-examples" id=
"func-add-dayTimeDurations-examples"></a>10.6.6.1 Examples</h5>
<ul>
<li>
<p><code>op:add-dayTimeDurations(xs:dayTimeDuration("P2DT12H5M"),
xs:dayTimeDuration("P5DT12H"))</code> returns a
<code>xs:dayTimeDuration</code> value corresponding to 8 days and 5
minutes.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-dayTimeDurations" id=
"func-subtract-dayTimeDurations"></a>10.6.7
op:subtract-dayTimeDurations</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-dayTimeDurations</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of subtracting the value of
<code>$arg2</code> from the value of <code>$arg1</code>. Backs up
the "-" operator on <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-dayTimeDurations-examples" id=
"func-subtract-dayTimeDurations-examples"></a>10.6.7.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-dayTimeDurations(xs:dayTimeDuration("P2DT12H"),
xs:dayTimeDuration("P1DT10H30M"))</code> returns a
<code>xs:dayTimeDuration</code> value corresponding to 1 day, 1
hour and 30 minutes.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-multiply-dayTimeDuration" id=
"func-multiply-dayTimeDuration"></a>10.6.8
op:multiply-dayTimeDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:multiply-dayTimeDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of multiplying the value of
<code>$arg1</code> by <code>$arg2</code>.</p>
<p>If <code>$arg2</code> is positive or negative zero, the result
is a zero-length duration. If <code>$arg2</code> is positive or
negative infinity, the result overflows and is handled as discussed
in <a href="#date-time-duration-conformance"><b>10.1.1 Limits and
Precision</b></a>. If <code>$arg2</code> is <code>NaN</code> an
error is raised [<a href="#ERRFOCA0005" title=
"err:FOCA0005">err:FOCA0005</a>]</p>
<p>Backs up the "*" operator on <code>xs:dayTimeDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-multiply-yearMonthDuration-examples" id=
"func-multiply-yearMonthDuration-examples"></a>10.6.8.1
Examples</h5>
<ul>
<li>
<p><code>op:multiply-dayTimeDuration(xs:dayTimeDuration("PT2H10M"),
2.1)</code> returns a <code>xs:dayTimeDuration</code> value
corresponding to 4 hours and 33 minutes.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-divide-dayTimeDuration" id=
"func-divide-dayTimeDuration"></a>10.6.9
op:divide-dayTimeDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:divide-dayTimeDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of dividing the value of
<code>$arg1</code> by <code>$arg2</code>.</p>
<p>If <code>$arg2</code> is positive or negative infinity, the
result is a zero-length duration. If <code>$arg2</code> is positive
or negative zero, the result overflows and is handled as discussed
in <a href="#date-time-duration-conformance"><b>10.1.1 Limits and
Precision</b></a>. If <code>$arg2</code> is <code>NaN</code> an
error is raised [<a href="#ERRFOCA0005" title=
"err:FOCA0005">err:FOCA0005</a>]</p>
<p>Backs up the "div" operator on <code>xs:dayTimeDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-divide-yearMonthDuration-examples" id=
"func-divide-yearMonthDuration-examples"></a>10.6.9.1 Examples</h5>
<ul>
<li>
<p>
<code>op:divide-dayTimeDuration(xs:yearMonthDuration("P1DT2H30M10.5S"),
1.5)</code> returns a <code>xs:dayTimeDuration</code> value
corresponding to 17 hours, 40 minutes and 7 seconds.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-divide-dayTimeDuration-by-dayTimeDuration" id=
"func-divide-dayTimeDuration-by-dayTimeDuration"></a>10.6.10
op:divide-dayTimeDuration-by-dayTimeDuration</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:divide-dayTimeDuration-by-dayTimeDuration</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:decimal</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the result of dividing the value of
<code>$arg1</code> by <code>$arg2</code>. Since the values of both
operands are decimals, the semantics of the division is identical
to <a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a> with
<code>xs:decimal</code> operands.</p>
<p>Backs up the "div" operator on <code>xs:dayTimeDuration</code>
values.</p>
<div class="div4">
<h5><a name=
"func-divide-dayTimeDuration-by-dayTimeDuration-examples" id=
"func-divide-dayTimeDuration-by-dayTimeDuration-examples"></a>10.6.10.1
Examples</h5>
<ul>
<li>
<p>
<code>op:divide-dayTimeDuration-by-dayTimeDuration(xs:dayTimeDuration("P2DT53M11S"),
xs:dayTimeDuration("P1DT10H))</code> returns
<code>1.4378349...</code></p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="timezone.functions" id="timezone.functions"></a>10.7
Timezone Adjustment Functions on Dates and Time Values</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone</code></a></td>
<td>Adjusts an <code>xs:dateTime</code> value to a specific
timezone, or to no timezone at all.</td>
</tr>
<tr>
<td><a href=
"#func-adjust-date-to-timezone"><code>fn:adjust-date-to-timezone</code></a></td>
<td>Adjusts an <code>xs:date</code> value to a specific timezone,
or to no timezone at all.</td>
</tr>
<tr>
<td><a href=
"#func-adjust-time-to-timezone"><code>fn:adjust-time-to-timezone</code></a></td>
<td>Adjusts an <code>xs:time</code> value to a specific timezone,
or to no timezone at all.</td>
</tr>
</tbody>
</table>
<p>These functions adjust the timezone component of an
<code>xs:dateTime</code>, <code>xs:date</code> or
<code>xs:time</code> value. The <code>$timezone</code> argument to
these functions is defined as an <code>xs:dayTimeDuration</code>
but must be a valid timezone value.</p>
<div class="div3">
<h4><a name="func-adjust-dateTime-to-timezone" id=
"func-adjust-dateTime-to-timezone"></a>10.7.1
fn:adjust-dateTime-to-timezone</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:adjust-dateTime-to-timezone</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime?</code></div>
</div>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:adjust-dateTime-to-timezone</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$timezone</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Adjusts an <code>xs:dateTime</code> value to a specific
timezone, or to no timezone at all. If <code>$timezone</code> is
the empty sequence, returns an <code>xs:dateTime</code> without a
timezone. Otherwise, returns an <code>xs:dateTime</code> with a
timezone.</p>
<p>If <code>$timezone</code> is not specified, then
<code>$timezone</code> is the value of the implicit timezone in the
dynamic context.</p>
<p>If <code>$arg</code> is the empty sequence, then the result is
the empty sequence.</p>
<p>A dynamic error is raised [<a href="#ERRFODT0003" title=
"err:FODT0003">err:FODT0003</a>] if <code>$timezone</code> is less
than <code>-PT14H</code> or greater than <code>PT14H</code> or if
does not contain an integral number of minutes.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
<code>$arg</code>.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is not the empty sequence, then the result
is <code>$arg</code> with <code>$timezone</code> as the timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
the localized value of <code>$arg</code> without its timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is not the empty sequence, then the result
is an <code>xs:dateTime</code> value with a timezone component of
<code>$timezone</code> that is equal to <code>$arg</code>.</p>
<div class="div4">
<h5><a name="func-adjust-dateTime-to-timezone-examples" id=
"func-adjust-dateTime-to-timezone-examples"></a>10.7.1.1
Examples</h5>
<p>Assume the dynamic context provides an implicit timezone of
<code>-05:00 (-PT5H0M)</code>.</p>
<p><code>let $tz := xs:dayTimeDuration("-PT10H")</code></p>
<ul>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00"))</code>
returns <code>2002-03-07T10:00:00-05:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"))</code>
returns <code>2002-03-07T12:00:00-05:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00"),
$tz)</code> returns <code>2002-03-07T10:00:00-10:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"),
$tz)</code> returns <code>2002-03-07T07:00:00-10:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"),
xs:dayTimeDuration("PT10H"))</code> returns
<code>2002-03-08T03:00:00+10:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T00:00:00+01:00"),
xs:dayTimeDuration("-PT8H"))</code> returns
<code>2002-03-06T15:00:00-08:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00"),
())</code> returns <code>2002-03-07T10:00:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"),
())</code> returns <code>2002-03-07T10:00:00</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-adjust-date-to-timezone" id=
"func-adjust-date-to-timezone"></a>10.7.2
fn:adjust-date-to-timezone</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:adjust-date-to-timezone</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:date?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date?</code></div>
</div>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:adjust-date-to-timezone</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:date?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$timezone</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Adjusts an <code>xs:date</code> value to a specific
timezone, or to no timezone at all. If <code>$timezone</code> is
the empty sequence, returns an <code>xs:date</code> without a
timezone. Otherwise, returns an <code>xs:date</code> with a
timezone. For purposes of timezone adjustment, an
<code>xs:date</code> is treated as an <code>xs:dateTime</code> with
time <code>00:00:00</code>.</p>
<p>If <code>$timezone</code> is not specified, then
<code>$timezone</code> is the value of the implicit timezone in the
dynamic context.</p>
<p>If <code>$arg</code> is the empty sequence, then the result is
the empty sequence.</p>
<p>A dynamic error is raised [<a href="#ERRFODT0003" title=
"err:FODT0003">err:FODT0003</a>] if <code>$timezone</code> is less
than <code>-PT14H</code> or greater than <code>PT14H</code> or if
does not contain an integral number of minutes.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
the value of <code>$arg</code>.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is not the empty sequence, then the result
is <code>$arg</code> with <code>$timezone</code> as the timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
the localized value of <code>$arg</code> without its timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is not the empty sequence, then:</p>
<ul>
<li>
<p>Let <code>$srcdt</code> be an <code>xs:dateTime</code> value,
with <code>00:00:00</code> for the time component and date and
timezone components that are the same as the date and timezone
components of <code>$arg</code>.</p>
</li>
<li>
<p>Let <code>$r</code> be the result of evaluating <a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone($srcdt,
$timezone)</code></a></p>
</li>
<li>
<p>The result of this function will be a date value that has date
and timezone components that are the same as the date and timezone
components of <code>$r</code>.</p>
</li>
</ul>
<div class="div4">
<h5><a name="func-adjust-date-to-timezone-examples" id=
"func-adjust-date-to-timezone-examples"></a>10.7.2.1 Examples</h5>
<p>Assume the dynamic context provides an implicit timezone of
<code>-05:00 (-PT5H0M)</code>.</p>
<p><code>let $tz := xs:dayTimeDuration("-PT10H")</code></p>
<ul>
<li>
<p><code>fn:adjust-date-to-timezone(xs:date("2002-03-07"))</code>
returns <code>2002-03-07-05:00.</code></p>
</li>
<li>
<p>
<code>fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"))</code>
returns <code>2002-03-07-05:00</code>. <code>$arg</code> is
converted to the <code>xs:dateTime
"2002-03-07T00:00:00-07:00"</code>. This is adjusted to the
implicit timezone, giving
<code>"2002-03-07T02:00:00-05:00".</code></p>
</li>
<li>
<p><code>fn:adjust-date-to-timezone(xs:date("2002-03-07"),
$tz)</code> returns <code>2002-03-07-10:00</code>.</p>
</li>
<li>
<p><code>fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"),
$tz)</code> returns <code>2002-03-06-10:00</code>.
<code>$arg</code> is converted to the <code>xs:dateTime
"2002-03-07T00:00:00-07:00"</code>. This is adjusted to the given
timezone, giving <code>"2002-03-06T21:00:00-10:00"</code>.</p>
</li>
<li>
<p><code>fn:adjust-date-to-timezone(xs:date("2002-03-07"),
())</code> returns <code>2002-03-07.</code></p>
</li>
<li>
<p><code>fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"),
())</code> returns <code>2002-03-07.</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-adjust-time-to-timezone" id=
"func-adjust-time-to-timezone"></a>10.7.3
fn:adjust-time-to-timezone</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:adjust-time-to-timezone</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:time?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time?</code></div>
</div>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:adjust-time-to-timezone</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:time?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$timezone</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Adjusts an <code>xs:time</code> value to a specific
timezone, or to no timezone at all. If <code>$timezone</code> is
the empty sequence, returns an <code>xs:time</code> without a
timezone. Otherwise, returns an <code>xs:time</code> with a
timezone.</p>
<p>If <code>$timezone</code> is not specified, then
<code>$timezone</code> is the value of the implicit timezone in the
dynamic context.</p>
<p>If <code>$arg</code> is the empty sequence, then the result is
the empty sequence.</p>
<p>A dynamic error is raised [<a href="#ERRFODT0003" title=
"err:FODT0003">err:FODT0003</a>] if <code>$timezone</code> is less
than <code>-PT14H</code> or greater than <code>PT14H</code> or if
does not contain an integral number of minutes.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
<code>$arg</code>.</p>
<p>If <code>$arg</code> does not have a timezone component and
<code>$timezone</code> is not the empty sequence, then the result
is <code>$arg</code> with <code>$timezone</code> as the timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is the empty sequence, then the result is
the localized value of <code>$arg</code> without its timezone
component.</p>
<p>If <code>$arg</code> has a timezone component and
<code>$timezone</code> is not the empty sequence, then:</p>
<ul>
<li>
<p>Let <code>$srcdt</code> be an <code>xs:dateTime</code> value,
with an arbitrary date for the date component and time and timezone
components that are the same as the time and timezone components of
<code>$arg</code>.</p>
</li>
<li>
<p>Let <code>$r</code> be the result of evaluating</p>
<p><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone($srcdt,
$timezone)</code></a></p>
</li>
<li>
<p>The result of this function will be a time value that has time
and timezone components that are the same as the time and timezone
components of <code>$r</code>.</p>
</li>
</ul>
<div class="div4">
<h5><a name="func-adjust-time-to-timezone-examples" id=
"func-adjust-time-to-timezone-examples"></a>10.7.3.1 Examples</h5>
<p>Assume the dynamic context provides an implicit timezone of
<code>-05:00 (-PT5H0M)</code>.</p>
<p><code>let $tz := xs:dayTimeDuration("-PT10H")</code></p>
<ul>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00"))</code>
returns <code>10:00:00-05:00</code></p>
</li>
<li>
<p>
<code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"))</code>
returns <code>12:00:00-05:00</code></p>
</li>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00"),
$tz)</code> returns <code>10:00:00-10:00</code></p>
</li>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"),
$tz)</code> returns <code>07:00:00-10:00</code></p>
</li>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00"), ())</code>
returns <code>10:00:00</code></p>
</li>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"),
())</code> returns <code>10:00:00</code></p>
</li>
<li>
<p><code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"),
xs:dayTimeDuration("PT10H"))</code> returns
<code>03:00:00+10:00</code></p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="dateTime-arithmetic" id="dateTime-arithmetic"></a>10.8
Arithmetic Operators on Durations, Dates and Times</h3>
<p>These functions support adding or subtracting a duration value
to or from an <code>xs:dateTime</code>, an <code>xs:date</code> or
an <code>xs:time</code> value. Appendix E of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
describes an algorithm for performing such operations.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-subtract-dateTimes"><code>op:subtract-dateTimes</code></a></td>
<td>Returns the difference between two <code>xs:dateTimes</code> as
an <code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-dates"><code>op:subtract-dates</code></a></td>
<td>Returns the difference between two <code>xs:dateTimes</code> as
an <code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-times"><code>op:subtract-times</code></a></td>
<td>Returns the difference between two <code>xs:time</code>s as an
<code>xs:dayTimeDuration</code>.</td>
</tr>
<tr>
<td><a href=
"#func-add-yearMonthDuration-to-dateTime"><code>op:add-yearMonthDuration-to-dateTime</code></a></td>
<td>Returns the end of a time period by adding an
<code>xs:yearMonthDuration</code> to the <code>xs:dateTime</code>
that starts the period.</td>
</tr>
<tr>
<td><a href=
"#func-add-dayTimeDuration-to-dateTime"><code>op:add-dayTimeDuration-to-dateTime</code></a></td>
<td>Returns the end of a time period by adding an
<code>xs:dayTimeDuration</code> to the <code>xs:dateTime</code>
that starts the period.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-yearMonthDuration-from-dateTime"><code>op:subtract-yearMonthDuration-from-dateTime</code></a></td>
<td>Returns the beginning of a time period by subtracting an
<code>xs:yearMonthDuration</code> from the <code>xs:dateTime</code>
that ends the period.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-dayTimeDuration-from-dateTime"><code>op:subtract-dayTimeDuration-from-dateTime</code></a></td>
<td>Returns the beginning of a time period by subtracting an
<code>xs:dayTimeDuration</code> from the <code>xs:dateTime</code>
that ends the period.</td>
</tr>
<tr>
<td><a href=
"#func-add-yearMonthDuration-to-date"><code>op:add-yearMonthDuration-to-date</code></a></td>
<td>Returns the end of a time period by adding an
<code>xs:yearMonthDuration</code> to the <code>xs:date</code> that
starts the period.</td>
</tr>
<tr>
<td><a href=
"#func-add-dayTimeDuration-to-date"><code>op:add-dayTimeDuration-to-date</code></a></td>
<td>Returns the end of a time period by adding an
<code>xs:dayTimeDuration</code> to the <code>xs:date</code> that
starts the period.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-yearMonthDuration-from-date"><code>op:subtract-yearMonthDuration-from-date</code></a></td>
<td>Returns the beginning of a time period by subtracting an
<code>xs:yearMonthDuration</code> from the <code>xs:date</code>
that ends the period.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-dayTimeDuration-from-date"><code>op:subtract-dayTimeDuration-from-date</code></a></td>
<td>Returns the beginning of a time period by subtracting an
<code>xs:dayTimeDuration</code> from the <code>xs:date</code> that
ends the period.</td>
</tr>
<tr>
<td><a href=
"#func-add-dayTimeDuration-to-time"><code>op:add-dayTimeDuration-to-time</code></a></td>
<td>Adds the value of the hours, minutes and seconds components of
an <code>xs:dayTimeDuration</code> to an <code>xs:time</code>
value.</td>
</tr>
<tr>
<td><a href=
"#func-subtract-dayTimeDuration-from-time"><code>op:subtract-dayTimeDuration-from-time</code></a></td>
<td>Subtracts the value of the hours, minutes and seconds
components of an <code>xs:dayTimeDuration</code> to an
<code>xs:time</code> value.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-subtract-dateTimes" id=
"func-subtract-dateTimes"></a>10.8.1 op:subtract-dateTimes</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-dateTimes</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:dayTimeDuration</code> that
corresponds to the difference between the normalized value of
<code>$arg1</code> and the normalized value of <code>$arg2</code>.
If either <code>$arg1</code> or <code>$arg2</code> do not contain
an explicit timezone then, for the purpose of the operation, the
implicit timezone provided by the dynamic context (See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) is assumed to be
present as part of the value.</p>
<p>If the normalized value of <code>$arg1</code> precedes in time
the normalized value of <code>$arg2</code>, then the returned value
is a negative duration.</p>
<p>Backs up the subtract, "-", operator on <code>xs:dateTime</code>
values.</p>
<div class="div4">
<h5><a name="func-subtract-dateTimes-examples" id=
"func-subtract-dateTimes-examples"></a>10.8.1.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>.</p>
<ul>
<li>
<p><code>op:subtract-dateTimes(xs:dateTime("2000-10-30T06:12:00"),
xs:dateTime("1999-11-28T09:00:00Z"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to 337 days, 2
hours and 12 minutes.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-dates" id=
"func-subtract-dates"></a>10.8.2 op:subtract-dates</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:subtract-dates</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:date</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration?</code></div>
</div>
<p>Summary: Returns the <code>xs:dayTimeDuration</code> that
corresponds to the difference between the starting instant of
<code>$arg1</code> and the the starting instant of
<code>$arg2</code>. If either <code>$arg1</code> or
<code>$arg2</code> do not contain an explicit timezone then, for
the purpose of the operation, the implicit timezone provided by the
dynamic context (See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) is assumed to be
present as part of the value.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at <code>00:00:00</code> on that date.</p>
<p>The result is the result of subtracting the two starting
instants using <a href=
"#func-subtract-dateTimes"><code>op:subtract-dateTimes</code></a>.</p>
<p>If the starting instant of <code>$arg1</code> precedes in time
the starting instant of <code>$arg2</code>, then the returned value
is a negative duration.</p>
<p>Backs up the subtract, "-", operator on <code>xs:date</code>
values.</p>
<div class="div4">
<h5><a name="func-subtract-dates-examples" id=
"func-subtract-dates-examples"></a>10.8.2.1 Examples</h5>
<ul>
<li>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>Z</code>.
<code>op:subtract-dates(xs:date("2000-10-30"),
xs:date("1999-11-28"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to 337 days.
The normalized values of the two starting instants are <code>{2000,
10, 30, 0, 0, 0, PT0S}</code> and <code>{1999, 11, 28, 0, 0, 0,
PT0S}</code>.</p>
</li>
<li>
<p>If the dynamic context provides an implicit timezone value of
<code>+05:00</code>, <code>op:subtract-dates(xs:date("2000-10-30"),
xs:date("1999-11-28Z"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to 336 days and
19 hours. The normalized values of the two starting instants are
<code>{2000, 10, 29, 19, 0, 0, PT0S}</code> and <code>{1999, 11,
28, 0, 0, 0, PT0S}</code>.</p>
</li>
<li>
<p><code>op:subtract-dates(xs:date("2000-10-15-05:00"),
xs:date("2000-10-10+02:00"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to lexical form
"<code>P5DT7H</code>".</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-times" id=
"func-subtract-times"></a>10.8.3 op:subtract-times</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:subtract-times</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:time</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></div>
</div>
<p>Summary: Returns the <code>xs:dayTimeDuration</code> that
corresponds to the difference between the value of
<code>$arg1</code> converted to an <code>xs:dateTime</code> using
the date components from the reference <code>xs:dateTime</code> and
the value of <code>$arg2</code> converted to an
<code>xs:dateTime</code> using the date components from the same
reference <code>xs:dateTime</code> . If either <code>$arg1</code>
or <code>$arg2</code> do not contain an explicit timezone then, for
the purpose of the operation, the implicit timezone provided by the
dynamic context (See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) is assumed to be
present as part of the value.</p>
<p>The result is the result of subtracting the two
<code>xs:dateTime</code>s using <a href=
"#func-subtract-dateTimes"><code>op:subtract-dateTimes</code></a>.</p>
<p>If the value of <code>$arg1</code> converted to an
<code>xs:dateTime</code> using the date components from the
reference <code>xs:dateTime</code> precedes in time the value of
<code>$arg2</code> converted to an <code>xs:dateTime</code> using
the date components from the same reference
<code>xs:dateTime</code> , then the returned value is a negative
duration.</p>
<p>Backs up the subtract, "-", operator on <code>xs:time</code>
values.</p>
<div class="div4">
<h5><a name="func-subtract-times-examples" id=
"func-subtract-times-examples"></a>10.8.3.1 Examples</h5>
<p>Assume that the dynamic context provides an implicit timezone
value of <code>-05:00</code>. Assume, also, that the date
components of the reference <code>xs:dateTime</code> correspond to
<code>"1972-12-31"</code>.</p>
<ul>
<li>
<p><code>op:subtract-times(xs:time("11:12:00Z"),
xs:time("04:00:00"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to 2 hours and
12 minutes. This is obtained by subtracting from the
<code>xs:dateTime</code> value <code>{1972, 12, 31, 11, 12, 0,
PT0S}</code> the <code>xs:dateTime</code> value <code>{1972, 12,
31, 9, 0, 0, PT0S}</code>.</p>
</li>
<li>
<p><code>op:subtract-times(xs:time("11:00:00-05:00"),
xs:time("21:30:00+05:30"))</code> returns a zero
<code>xs:dayTimeDuration</code> value corresponding to the lexical
representation <code>"PT0S"</code>. The two
<code>xs:dateTime</code> values are <code>{1972, 12, 31, 11, 0, 0,
-PT5H}</code> and <code>{1972, 12, 31, 21, 30, 0, PT5H30M}</code>.
These normalize to <code>{1972, 12, 31, 16, 0, 0, PT0S}</code> and
<code>{1972, 12, 31, 16, 0, 0, PT0S}</code>.</p>
</li>
<li>
<p><code>op:subtract-times(xs:time("17:00:00-06:00"),
xs:time("08:00:00+09:00"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to one day or
24 hours. The two normalized <code>xs:dateTime</code> values are
<code>{1972, 12, 31, 23, 0, 0, PT0S}</code> and <code>{1972, 12,
30, 23, 0, 0, PT0S}</code>.</p>
</li>
<li>
<p><code>op:subtract-times(xs:time("24:00:00"),
xs:time("23:59:59"))</code> returns an
<code>xs:dayTimeDuration</code> value corresponding to
<code>"-PT23H59M59S"</code>. The two normalized
<code>xs:dateTime</code> values are <code>{1972, 12, 31, 0, 0, 0,
()}</code> and <code>{1972, 12, 31, 23, 59, 59.0, ()}</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-yearMonthDuration-to-dateTime" id=
"func-add-yearMonthDuration-to-dateTime"></a>10.8.4
op:add-yearMonthDuration-to-dateTime</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-yearMonthDuration-to-dateTime</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:dateTime</code> computed by adding
<code>$arg2</code> to the value of <code>$arg1</code> using the
algorithm described in Appendix E of <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> disregarding the rule
about leap seconds. If <code>$arg2</code> is negative, then the
result <code>xs:dateTime</code> precedes <code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "+" operator on
<code>xs:dateTime</code> and <code>xs:yearMonthDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-add-yearMonthDuration-to-dateTime-examples" id=
"func-add-yearMonthDuration-to-dateTime-examples"></a>10.8.4.1
Examples</h5>
<ul>
<li>
<p>
<code>op:add-yearMonthDuration-to-dateTime(xs:dateTime("2000-10-30T11:12:00"),
xs:yearMonthDuration("P1Y2M"))</code> returns an
<code>xs:dateTime</code> value corresponding to the lexical
representation <code>"2001-12-30T11:12:00"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-dayTimeDuration-to-dateTime" id=
"func-add-dayTimeDuration-to-dateTime"></a>10.8.5
op:add-dayTimeDuration-to-dateTime</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-dayTimeDuration-to-dateTime</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:dateTime</code> computed by adding
<code>$arg2</code> to the value of <code>$arg1</code> using the
algorithm described in Appendix E of <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a> disregarding the rule
about leap seconds. If <code>$arg2</code> is negative, then the
result <code>xs:dateTime</code> precedes <code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "+" operator on
<code>xs:dateTime</code> and <code>xs:dayTimeDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-add-dayTimeDuration-to-dateTime-examples" id=
"func-add-dayTimeDuration-to-dateTime-examples"></a>10.8.5.1
Examples</h5>
<ul>
<li>
<p>
<code>op:add-dayTimeDuration-to-dateTime(xs:dateTime("2000-10-30T11:12:00"),
xs:dayTimeDuration("P3DT1H15M"))</code> returns an
<code>xs:dateTime</code> value corresponding to the lexical
representation <code>"2000-11-02T12:27:00"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-yearMonthDuration-from-dateTime" id=
"func-subtract-yearMonthDuration-from-dateTime"></a>10.8.6
op:subtract-yearMonthDuration-from-dateTime</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-yearMonthDuration-from-dateTime</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:dateTime</code> computed by
negating <code>$arg2</code> and adding the result to the value of
<code>$arg1</code> using the algorithm described in Appendix E of
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> disregarding the rule about leap seconds. If
<code>$arg2</code> is negative, then the <code>xs:dateTime</code>
returned follows <code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "-" operator on
<code>xs:dateTime</code> and <code>xs:yearMonthDuration</code>
values.</p>
<div class="div4">
<h5><a name=
"func-subtract-yearMonthDuration-from-dateTime-examples" id=
"func-subtract-yearMonthDuration-from-dateTime-examples"></a>10.8.6.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-yearMonthDuration-from-dateTime(xs:dateTime("2000-10-30T11:12:00"),
xs:yearMonthDuration("P1Y2M"))</code> returns an
<code>xs:dateTime</code> value corresponding to the lexical
representation <code>"1999-08-30T11:12:00"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-dayTimeDuration-from-dateTime" id=
"func-subtract-dayTimeDuration-from-dateTime"></a>10.8.7
op:subtract-dayTimeDuration-from-dateTime</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-dayTimeDuration-from-dateTime</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dateTime</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:dateTime</code> computed by
negating <code>$arg2</code> and adding the result to the value of
<code>$arg1</code> using the algorithm described in Appendix E of
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> disregarding the rule about leap seconds. If
<code>$arg2</code> is negative, then the <code>xs:dateTime</code>
returned follows <code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "-" operator on
<code>xs:dateTime</code> and <code>xs:dayTimeDuration</code>
values.</p>
<div class="div4">
<h5><a name="func-subtract-dayTimeDuration-from-dateTime-examples"
id=
"func-subtract-dayTimeDuration-from-dateTime-examples"></a>10.8.7.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-dayTimeDuration-from-dateTime(xs:dateTime("2000-10-30T11:12:00"),
xs:dayTimeDuration("P3DT1H15M"))</code> returns an
<code>xs:dateTime</code> value corresponding to the lexical
representation <code>"2000-10-27T09:57:00"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-yearMonthDuration-to-date" id=
"func-add-yearMonthDuration-to-date"></a>10.8.8
op:add-yearMonthDuration-to-date</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-yearMonthDuration-to-date</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:date</code> computed by adding
<code>$arg2</code> to the starting instant of <code>$arg1</code>
using the algorithm described in Appendix E of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
and discarding the time components from the resulting
<code>xs:dateTime</code>. If <code>$arg2</code> is negative, then
the <code>xs:date</code> returned precedes <code>$arg1</code>.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at time <code>00:00:00</code> on that
date.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "+" operator on <code>xs:date</code>
and <code>xs:yearMonthDuration</code> values.</p>
<div class="div4">
<h5><a name="func-add-yearMonthDuration-to-date-examples" id=
"func-add-yearMonthDuration-to-date-examples"></a>10.8.8.1
Examples</h5>
<ul>
<li>
<p><code>op:add-yearMonthDuration-to-date(xs:date("2000-10-30"),
xs:yearMonthDuration("P1Y2M"))</code> returns the
<code>xs:date</code> corresponding to December 30, 2001.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-dayTimeDuration-to-date" id=
"func-add-dayTimeDuration-to-date"></a>10.8.9
op:add-dayTimeDuration-to-date</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-dayTimeDuration-to-date</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:date</code> computed by adding
<code>$arg2</code> to the starting instant of <code>$arg1</code>
using the algorithm described in Appendix E of <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
and discarding the time components from the resulting
<code>xs:dateTime</code>. If <code>$arg2</code> is negative, then
the <code>xs:date</code> returned precedes <code>$arg1</code>.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at time <code>00:00:00</code> on that
date.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "+" operator on <code>xs:date</code>
and <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-dayTimeDuration-to-date-examples" id=
"func-subtract-dayTimeDuration-to-date-examples"></a>10.8.9.1
Examples</h5>
<ul>
<li>
<p><code>op:add-dayTimeDuration-to-date(xs:date("2004-10-30Z"),
xs:dayTimeDuration("P2DT2H30M0S"))</code> returns the
<code>xs:date</code> November 1, 2004. The starting instant of the
first argument is the <code>xs:dateTime</code> value <code>{2004,
10, 30, 0, 0, 0, PT0S}</code>. Adding the second argument to this,
gives the <code>xs:dateTime</code> value <code>{2004, 11, 1, 2, 30,
0, PT0S}</code>. The time components are then discarded.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-yearMonthDuration-from-date" id=
"func-subtract-yearMonthDuration-from-date"></a>10.8.10
op:subtract-yearMonthDuration-from-date</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-yearMonthDuration-from-date</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:yearMonthDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:date</code> computed by negating
<code>$arg2</code> and adding the result to the starting instant of
<code>$arg1</code> using the algorithm described in Appendix E of
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> and discarding the time components from the resulting
<code>xs:dateTime</code>. If <code>$arg2</code> is positive, then
the <code>xs:date</code> returned precedes <code>$arg1</code>.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at <code>00:00:00</code> on that date.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "-" operator on <code>xs:date</code>
and <code>xs:yearMonthDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-yearMonthDuration-from-date-examples"
id="func-subtract-yearMonthDuration-from-date-examples"></a>10.8.10.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-yearMonthDuration-from-date(xs:date("2000-10-30"),
xs:yearMonthDuration("P1Y2M"))</code> returns the
<code>xs:date</code> August 30, 1999.</p>
</li>
<li>
<p>
<code>op:subtract-yearMonthDuration-from-date(xs:date("2000-02-29Z"),
xs:yearMonthDuration("P1Y"))</code> returns the
<code>xs:date</code> February 28, 1999 in timezone
<code>Z</code>.</p>
</li>
<li>
<p>
<code>op:subtract-yearMonthDuration-from-date(xs:date("2000-10-31-05:00"),
xs:yearMonthDuration("P1Y1M"))</code> returns the
<code>xs:date</code> September 30, 1999 in timezone
<code>-05:00</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-dayTimeDuration-from-date" id=
"func-subtract-dayTimeDuration-from-date"></a>10.8.11
op:subtract-dayTimeDuration-from-date</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-dayTimeDuration-from-date</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:date</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the <code>xs:date</code> computed by negating
<code>$arg2</code> and adding the result to the starting instant of
<code>$arg1</code> using the algorithm described in Appendix E of
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> and discarding the time components from the resulting
<code>xs:dateTime</code>. If <code>$arg2</code> is positive, then
the <code>xs:date</code> returned precedes <code>$arg1</code>.</p>
<p>The starting instant of an <code>xs:date</code> is the
<code>xs:dateTime</code> at <code>00:00:00</code> on that date.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "-" operator on <code>xs:date</code>
and <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-dayTimeDuration-from-date-examples" id=
"func-subtract-dayTimeDuration-from-date-examples"></a>10.8.11.1
Examples</h5>
<ul>
<li>
<p>
<code>op:subtract-dayTimeDuration-from-date(xs:date("2000-10-30"),
xs:dayTimeDuration("P3DT1H15M"))</code> returns the
<code>xs:date</code> October 26, 2000.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-add-dayTimeDuration-to-time" id=
"func-add-dayTimeDuration-to-time"></a>10.8.12
op:add-dayTimeDuration-to-time</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:add-dayTimeDuration-to-time</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: First, the days component in the canonical lexical
representation of <code>$arg2</code> is set to zero (0) and the
value of the resulting <code>xs:dayTimeDuration</code> is
calculated. Alternatively, the value of <code>$arg2</code> modulus
86,400 is used as the second argument. This value is added to the
value of <code>$arg1</code> converted to an
<code>xs:dateTime</code> using a reference date such as
<code>1972-12-31</code> and the time components of the result
returned. Note that the <code>xs:time</code> returned may occur in
a following or preceding day and may be less than
<code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "+" operator on <code>xs:time</code>
and <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-add-dayTimeDuration-to-time-examples" id=
"func-add-dayTimeDuration-to-time-examples"></a>10.8.12.1
Examples</h5>
<ul>
<li>
<p><code>op:add-dayTimeDuration-to-time(xs:time("11:12:00"),
xs:dayTimeDuration("P3DT1H15M"))</code> returns the
<code>xs:time</code> value corresponding to the lexical
representation "<code>12:27:00</code>".</p>
</li>
<li>
<p><code>op:add-dayTimeDuration-to-time(xs:time("23:12:00+03:00"),
xs:dayTimeDuration("P1DT3H15M"))</code> returns the
<code>xs:time</code> value corresponding to the lexical
representation "<code>02:27:00+03:00</code>", i.e. <code>{0, 0, 0,
2, 27, 0, PT3H}</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subtract-dayTimeDuration-from-time" id=
"func-subtract-dayTimeDuration-from-time"></a>10.8.13
op:subtract-dayTimeDuration-from-time</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:subtract-dayTimeDuration-from-time</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:time</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:dayTimeDuration</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: The result is calculated by first setting the day
component in the canonical lexical representation of
<code>$arg2</code> to zero (0) and calculating the value of the
resulting <code>xs:dayTimeDuration</code>. Alternatively, the value
of <code>$arg2</code> modulus 86,400 is used as the second
argument. This value is subtracted from the value of
<code>$arg1</code> converted to an <code>xs:dateTime</code> using a
reference date such as <code>1972-12-31</code> and the time
components of the result are returned. Note that the
<code>xs:time</code> returned may occur in a preceding or following
day and may be greater than <code>$arg1</code>.</p>
<p>The result has the same timezone as <code>$arg1</code>. If
<code>$arg1</code> has no timezone, the result has no timezone.</p>
<p>This functions backs up the "-" operator on <code>xs:time</code>
and <code>xs:dayTimeDuration</code> values.</p>
<div class="div4">
<h5><a name="func-subtract-dayTimeDuration-from-time-examples" id=
"func-subtract-dayTimeDuration-from-time-examples"></a>10.8.13.1
Examples</h5>
<ul>
<li>
<p><code>op:subtract-dayTimeDuration-from-time(xs:time("11:12:00"),
xs:dayTimeDuration("P3DT1H15M"))</code> returns an
<code>xs:time</code> value corresponding to the lexical
representation <code>"09:57:00"</code>.</p>
</li>
<li>
<p>
<code>op:subtract-dayTimeDuration-from-time(xs:time("08:20:00-05:00"),
xs:dayTimeDuration("P23DT10H10M"))</code> returns the
<code>xs:time</code> value corresponding to the lexical
representation <code>"22:10:00-05:00"</code> i.e. <code>{0, 0, 0,
22, 10, 0, -PT5H}</code></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="QName-funcs" id="QName-funcs"></a>11 Functions Related
to QNames</h2>
<div class="div2">
<h3><a name="QName-constructors" id="QName-constructors"></a>11.1
Additional Constructor Functions for QNames</h3>
<p>This section defines additional constructor functions for QName
as defined in <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a>. Leading and trailing whitespace, if present,
is stripped from string arguments before the result is
constructed.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-resolve-QName"><code>fn:resolve-QName</code></a></td>
<td>Returns an <code>xs:QName</code> with the lexical form given in
the first argument. The prefix is resolved using the in-scope
namespaces for a given element.</td>
<td></td>
</tr>
<tr>
<td><a href="#func-QName"><code>fn:QName</code></a></td>
<td>Returns an <code>xs:QName</code> with the namespace URI given
in the first argument and the local name and prefix in the second
argument.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-resolve-QName" id="func-resolve-QName"></a>11.1.1
fn:resolve-QName</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:resolve-QName</code>(<code class=
"arg">$qname</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$element</code><code class=
"as">&#160;as&#160;</code><code class=
"type">element()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:QName?</code></div>
</div>
<p>Summary: Returns an <code>xs:QName</code> value (that is, an
expanded-QName) by taking an <code>xs:string</code> that has the
lexical form of an <code>xs:QName</code> (a string in the form
"prefix:local-name" or "local-name") and resolving it using the
in-scope namespaces for a given element.</p>
<p>If <code>$qname</code> does not have the correct lexical form
for <code>xs:QName</code> an error is raised [<a href=
"#ERRFOCA0002" title="err:FOCA0002">err:FOCA0002</a>].</p>
<p>If <code>$qname</code> is the empty sequence, returns the empty
sequence.</p>
<p>More specifically, the function searches the namespace bindings
of <code>$element</code> for a binding whose name matches the
prefix of <code>$qname</code>, or the zero-length string if it has
no prefix, and constructs an expanded-QName whose local name is
taken from the supplied <code>$qname</code>, and whose namespace
URI is taken from the string value of the namespace binding.</p>
<p>If the <code>$qname</code> has a prefix and if there is no
namespace binding for <code>$element</code> that matches this
prefix, then an error is raised [<a href="#ERRFONS0004" title=
"err:FONS0004">err:FONS0004</a>].</p>
<p>If the <code>$qname</code> has no prefix, and there is no
namespace binding for <code>$element</code> corresponding to the
default (unnamed) namespace, then the resulting expanded-QName has
no namespace part.</p>
<p>The prefix (or absence of a prefix) in the supplied
<code>$qname</code> argument is retained in the returned
expanded-QName, as discussed in <a href=
"http://www.w3.org/TR/xpath-datamodel/#terminology">Section 2.1
Terminology</a><sup><small>DM</small></sup>.</p>
<div class="div4">
<h5><a name="func-resolve-QName-uasge" id=
"func-resolve-QName-uasge"></a>11.1.1.1 Usage Note</h5>
<p>Sometimes the requirement is to construct an
<code>xs:QName</code> without using the default namespace. This can
be achieved by writing:</p>
<div class="exampleInner">
<pre>
if (contains($qname, ":")) then fn:resolve-QName($qname, $element) else
fn:QName("", $qname)
</pre></div>
<p>If the requirement is to construct an <code>xs:QName</code>
using the namespaces in the static context, then the
<code>xs:QName</code> constructor should be used.</p>
</div>
<div class="div4">
<h5><a name="func-resolve-QName-examples" id=
"func-resolve-QName-examples"></a>11.1.1.2 Examples</h5>
<p>Assume that the element bound to <code>$element</code> has a
single namespace binding bound to the prefix <code>eg</code>.</p>
<ul>
<li>
<p><code>fn:resolve-QName("hello", $element)</code> returns a QName
with local name "hello" that is in no namespace.</p>
</li>
<li>
<p><code>fn:resolve-QName("eg:myFunc", $element)</code> returns an
<code>xs:QName</code> whose namespace URI is specified by the
namespace binding corresponding to the prefix "eg" and whose local
name is "myFunc".</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-QName" id="func-QName"></a>11.1.2 fn:QName</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:QName</code>(<code class=
"arg">$paramURI</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$paramQName</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:QName</code></div>
</div>
<p>Summary: Returns an <code>xs:QName</code> with the namespace URI
given in <code>$paramURI</code>. If <code>$paramURI</code> is the
zero-length string or the empty sequence, it represents "no
namespace"; in this case, if the value of <code>$paramQName</code>
contains a colon (<code>:</code>), an error is raised [<a href=
"#ERRFOCA0002" title="err:FOCA0002">err:FOCA0002</a>]. The prefix
(or absence of a prefix) in <code>$paramQName</code> is retained in
the returned <code>xs:QName</code> value. The local name in the
result is taken from the local part of
<code>$paramQName</code>.</p>
<p>If <code>$paramQName</code> does not have the correct lexical
form for <code>xs:QName</code> an error is raised [<a href=
"#ERRFOCA0002" title="err:FOCA0002">err:FOCA0002</a>].</p>
<p>Note that unlike <code>xs:QName</code> this function does not
require a <code>xs:string</code> literal as the argument.</p>
<div class="div4">
<h5><a name="func-QName-examples" id=
"func-QName-examples"></a>11.1.2.1 Examples</h5>
<ul>
<li>
<p><code>fn:QName("http://www.example.com/example",
"person")</code> returns an <code>xs:QName</code> with namespace
URI = "http://www.example.com/example", local name = "person" and
prefix = "".</p>
</li>
<li>
<p><code>fn:QName("http://www.example.com/example",
"ht:person")</code> returns an <code>xs:QName</code> with namespace
URI = "http://www.example.com/example", local name = "person" and
prefix = "ht".</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="QName-functions" id="QName-functions"></a>11.2
Functions and Operators Related to QNames</h3>
<p>This section discusses functions on QNames as defined in
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a>.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-QName-equal"><code>op:QName-equal</code></a></td>
<td>Returns <code>true</code> if the local names and namespace URIs
of the two arguments are equal.</td>
</tr>
<tr>
<td><a href=
"#func-prefix-from-QName"><code>fn:prefix-from-QName</code></a></td>
<td>Returns an <code>xs:NCName</code> representing the prefix of
the <code>xs:QName</code> argument.</td>
</tr>
<tr>
<td><a href=
"#func-local-name-from-QName"><code>fn:local-name-from-QName</code></a></td>
<td>Returns an <code>xs:NCName</code> representing the local name
of the <code>xs:QName</code> argument.</td>
</tr>
<tr>
<td><a href=
"#func-namespace-uri-from-QName"><code>fn:namespace-uri-from-QName</code></a></td>
<td>Returns the namespace URI for the <code>xs:QName</code>
argument. If the <code>xs:QName</code> is in no namespace, the
zero-length string is returned.</td>
</tr>
<tr>
<td><a href=
"#func-namespace-uri-for-prefix"><code>fn:namespace-uri-for-prefix</code></a></td>
<td>Returns the namespace URI of one of the in-scope namespaces for
the given element, identified by its namespace prefix.</td>
</tr>
<tr>
<td><a href=
"#func-in-scope-prefixes"><code>fn:in-scope-prefixes</code></a></td>
<td>Returns the prefixes of the in-scope namespaces for the given
element.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-QName-equal" id="func-QName-equal"></a>11.2.1
op:QName-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:QName-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:QName</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:QName</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if the namespace URIs of
<code>$arg1</code> and <code>$arg2</code> are equal and the local
names of <code>$arg1</code> and <code>$arg2</code> are identical
based on the Unicode code point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).
Otherwise, returns <code>false</code>. Two namespace URIs are
considered equal if they are either both absent or both present and
identical based on the Unicode code point collation. The prefix
parts of <code>$arg1</code> and <code>$arg2</code>, if any, are
ignored.</p>
<p>Backs up the "eq" and "ne" operators on values of type
<code>xs:QName</code>.</p>
</div>
<div class="div3">
<h4><a name="func-prefix-from-QName" id=
"func-prefix-from-QName"></a>11.2.2 fn:prefix-from-QName</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:prefix-from-QName</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:QName?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:NCName?</code></div>
</div>
<p>Summary: Returns an <code>xs:NCName</code> representing the
prefix of <code>$arg</code>. The empty sequence is returned if
<code>$arg</code> is the empty sequence or if the value of
<code>$arg</code> contains no prefix.</p>
</div>
<div class="div3">
<h4><a name="func-local-name-from-QName" id=
"func-local-name-from-QName"></a>11.2.3
fn:local-name-from-QName</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:local-name-from-QName</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:QName?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:NCName?</code></div>
</div>
<p>Summary: Returns an <code>xs:NCName</code> representing the
local part of <code>$arg</code>. If <code>$arg</code> is the empty
sequence, returns the empty sequence.</p>
<div class="div4">
<h5><a name="func-local-name-from-QName-examples" id=
"func-local-name-from-QName-examples"></a>11.2.3.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:local-name-from-QName(fn:QName("http://www.example.com/example",
"person"))</code> returns <code>"person"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-namespace-uri-from-QName" id=
"func-namespace-uri-from-QName"></a>11.2.4
fn:namespace-uri-from-QName</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:namespace-uri-from-QName</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:QName?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<p>Summary: Returns the namespace URI for <code>$arg</code> as an
<code>xs:string</code>. If <code>$arg</code> is the empty sequence,
the empty sequence is returned. If <code>$arg</code> is in no
namespace, the zero-length string is returned.</p>
<div class="div4">
<h5><a name="func-namespace-uri-from-QName-examples" id=
"func-namespace-uri-from-QName-examples"></a>11.2.4.1 Examples</h5>
<ul>
<li>
<p>
<code>fn:namespace-uri-from-QName(fn:QName("http://www.example.com/example",
"person"))</code> returns the namespace URI corresponding to
<code>"http://www.example.com/example"</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-namespace-uri-for-prefix" id=
"func-namespace-uri-for-prefix"></a>11.2.5
fn:namespace-uri-for-prefix</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:namespace-uri-for-prefix</code>(</td>
<td valign="baseline"><code class="arg">$prefix</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$element</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">element()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the namespace URI of one of the in-scope
namespaces for <code>$element</code>, identified by its namespace
prefix.</p>
<p>If <code>$element</code> has an in-scope namespace whose
namespace prefix is equal to <code>$prefix</code>, it returns the
namespace URI of that namespace. If <code>$prefix</code> is the
zero-length string or the empty sequence, it returns the namespace
URI of the default (unnamed) namespace. Otherwise, it returns the
empty sequence.</p>
<p>Prefixes are equal only if their Unicode code points match
exactly.</p>
</div>
<div class="div3">
<h4><a name="func-in-scope-prefixes" id=
"func-in-scope-prefixes"></a>11.2.6 fn:in-scope-prefixes</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:in-scope-prefixes</code>(<code class=
"arg">$element</code><code class=
"as">&#160;as&#160;</code><code class=
"type">element()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string*</code></div>
</div>
<p>Summary: Returns the prefixes of the in-scope namespaces for
<code>$element</code>. For namespaces that have a prefix, it
returns the prefix as an <code>xs:NCName</code>. For the default
namespace, which has no prefix, it returns the zero-length
string.</p>
</div>
</div>
</div>
<div class="div1">
<h2><a name="binary-functions" id="binary-functions"></a>12
Operators on base64Binary and hexBinary</h2>
<div class="div2">
<h3><a name="binary-value-comparisons" id=
"binary-value-comparisons"></a>12.1 Comparisons of base64Binary and
hexBinary Values</h3>
<p>The following comparison operators on
<code>xs:base64Binary</code> and <code>xs:hexBinary</code> values
are defined. Comparisons take two operands of the same type; that
is, both operands must be <code>xs:base64Binary</code> or both
operands may be <code>xs:hexBinary</code>. Each returns a boolean
value.</p>
<p>A value of type <code>xs:hexBinary</code> can be compared with a
value of type <code>xs:base64Binary</code> by casting one value to
the other type. See <a href="#casting-to-binary"><b>17.1.7 Casting
to xs:base64Binary and xs:hexBinary</b></a>.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-hexBinary-equal"><code>op:hexBinary-equal</code></a></td>
<td>Returns <code>true</code> if the two arguments are equal.</td>
</tr>
<tr>
<td><a href=
"#func-base64Binary-equal"><code>op:base64Binary-equal</code></a></td>
<td>Returns <code>true</code> if the two arguments are equal.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-hexBinary-equal" id=
"func-hexBinary-equal"></a>12.1.1 op:hexBinary-equal</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:hexBinary-equal</code>(</td>
<td valign="baseline"><code class="arg">$value1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:hexBinary</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$value2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:hexBinary</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if <code>$value1</code> and
<code>$value2</code> are of the same length, measured in binary
octets, and contain the same octets in the same order. Otherwise,
returns <code>false</code>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:hexBinary</code> values.</p>
</div>
<div class="div3">
<h4><a name="func-base64Binary-equal" id=
"func-base64Binary-equal"></a>12.1.2 op:base64Binary-equal</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">op:base64Binary-equal</code>(</td>
<td valign="baseline"><code class="arg">$value1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:base64Binary</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$value2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:base64Binary</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns <code>true</code> if <code>$value1</code> and
<code>$value2</code> are of the same length, measured in binary
octets, and contain the same octets in the same order. Otherwise,
returns <code>false</code>.</p>
<p>This function backs up the "eq" and "ne" operators on
<code>xs:base64Binary</code> values.</p>
</div>
</div>
</div>
<div class="div1">
<h2><a name="NOTATION-functions" id="NOTATION-functions"></a>13
Operators on NOTATION</h2>
<div class="div2">
<h3><a name="op.NOTATION" id="op.NOTATION"></a>13.1 Operators on
NOTATION</h3>
<p>This section discusses functions that take NOTATION as
arguments.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-NOTATION-equal"><code>op:NOTATION-equal</code></a></td>
<td>Returns <code>true</code> if the two arguments are <a href=
"#func-QName-equal"><code>op:QName-equal</code></a>.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-NOTATION-equal" id=
"func-NOTATION-equal"></a>13.1.1 op:NOTATION-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:NOTATION-equal</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:NOTATION</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:NOTATION</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Returns <code>true</code> if the namespace URIs of
<code>$arg1</code> and <code>$arg2</code> are equal and the local
names of <code>$arg1</code> and <code>$arg2</code> are identical
based on the Unicode code point collation:
<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>.
Otherwise, returns false. Two namespace URIs are considered equal
if they are either both absent or both present and identical based
on the Unicode code point collation. The prefix parts of
<code>$arg1</code> and <code>$arg2</code>, if any, are ignored.</p>
<p>Backs up the "eq" and "ne" operators on values of type
<code>xs:NOTATION</code>.</p>
</div>
</div>
</div>
<div class="div1">
<h2><a name="node-functions" id="node-functions"></a>14 Functions
and Operators on Nodes</h2>
<p>This section discusses functions and operators on nodes. Nodes
are formally defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#Node">Section 6
Nodes</a><sup><small>DM</small></sup>.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-name"><code>fn:name</code></a></td>
<td>Returns the name of the context node or the specified node as
an <code>xs:string</code>.</td>
</tr>
<tr>
<td><a href="#func-local-name"><code>fn:local-name</code></a></td>
<td>Returns the local name of the context node or the specified
node as an <code>xs:NCName</code>.</td>
</tr>
<tr>
<td><a href=
"#func-namespace-uri"><code>fn:namespace-uri</code></a></td>
<td>Returns the namespace URI as an <code>xs:anyURI</code> for the
<code>xs:QName</code> of the argument node or the context node if
the argument is omitted. This may be the URI corresponding to the
zero-length string if the <code>xs:QName</code> is in no
namespace.</td>
<td></td>
</tr>
<tr>
<td><a href="#func-number"><code>fn:number</code></a></td>
<td>Returns the value of the context item after atomization or the
specified argument converted to an <code>xs:double</code>.</td>
</tr>
<tr>
<td><a href="#func-lang"><code>fn:lang</code></a></td>
<td>Returns <code>true</code> or <code>false</code>, depending on
whether the language of the given node or the context node, as
defined using the xml:lang attribute, is the same as, or a
sublanguage of, the language specified by the argument.</td>
</tr>
<tr>
<td><a href=
"#func-is-same-node"><code>op:is-same-node</code></a></td>
<td>Returns <code>true</code> if the two arguments have the same
identity.</td>
</tr>
<tr>
<td><a href=
"#func-node-before"><code>op:node-before</code></a></td>
<td>Indicates whether one node appears before another node in
document order.</td>
</tr>
<tr>
<td><a href="#func-node-after"><code>op:node-after</code></a></td>
<td>Indicates whether one node appears after another node in
document order.</td>
</tr>
<tr>
<td><a href="#func-root"><code>fn:root</code></a></td>
<td>Returns the root of the tree to which the node argument
belongs.</td>
</tr>
</tbody>
</table>
<p>For the illustrative examples below assume an XQuery or
transformation operating on a PurchaseOrder document containing a
number of line-item elements. Each line-item has child elements
called description, price, quantity, etc. whose content is
different for each line-item. Quantity has simple content of type
<code>xs:decimal</code>. Further assume that variables
<code>$item1</code>, <code>$item2</code>, etc. are each bound to
single line-item element nodes in the document in sequence and that
the value of the quantity child of the first line-item is
<code>5.0</code>.</p>
<div class="exampleInner">
<pre>
&lt;PurchaseOrder&gt;
&lt;line-item&gt;
&lt;description&gt; ... &lt;/description&gt;
&lt;price&gt; ... &lt;/price&gt;
&lt;quantity&gt;5.0&lt;/quantity&gt;
...
&lt;/line-item&gt;
&lt;line-item&gt;
...
&lt;/line-item&gt;
...
&lt;/PurchaseOrder&gt;
</pre></div>
<div class="div2">
<h3><a name="func-name" id="func-name"></a>14.1 fn:name</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:name</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto"><code class=
"function">fn:name</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the name of a node, as an
<code>xs:string</code> that is either the zero-length string, or
has the lexical form of an <code>xs:QName</code>.</p>
<p>If the argument is omitted, it defaults to the context item
(<code>.</code>). The behavior of the function if the argument is
omitted is exactly the same as if the context item had been passed
as the argument.</p>
<p>The following errors may be raised: if the context item is
undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>If the argument is supplied and is the empty sequence, the
function returns the zero-length string.</p>
<p>If the target node has no name (that is, if it is a document
node, a comment, a text node, or a namespace binding having no
name), the function returns the zero-length string.</p>
<p>Otherwise, the value returned is <a href=
"#func-string"><code>fn:string(fn:node-name($arg))</code></a>.</p>
</div>
<div class="div2">
<h3><a name="func-local-name" id="func-local-name"></a>14.2
fn:local-name</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:local-name</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
<div class="proto"><code class=
"function">fn:local-name</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the local part of the name of <code>$arg</code>
as an <code>xs:string</code> that will either be the zero-length
string or will have the lexical form of an
<code>xs:NCName</code>.</p>
<p>If the argument is omitted, it defaults to the context item
(<code>.</code>). The behavior of the function if the argument is
omitted is exactly the same as if the context item had been passed
as the argument.</p>
<p>The following errors may be raised: if the context item is
undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>If the argument is supplied and is the empty sequence, the
function returns the zero-length string.</p>
<p>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.</p>
<p>Otherwise, the value returned will be the local part of the
expanded-QName of the target node (as determined by the
<code>dm:node-name</code> accessor in <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-node-name">Section 5.11
node-name Accessor</a><sup><small>DM</small></sup>. This will be an
<code>xs:string</code> whose lexical form is an
<code>xs:NCName</code>.</p>
</div>
<div class="div2">
<h3><a name="func-namespace-uri" id="func-namespace-uri"></a>14.3
fn:namespace-uri</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:namespace-uri</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI</code></div>
<div class="proto"><code class=
"function">fn:namespace-uri</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI</code></div>
</div>
<p>Summary: Returns the namespace URI of the <code>xs:QName</code>
of <code>$arg</code>.</p>
<p>If the argument is omitted, it defaults to the context node
(<code>.</code>). The behavior of the function if the argument is
omitted is exactly the same as if the context item had been passed
as the argument.</p>
<p>The following errors may be raised: if the context item is
undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>If <code>$arg</code> is neither an element nor an attribute
node, or if it is an element or attribute node whose expanded-QName
(as determined by the <code>dm:node-name</code> accessor in the
<a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-node-name">Section 5.11
node-name Accessor</a><sup><small>DM</small></sup>) is in no
namespace, then the function returns the <code>xs:anyURI</code>
corresponding to the zero-length string.</p>
</div>
<div class="div2">
<h3><a name="func-number" id="func-number"></a>14.4 fn:number</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:number</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double</code></div>
<div class="proto"><code class=
"function">fn:number</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double</code></div>
</div>
<p>Summary: Returns the value indicated by <code>$arg</code> or, if
<code>$arg</code> is not specified, the context item after
atomization, converted to an <code>xs:double</code></p>
<p>Calling the zero-argument version of the function is defined to
give the same result as calling the single-argument version with
the context item (<code>.</code>). That is,
<code>fn:number()</code> is equivalent to
<code>fn:number(.)</code>.</p>
<p>If <code>$arg</code> is the empty sequence or if
<code>$arg</code> or the context item cannot be converted to an
<code>xs:double</code>, the <code>xs:double</code> value
<code>NaN</code> is returned. If the context item is undefined an
error is raised: [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>.</p>
<p>If <code>$arg</code> is the empty sequence, <code>NaN</code> is
returned. Otherwise, <code>$arg</code>, or the context item after
atomization, is converted to an <code>xs:double</code> following
the rules of <a href="#casting-to-double"><b>17.1.3.2 Casting to
xs:double</b></a>. If the conversion to <code>xs:double</code>
fails, the <code>xs:double</code> value <code>NaN</code> is
returned.</p>
<div class="div3">
<h4><a name="func-number-examples" id=
"func-number-examples"></a>14.4.1 Examples</h4>
<ul>
<li>
<p><code>fn:number($item1/quantity)</code> returns
<code>5.0</code>.</p>
</li>
<li>
<p><code>fn:number($item2)</code> returns <code>NaN</code>.</p>
</li>
<li>
<p>Assume that the context item is the <code>xs:string</code>
"<code>15</code>". <code>fn:number()</code> returns
<code>1.5E1</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-lang" id="func-lang"></a>14.5 fn:lang</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:lang</code>(<code class=
"arg">$testlang</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:lang</code>(<code class=
"arg">$testlang</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$node</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: This function tests whether the language of
<code>$node</code>, or the context item if the second argument is
omitted, as specified by <code>xml:lang</code> attributes is the
same as, or is a sublanguage of, the language specified by
<code>$testlang</code>. The behavior of the function if the second
argument is omitted is exactly the same as if the context item
(<code>.</code>) had been passed as the second argument. The
language of the argument node, or the context item if the second
argument is omitted, is determined by the value of the
<code>xml:lang</code> attribute on the node, or, if the node has no
such attribute, by the value of the <code>xml:lang</code> attribute
on the nearest ancestor of the node that has an
<code>xml:lang</code> attribute. If there is no such ancestor, then
the function returns <code>false</code></p>
<p>The following errors may be raised: if the context item is
undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>If <code>$testlang</code> is the empty sequence it is
interpreted as the zero-length string.</p>
<p>The relevant <code>xml:lang</code> attribute is determined by
the value of the XPath expression:</p>
<div class="exampleInner">
<pre>
(ancestor-or-self::*/@xml:lang)[last()]
</pre></div>
<p>If this expression returns an empty sequence, the function
returns <code>false</code>.</p>
<p>Otherwise, the function returns <code>true</code> if and only
if, based on a caseless default match as specified in section 3.13
of <a href="#Unicode4">[The Unicode Standard]</a>, either:</p>
<ol class="enumar">
<li>
<p>(1) <code>$testlang</code> is equal to the string-value of the
relevant <code>xml:lang</code> attribute, or</p>
</li>
<li>
<p>(2) <code>$testlang</code> is equal to some substring of the
string-value of the relevant <code>xml:lang</code> attribute that
starts at the start of the string-value and ends immediately before
a hyphen, "-" (The character "-" is HYPHEN-MINUS, #x002D).</p>
</li>
</ol>
<div class="div3">
<h4><a name="func-lang-examples" id="func-lang-examples"></a>14.5.1
Examples</h4>
<ul>
<li>
<p>The expression <code>fn:lang("en")</code> would return
<code>true</code> if the context node were any of the following
four elements:</p>
<ul>
<li>
<p><code>&lt;para xml:lang="en"/&gt;</code></p>
</li>
<li>
<p><code>&lt;div xml:lang="en"&gt;&lt;para&gt;And now, and
forever!&lt;/para&gt;&lt;/div&gt;</code></p>
</li>
<li>
<p><code>&lt;para xml:lang="EN"/&gt;</code></p>
</li>
<li>
<p><code>&lt;para xml:lang="en-us"/&gt;</code></p>
</li>
</ul>
</li>
<li>
<p>The expression <code>fn:lang("fr")</code> would return
<code>false</code> if the context node were <code>&lt;para
xml:lang="EN"/&gt;</code></p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-is-same-node" id="func-is-same-node"></a>14.6
op:is-same-node</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:is-same-node</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If the node identified by the value of
<code>$parameter1</code> is the same node as the node identified by
the value of <code>$parameter2</code> (that is, the two nodes have
the same identity), then the function returns <code>true</code>;
otherwise, the function returns <code>false</code>. This function
backs up the "is" operator on nodes.</p>
<div class="div3">
<h4><a name="func-is-same-node-examples" id=
"func-is-same-node-examples"></a>14.6.1 Examples</h4>
<ul>
<li>
<p><code>op:is-same-node($item1, $item1)</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:is-same-node($item1, $item2)</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-node-before" id="func-node-before"></a>14.7
op:node-before</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:node-before</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If the node identified by the value of
<code>$parameter1</code> occurs in document order before the node
identified by the value of <code>$parameter2</code>, this function
returns <code>true</code>; otherwise, it returns
<code>false</code>. The rules determining the order of nodes within
a single document and in different documents can be found in
<a href=
"http://www.w3.org/TR/xpath-datamodel/#document-order">Section 2.4
Document Order</a><sup><small>DM</small></sup>. This function backs
up the "&lt;&lt;" operator.</p>
<div class="div3">
<h4><a name="func-node-before-examples" id=
"func-node-before-examples"></a>14.7.1 Examples</h4>
<ul>
<li>
<p><code>op:node-before($item1, $item2)</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>op:node-before($item1, $item1)</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-node-after" id="func-node-after"></a>14.8
op:node-after</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:node-after</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If the node identified by the value of
<code>$parameter1</code> occurs in document order after the node
identified by the value of <code>$parameter2</code>, this function
returns <code>true</code>; otherwise, it returns
<code>false</code>. The rules determining the order of nodes within
a single document and in different documents can be found in
<a href=
"http://www.w3.org/TR/xpath-datamodel/#document-order">Section 2.4
Document Order</a><sup><small>DM</small></sup>. This function backs
up the "&gt;&gt;" operator.</p>
<div class="div3">
<h4><a name="func-node-after-examples" id=
"func-node-after-examples"></a>14.8.1 Examples</h4>
<ul>
<li>
<p><code>op:node-after($item1, $item2)</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>op:node-after($item1, $item1)</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>op:node-after($item2, $item1)</code> returns
<code>true</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-root" id="func-root"></a>14.9 fn:root</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:root</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:root</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()?</code></div>
</div>
<p>Summary: Returns the root of the tree to which <code>$arg</code>
belongs. This will usually, but not necessarily, be a document
node.</p>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned.</p>
<p>If <code>$arg</code> is a document node, <code>$arg</code> is
returned.</p>
<p>If the function is called without an argument, the context item
(<code>.</code>) is used as the default argument. The behavior of
the function if the argument is omitted is exactly the same as if
the context item had been passed as the argument.</p>
<p>The following errors may be raised: if the context item is
undefined [<a href="http://www.w3.org/TR/xpath20/#ERRXPDY0002"
title="err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>;
if the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<div class="div3">
<h4><a name="func-root-examples" id="func-root-examples"></a>14.9.1
Examples</h4>
<p>These examples use some variables which could be defined in
<a href="#xquery">[XQuery 1.0: An XML Query Language]</a> as:</p>
<div class="exampleInner">
<pre>
let $i := &lt;tool&gt;wrench&lt;/tool&gt;
let $o := &lt;order&gt; {$i} &lt;quantity&gt;5&lt;/quantity&gt; &lt;/order&gt;
let $odoc := document {$o}
let $newi := $o/tool
</pre></div>
<p>Or they could be defined in <a href="#xslt20">[XSL
Transformations (XSLT) Version 2.0]</a> as:</p>
<div class="exampleInner">
<pre>
&lt;xsl:variable name="i" as="element()"&gt;
&lt;tool&gt;wrench&lt;/tool&gt;
&lt;/xsl:variable&gt;
&lt;xsl:variable name="o" as="element()"&gt;
&lt;order&gt;
&lt;xsl:copy-of select="$i"/&gt;
&lt;quantity&gt;5&lt;/quantity&gt;
&lt;/order&gt;
&lt;/xsl:variable&gt;
&lt;xsl:variable name="odoc"&gt;
&lt;xsl:copy-of select="$o"/&gt;
&lt;/xsl:variable&gt;
&lt;xsl:variable name="newi" select="$o/tool"/&gt;
</pre></div>
<ul>
<li>
<p><code>fn:root($i)</code> returns <code>$i</code></p>
</li>
<li>
<p><code>fn:root($o/quantity)</code> returns <code>$o</code></p>
</li>
<li>
<p><code>fn:root($odoc//quantity)</code> returns
<code>$odoc</code></p>
</li>
<li>
<p><code>fn:root($newi)</code> returns <code>$o</code></p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The final three examples could be made type-safe by wrapping
their operands with fn:exactly-one().</p>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="sequence-functions" id="sequence-functions"></a>15
Functions and Operators on Sequences</h2>
<p>A <code>sequence</code> is an ordered collection of zero or more
<code>items</code>. An <code>item</code> is either a node or an
atomic value. The terms <code>sequence</code> and <code>item</code>
are defined formally in <a href="#xquery">[XQuery 1.0: An XML Query
Language]</a> and <a href="#xpath20">[XML Path Language (XPath)
2.0]</a>.</p>
<div class="div2">
<h3><a name="general-seq-funcs" id="general-seq-funcs"></a>15.1
General Functions and Operators on Sequences</h3>
<p>The following functions are defined on sequences.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-boolean"><code>fn:boolean</code></a></td>
<td>Computes the effective boolean value of the argument
sequence.</td>
</tr>
<tr>
<td><a href=
"#func-concatenate"><code>op:concatenate</code></a></td>
<td>Concatenates two sequences.</td>
</tr>
<tr>
<td><a href="#func-index-of"><code>fn:index-of</code></a></td>
<td>Returns a sequence of <code>xs:integer</code>s, each of which
is the index of a member of the sequence specified as the first
argument that is equal to the value of the second argument. If no
members of the specified sequence are equal to the value of the
second argument, the empty sequence is returned.</td>
</tr>
<tr>
<td><a href="#func-empty"><code>fn:empty</code></a></td>
<td>Indicates whether or not the provided sequence is empty.</td>
</tr>
<tr>
<td><a href="#func-exists"><code>fn:exists</code></a></td>
<td>Indicates whether or not the provided sequence is not
empty.</td>
</tr>
<tr>
<td><a href=
"#func-distinct-values"><code>fn:distinct-values</code></a></td>
<td>Returns a sequence in which all but one of a set of duplicate
values, based on value equality, have been deleted. The order in
which the distinct values are returned is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</td>
</tr>
<tr>
<td><a href=
"#func-insert-before"><code>fn:insert-before</code></a></td>
<td>Inserts an item or sequence of items at a specified position in
a sequence.</td>
</tr>
<tr>
<td><a href="#func-remove"><code>fn:remove</code></a></td>
<td>Removes an item from a specified position in a sequence.</td>
</tr>
<tr>
<td><a href="#func-reverse"><code>fn:reverse</code></a></td>
<td>Reverses the order of items in a sequence.</td>
</tr>
<tr>
<td><a href=
"#func-subsequence"><code>fn:subsequence</code></a></td>
<td>Returns the subsequence of a given sequence, identified by
location.</td>
</tr>
<tr>
<td><a href="#func-unordered"><code>fn:unordered</code></a></td>
<td>Returns the items in the given sequence in a non-deterministic
order.</td>
</tr>
</tbody>
</table>
<p>As in the previous section, for the illustrative examples below,
assume an XQuery or transformation operating on a non-empty
Purchase Order document containing a number of line-item elements.
The variable <code>$seq</code> is bound to the sequence of
line-item nodes in document order. The variables
<code>$item1</code>, <code>$item2</code>, etc. are bound to
separate, individual line-item nodes in the sequence.</p>
<div class="div3">
<h4><a name="func-boolean" id="func-boolean"></a>15.1.1
fn:boolean</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:boolean</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: Computes the effective boolean value of the sequence
<code>$arg</code>. See <a href=
"http://www.w3.org/TR/xpath20/#id-ebv">Section 2.4.3 Effective
Boolean Value</a><sup><small>XP</small></sup></p>
<ul>
<li>
<p>If <code>$arg</code> is the empty sequence,
<code>fn:boolean</code> returns <code>false</code>.</p>
</li>
<li>
<p>If <code>$arg</code> is a sequence whose first item is a node,
<code>fn:boolean</code> returns <code>true</code>.</p>
</li>
<li>
<p>If <code>$arg</code> is a singleton value of type
<code>xs:boolean</code> or a derived from <code>xs:boolean</code>,
<code>fn:boolean</code> returns <code>$arg</code>.</p>
</li>
<li>
<p>If <code>$arg</code> is a singleton value of type
<code>xs:string</code> or a type derived from
<code>xs:string</code>, <code>xs:anyURI</code> or a type derived
from <code>xs:anyURI</code> or <code>xs:untypedAtomic</code>,
<code>fn:boolean</code> returns <code>false</code> if the operand
value has zero length; otherwise it returns <code>true</code>.</p>
</li>
<li>
<p>If <code>$arg</code> is a singleton value of any numeric type or
a type derived from a numeric type, <code>fn:boolean</code> returns
<code>false</code> if the operand value is <code>NaN</code> or is
numerically equal to zero; otherwise it returns
<code>true</code>.</p>
</li>
<li>
<p>In all other cases, <code>fn:boolean</code> raises a type error
[<a href="#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
</ul>
<p>The static semantics of this function are described in <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_boolean">Section
7.2.4 The fn:boolean function</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The result of this function is not necessarily the same as "
<code>$arg cast as xs:boolean</code> ". For example,
<code>fn:boolean("false")</code> returns the value
<code>"true"</code> whereas "<code>false</code>" <code>cast as
xs:boolean</code> returns <code>false</code>.</p>
</div>
<div class="div4">
<h5><a name="func-boolean-examples" id=
"func-boolean-examples"></a>15.1.1.1 Examples</h5>
<p>let <code>$x := ("a", "b", "c")</code></p>
<ul>
<li>
<p><code>fn:boolean($x)</code> raises a type error [<a href=
"#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
<li>
<p><code>fn:boolean($x[1])</code> returns <code>true</code>.</p>
</li>
<li>
<p><code>fn:boolean($x[0])</code> returns <code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-concatenate" id="func-concatenate"></a>15.1.2
op:concatenate</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:concatenate</code>(<code class=
"arg">$seq1</code><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,
<code class="arg">$seq2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
</div>
<p>Summary: Returns a sequence consisting of the items in
<code>$seq1</code> followed by the items in <code>$seq2</code>.
This function backs up the infix operator ",". If either sequence
is the empty sequence, the other operand is returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_constructing_sequences">
Section 4.3.1 Constructing
Sequences</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-concatenate-examples" id=
"func-concatenate-examples"></a>15.1.2.1 Examples</h5>
<ul>
<li>
<p><code>op:concatenate((1, 2, 3), (4, 5))</code> returns <code>(1,
2, 3, 4, 5)</code>.</p>
</li>
<li>
<p><code>op:concatenate((1, 2, 3), ())</code> returns <code>(1, 2,
3)</code>.</p>
</li>
<li>
<p><code>op:concatenate((), ())</code> returns <code>()</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-index-of" id="func-index-of"></a>15.1.3
fn:index-of</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:index-of</code>(</td>
<td valign="baseline"><code class="arg">$seqParam</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$srchParam</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer*</code></td>
</tr>
</table>
</div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:index-of</code>(</td>
<td valign="baseline"><code class="arg">$seqParam</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$srchParam</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer*</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns a sequence of positive integers giving the
positions within the sequence <code>$seqParam</code> of items that
are equal to <code>$srchParam</code>.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>. The collation is used when string comparison is
required.</p>
<p>The items in the sequence <code>$seqParam</code> are compared
with <code>$srchParam</code> under the rules for the
<code>eq</code> operator. Values of type
<code>xs:untypedAtomic</code> are compared as if they were of type
<code>xs:string</code>. Values that cannot be compared, i.e. the
<code>eq</code> operator is not defined for their types, are
considered to be distinct. If an item compares equal, then the
position of that item in the sequence <code>$seqParam</code> is
included in the result.</p>
<p>If the value of <code>$seqParam</code> is the empty sequence, or
if no item in <code>$seqParam</code> matches
<code>$srchParam</code>, then the empty sequence is returned.</p>
<p>The first item in a sequence is at position 1, not position
0.</p>
<p>The result sequence is in ascending numeric order.</p>
<div class="div4">
<h5><a name="func-index-of-examples" id=
"func-index-of-examples"></a>15.1.3.1 Examples</h5>
<ul>
<li>
<p><code>fn:index-of ((10, 20, 30, 40), 35)</code> returns
<code>().</code></p>
</li>
<li>
<p><code>fn:index-of ((10, 20, 30, 30, 20, 10), 20)</code> returns
<code>(2, 5).</code></p>
</li>
<li>
<p><code>fn:index-of (("a", "sport", "and", "a", "pastime"),
"a")</code> returns <code>(1, 4).</code></p>
</li>
<li>
<p>If @a is an attribute of type <code>xs:NMTOKENS</code> whose
typed value is " <code>red green blue</code> ", then:
<code>fn:index-of (@a, "blue")</code> returns <code>3</code>.</p>
<p>This is because the function calling mechanism atomizes the
attribute node to produce a sequence of three
<code>xs:NMTOKEN</code>s.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-empty" id="func-empty"></a>15.1.4 fn:empty</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:empty</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If the value of <code>$arg</code> is the empty
sequence, the function returns <code>true</code>; otherwise, the
function returns <code>false</code>.</p>
<div class="div4">
<h5><a name="func-empty-examples" id=
"func-empty-examples"></a>15.1.4.1 Examples</h5>
<ul>
<li>
<p><code>fn:empty(fn:remove(("hello", "world"), 1))</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-exists" id="func-exists"></a>15.1.5
fn:exists</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:exists</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If the value of <code>$arg</code> is not the empty
sequence, the function returns <code>true</code>; otherwise, the
function returns <code>false</code>.</p>
<div class="div4">
<h5><a name="func-exists-examples" id=
"func-exists-examples"></a>15.1.5.1 Examples</h5>
<ul>
<li>
<p><code>fn:exists(fn:remove(("hello"), 1))</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-distinct-values" id=
"func-distinct-values"></a>15.1.6 fn:distinct-values</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:distinct-values</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType*</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:distinct-values</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the sequence that results from removing from
<code>$arg</code> all but one of a set of values that are
<code>eq</code> to one other. Values of type
<code>xs:untypedAtomic</code> are compared as if they were of type
<code>xs:string</code>. Values that cannot be compared, i.e. the
<code>eq</code> operator is not defined for their types, are
considered to be distinct. The order in which the sequence of
values is returned is <a title="implementation dependent" class=
"termref" href="#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>The static type of the result is a sequence of prime types as
defined in <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_distinct_node_vals">Section
7.2.7 The fn:distinct-values
function</a><sup><small>FS</small></sup>.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>. The collation is used when string comparison is
required.</p>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned.</p>
<p>For <code>xs:float</code> and <code>xs:double</code> values,
positive zero is equal to negative zero and, although
<code>NaN</code> does not equal itself, if <code>$arg</code>
contains multiple <code>NaN</code> values a single <code>NaN</code>
is returned.</p>
<p>If <code>xs:dateTime</code>, <code>xs:date</code> or
<code>xs:time</code> values do not have a timezone, they are
considered to have the implicit timezone provided by the dynamic
context for the purpose of comparison. Note that
<code>xs:dateTime</code>, <code>xs:date</code> or
<code>xs:time</code> values can compare equal even if their
timezones are different.</p>
<p>Which value of a set of values that compare equal is returned is
<a title="implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="div4">
<h5><a name="func-distinct-values-examples" id=
"func-distinct-values-examples"></a>15.1.6.1 Examples</h5>
<ul>
<li>
<p><code>fn:distinct-values((1, 2.0, 3, 2))</code> might return
<code>(1, 3, 2.0)</code>.</p>
</li>
<li>
<p>The following query:</p>
<div class="exampleInner">
<pre>
let $x as xs:untypedAtomic*
:= (xs:untypedAtomic("cherry"),
xs:untypedAtomic("bar"),
xs:untypedAtomic("bar"))
return fn:distinct-values ($x)
</pre></div>
returns a sequence containing two items of type
<code>xs:untypedAtomic</code>.</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-insert-before" id="func-insert-before"></a>15.1.7
fn:insert-before</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:insert-before</code>(</td>
<td valign="baseline"><code class="arg">$target</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$position</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:integer</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$inserts</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns a new sequence constructed from the value of
<code>$target</code> with the value of <code>$inserts</code>
inserted at the position specified by the value of
<code>$position</code>. (The value of <code>$target</code> is not
affected by the sequence construction.)</p>
<p>If <code>$target</code> is the empty sequence,
<code>$inserts</code> is returned. If <code>$inserts</code> is the
empty sequence, <code>$target</code> is returned.</p>
<p>The value returned by the function consists of all items of
<code>$target</code> whose index is less than
<code>$position</code>, followed by all items of
<code>$inserts</code>, followed by the remaining elements of
<code>$target</code>, in that sequence.</p>
<p>If <code>$position</code> is less than one (1), the first
position, the effective value of <code>$position</code> is one (1).
If <code>$position</code> is greater than the number of items in
<code>$target</code>, then the effective value of
<code>$position</code> is equal to the number of items in
<code>$target</code> plus 1.</p>
<p>For detailed semantics see, <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_insert_before">Section
7.2.15 The fn:insert-before
function</a><sup><small>FS</small></sup>.</p>
<div class="div4">
<h5><a name="func-insert-before-examples" id=
"func-insert-before-examples"></a>15.1.7.1 Examples</h5>
<p>let <code>$x</code> := <code>("a", "b", "c")</code></p>
<ul>
<li>
<p><code>fn:insert-before($x, 0, "z")</code> returns <code>("z",
"a", "b", "c")</code></p>
</li>
<li>
<p><code>fn:insert-before($x, 1, "z")</code> returns <code>("z",
"a", "b", "c")</code></p>
</li>
<li>
<p><code>fn:insert-before($x, 2, "z")</code> returns <code>("a",
"z", "b", "c")</code></p>
</li>
<li>
<p><code>fn:insert-before($x, 3, "z")</code> returns <code>("a",
"b", "z", "c")</code></p>
</li>
<li>
<p><code>fn:insert-before($x, 4, "z")</code> returns <code>("a",
"b", "c", "z")</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-remove" id="func-remove"></a>15.1.8
fn:remove</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:remove</code>(<code class=
"arg">$target</code><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,
<code class="arg">$position</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:integer</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
</div>
<p>Summary: Returns a new sequence constructed from the value of
<code>$target</code> with the item at the position specified by the
value of <code>$position</code> removed.</p>
<p>If <code>$position</code> is less than 1 or greater than the
number of items in <code>$target</code>, <code>$target</code> is
returned. Otherwise, the value returned by the function consists of
all items of <code>$target</code> whose index is less than
<code>$position</code>, followed by all items of
<code>$target</code> whose index is greater than
<code>$position</code>. If <code>$target</code> is the empty
sequence, the empty sequence is returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_remove">Section
7.2.11 The fn:remove function</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-remove-examples" id=
"func-remove-examples"></a>15.1.8.1 Examples</h5>
<p>let <code>$x</code> := <code>("a", "b", "c")</code></p>
<ul>
<li>
<p><code>fn:remove($x, 0)</code> returns <code>("a", "b",
"c")</code></p>
</li>
<li>
<p><code>fn:remove($x, 1)</code> returns <code>("b",
"c")</code></p>
</li>
<li>
<p><code>fn:remove($x, 6)</code> returns <code>("a", "b",
"c")</code></p>
</li>
<li>
<p><code>fn:remove((), 3)</code> returns <code>()</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-reverse" id="func-reverse"></a>15.1.9
fn:reverse</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:reverse</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
</div>
<p>Summary: Reverses the order of items in a sequence. If
<code>$arg</code> is the empty sequence, the empty sequence is
returned.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_reverse">Section
7.2.12 The fn:reverse function</a><sup><small>FS</small></sup></p>
<div class="div4">
<h5><a name="func-reverse-examples" id=
"func-reverse-examples"></a>15.1.9.1 Examples</h5>
<p>let <code>$x</code> := <code>("a", "b", "c")</code></p>
<ul>
<li>
<p><code>fn:reverse($x)</code> returns <code>("c", "b",
"a")</code></p>
</li>
<li>
<p><code>fn:reverse(("hello"))</code> returns
<code>("hello")</code></p>
</li>
<li>
<p><code>fn:reverse(())</code> returns <code>()</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-subsequence" id="func-subsequence"></a>15.1.10
fn:subsequence</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:subsequence</code>(<code class=
"arg">$sourceSeq</code><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,
<code class="arg">$startingLoc</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:subsequence</code>(</td>
<td valign="baseline"><code class="arg">$sourceSeq</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$startingLoc</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:double</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$length</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns the contiguous sequence of items in the value
of <code>$sourceSeq</code> beginning at the position indicated by
the value of <code>$startingLoc</code> and continuing for the
number of items indicated by the value of <code>$length</code>.</p>
<p>In the two-argument case, returns:</p>
<div class="exampleInner">
<pre>
$sourceSeq[fn:round($startingLoc) le $p]
</pre></div>
<p>In the three-argument case, returns:</p>
<div class="exampleInner">
<pre>
$sourceSeq[fn:round($startingLoc) le $p
and $p lt fn:round($startingLoc) + fn:round($length)]
</pre></div>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>If <code>$sourceSeq</code> is the empty sequence, the empty
sequence is returned.</p>
<p>If <code>$startingLoc</code> is zero or negative, the
subsequence includes items from the beginning of the
<code>$sourceSeq</code>.</p>
<p>If <code>$length</code> is not specified, the subsequence
includes items to the end of <code>$sourceSeq</code>.</p>
<p>If <code>$length</code> is greater than the number of items in
the value of <code>$sourceSeq</code> following
<code>$startingLoc</code>, the subsequence includes items to the
end of <code>$sourceSeq</code>.</p>
<p>The first item of a sequence is located at position 1, not
position 0.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_subsequence">Section
7.2.13 The fn:subsequence
function</a><sup><small>FS</small></sup>.</p>
<p>The reason the function accepts arguments of type
<code>xs:double</code> is that many computations on untyped data
return an <code>xs:double</code> result; and the reason for the
rounding rules is to compensate for any imprecision in these
floating-point computations.</p>
</div>
<div class="div4">
<h5><a name="func-subsequence-examples" id=
"func-subsequence-examples"></a>15.1.10.1 Examples</h5>
<p>Assume <code>$seq = ($item1, $item2, $item3, $item4,
...)</code></p>
<ul>
<li>
<p><code>fn:subsequence($seq, 4)</code> returns <code>($item4,
...)</code></p>
</li>
<li>
<p><code>fn:subsequence($seq, 3, 2)</code> returns <code>($item3,
$item4)</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-unordered" id="func-unordered"></a>15.1.11
fn:unordered</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:unordered</code>(<code class=
"arg">$sourceSeq</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()*</code></div>
</div>
<p>Summary: Returns the items of <code>$sourceSeq</code> in an
<a title="implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a> order.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Query optimizers may be able to do a better job if the order of
the output sequence is not specified. For example, when retrieving
prices from a purchase order, if an index exists on prices, it may
be more efficient to return the prices in index order rather than
in document order.</p>
</div>
</div>
</div>
<div class="div2">
<h3><a name="cardinality-functions" id=
"cardinality-functions"></a>15.2 Functions That Test the
Cardinality of Sequences</h3>
<p>The following functions test the cardinality of their sequence
arguments.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href=
"#func-zero-or-one"><code>fn:zero-or-one</code></a></td>
<td>Returns the input sequence if it contains zero or one items.
Raises an error otherwise.</td>
</tr>
<tr>
<td><a href=
"#func-one-or-more"><code>fn:one-or-more</code></a></td>
<td>Returns the input sequence if it contains one or more items.
Raises an error otherwise.</td>
</tr>
<tr>
<td><a href=
"#func-exactly-one"><code>fn:exactly-one</code></a></td>
<td>Returns the input sequence if it contains exactly one item.
Raises an error otherwise.</td>
</tr>
</tbody>
</table>
<p>The functions <a href=
"#func-zero-or-one"><code>fn:zero-or-one</code></a>, <a href=
"#func-one-or-more"><code>fn:one-or-more</code></a>, and <a href=
"#func-exactly-one"><code>fn:exactly-one</code></a> defined in this
section, check that the cardinality of a sequence is in the
expected range. They are particularly useful with regard to static
typing. For example, the XML Schema <a href="#xmlschema-1">[XML
Schema Part 1: Structures Second Edition]</a> describing the output
of a query may require a sequence of length one-or-more in some
position, but the static type system may not be able to infer this;
inserting a call to <a href=
"#func-one-or-more"><code>fn:one-or-more</code></a> at the
appropriate place will provide a suitable static type at query
analysis time, and confirm that the length is correct with a
dynamic check at query execution time.</p>
<div class="div3">
<h4><a name="func-zero-or-one" id="func-zero-or-one"></a>15.2.1
fn:zero-or-one</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:zero-or-one</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()?</code></div>
</div>
<p>Summary: Returns <code>$arg</code> if it contains zero or one
items. Otherwise, raises an error [<a href="#ERRFORG0003" title=
"err:FORG0003">err:FORG0003</a>].</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_cardinality_funcs">Section
7.2.16 The fn:zero-or-one, fn:one-or-more, and fn:exactly-one
functions</a><sup><small>FS</small></sup></p>
</div>
<div class="div3">
<h4><a name="func-one-or-more" id="func-one-or-more"></a>15.2.2
fn:one-or-more</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:one-or-more</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()+</code></div>
</div>
<p>Summary: Returns <code>$arg</code> if it contains one or more
items. Otherwise, raises an error [<a href="#ERRFORG0004" title=
"err:FORG0004">err:FORG0004</a>].</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_cardinality_funcs">Section
7.2.16 The fn:zero-or-one, fn:one-or-more, and fn:exactly-one
functions</a><sup><small>FS</small></sup></p>
</div>
<div class="div3">
<h4><a name="func-exactly-one" id="func-exactly-one"></a>15.2.3
fn:exactly-one</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:exactly-one</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">item()</code></div>
</div>
<p>Summary: Returns <code>$arg</code> if it contains exactly one
item. Otherwise, raises an error [<a href="#ERRFORG0005" title=
"err:FORG0005">err:FORG0005</a>].</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_cardinality_funcs">Section
7.2.16 The fn:zero-or-one, fn:one-or-more, and fn:exactly-one
functions</a><sup><small>FS</small></sup></p>
</div>
</div>
<div class="div2">
<h3><a name="union-intersection-except" id=
"union-intersection-except"></a>15.3 Equals, Union, Intersection
and Except</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-deep-equal"><code>fn:deep-equal</code></a></td>
<td>Returns <code>true</code> if the two arguments have items that
compare equal in corresponding positions.</td>
</tr>
<tr>
<td><a href="#func-union"><code>op:union</code></a></td>
<td>Returns the union of the two sequence arguments, eliminating
duplicates.</td>
</tr>
<tr>
<td><a href="#func-intersect"><code>op:intersect</code></a></td>
<td>Returns the intersection of the two sequence arguments,
eliminating duplicates.</td>
</tr>
<tr>
<td><a href="#func-except"><code>op:except</code></a></td>
<td>Returns the difference of the two sequence arguments,
eliminating duplicates.</td>
</tr>
</tbody>
</table>
<p>As in the previous sections, for the illustrative examples
below, assume an XQuery or transformation operating on a Purchase
Order document containing a number of line-item elements. The
variables <code>$item1</code>, <code>$item2</code>, etc. are bound
to individual line-item nodes in the sequence. We use sequences of
these nodes in some of the examples below.</p>
<div class="div3">
<h4><a name="func-deep-equal" id="func-deep-equal"></a>15.3.1
fn:deep-equal</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:deep-equal</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:deep-equal</code>(</td>
<td valign="baseline"><code class="arg">$parameter1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$parameter2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">item()*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: This function assesses whether two sequences are
deep-equal to each other. To be deep-equal, they must contain items
that are pairwise deep-equal; and for two items to be deep-equal,
they must either be atomic values that compare equal, or nodes of
the same kind, with the same name, whose children are deep-equal.
This is defined in more detail below. The <code>$collation</code>
argument identifies a collation which is used at all levels of
recursion when strings are compared (but not when names are
compared), according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>.</p>
<p>If the two sequences are both empty, the function returns
<code>true</code>.</p>
<p>If the two sequences are of different lengths, the function
returns <code>false</code>.</p>
<p>If the two sequences are of the same length, the function
returns <code>true</code> if and only if every item in the sequence
<code>$parameter1</code> is deep-equal to the item at the same
position in the sequence <code>$parameter2</code>. The rules for
deciding whether two items are deep-equal follow.</p>
<p>Call the two items <code>$i1</code> and <code>$i2</code>
respectively.</p>
<p>If <code>$i1</code> and <code>$i2</code> are both atomic values,
they are deep-equal if and only if <code>($i1 eq $i2)</code> is
<code>true</code>, or if both values are <code>NaN</code>. If the
<code>eq</code> operator is not defined for <code>$i1</code> and
<code>$i2</code>, the function returns <code>false</code>.</p>
<p>If one of the pair <code>$i1</code> or <code>$i2</code> is an
atomic value and the other is a node, the function returns
<code>false</code>.</p>
<p>If <code>$i1</code> and <code>$i2</code> are both nodes, they
are compared as described below:</p>
<p>If the two nodes are of different kinds, the result is
<code>false</code>.</p>
<p>If the two nodes are both document nodes then they are
deep-equal if and only if the sequence <code>$i1/(*|text())</code>
is deep-equal to the sequence <code>$i2/(*|text())</code>.</p>
<p>If the two nodes are both element nodes then they are deep-equal
if and only if all of the following conditions are satisfied:</p>
<ol class="enumar">
<li>
<p>the two nodes have the same name, that is <code>(node-name($i1)
eq node-name($i2))</code>.</p>
</li>
<li>
<p>the two nodes are both annotated as having simple content or
both nodes are annotated as having complex content.</p>
</li>
<li>
<p>the two nodes have the same number of attributes, and for every
attribute <code>$a1</code> in <code>$i1/@*</code> there exists an
attribute <code>$a2</code> in <code>$i2/@*</code> such that
<code>$a1</code> and <code>$a2</code> are deep-equal.</p>
</li>
<li>
<p>One of the following conditions holds:</p>
<ul>
<li>
<p>Both element nodes have a type annotation that is simple
content, and the typed value of <code>$i1</code> is deep-equal to
the typed value of <code>$i2</code>.</p>
</li>
<li>
<p>Both element nodes have a type annotation that is complex
content with elementOnly content, and each child element of
<code>$i1</code> is deep-equal to the corresponding child element
of <code>$i2</code>.</p>
</li>
<li>
<p>Both element nodes have a type annotation that is complex
content with mixed content, and the sequence
<code>$i1/(*|text())</code> is deep-equal to the sequence
<code>$i2/(*|text())</code>.</p>
</li>
<li>
<p>Both element nodes have a type annotation that is complex
content with empty content.</p>
</li>
</ul>
</li>
</ol>
<p>If the two nodes are both attribute nodes then they are
deep-equal if and only if both the following conditions are
satisfied:</p>
<ol class="enumar">
<li>
<p>the two nodes have the same name, that is <code>(node-name($i1)
eq node-name($i2))</code>.</p>
</li>
<li>
<p>the typed value of <code>$i1</code> is deep-equal to the typed
value of <code>$i2</code>.</p>
</li>
</ol>
<p>If the two nodes are both processing instruction nodes or
namespace bindings, then they are deep-equal if and only if both
the following conditions are satisfied:</p>
<ol class="enumar">
<li>
<p>the two nodes have the same name, that is <code>(node-name($i1)
eq node-name($i2))</code>.</p>
</li>
<li>
<p>the string value of <code>$i1</code> is equal to the string
value of <code>$i2</code>.</p>
</li>
</ol>
<p>If the two nodes are both text nodes or comment nodes, then they
are deep-equal if and only if their string-values are equal.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>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 the
values returned by the <code>is-id</code> and
<code>is-idrefs</code> accessors (see <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-is-id">Section 5.5 is-id
Accessor</a><sup><small>DM</small></sup> and <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-is-idrefs">Section 5.6
is-idrefs Accessor</a><sup><small>DM</small></sup>). The order of
children is significant, but the order of attributes is
insignificant.</p>
<p>The contents of comments and processing instructions are
significant only if these nodes appear directly as items in the two
sequences being compared. The content of a comment or processing
instruction that appears as a descendant of an item in one of the
sequences being compared does not affect the result. However, the
presence of a comment or processing instruction, if it causes a
text node to be split into two text nodes, may affect the
result.</p>
<p>The result of <code>fn:deep-equal(1, current-dateTime())</code>
is <code>false</code>; it does not raise an error.</p>
</div>
<div class="div4">
<h5><a name="func-deep-equal-examples" id=
"func-deep-equal-examples"></a>15.3.1.1 Examples</h5>
<div class="exampleInner">
<pre>
let $at := &lt;attendees&gt; &lt;name last='Parker'
first='Peter'/&gt; &lt;name last='Barker' first='Bob'/&gt;
&lt;name last='Parker' first='Peter'/&gt; &lt;/attendees&gt;
</pre></div>
<ul>
<li>
<p><code>fn:deep-equal($at, $at/*)</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>fn:deep-equal($at/name[1], $at/name[2])</code> returns
<code>false</code>.</p>
</li>
<li>
<p><code>fn:deep-equal($at/name[1], $at/name[3])</code> returns
<code>true</code>.</p>
</li>
<li>
<p><code>fn:deep-equal($at/name[1], 'Peter Parker')</code> returns
<code>false</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-union" id="func-union"></a>15.3.2 op:union</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:union</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()*</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">node()*</code></div>
</div>
<p>Summary: Constructs a sequence containing every node that occurs
in the values of either <code>$parameter1</code> or
<code>$parameter2</code>, eliminating duplicate nodes. Nodes are
returned in document order. Two nodes are duplicates if they are
<a href=
"#func-is-same-node"><code>op:is-same-node()</code></a>.</p>
<p>If either operand is the empty sequence, a sequence is returned
containing the nodes in the other operand in document order after
eliminating duplicates.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_op_union_intersect_except">
Section 7.2.14 The op:union, op:intersect, and op:except
operators</a><sup><small>FS</small></sup></p>
<p>This function backs up the "union" or "|" operator.</p>
<div class="div4">
<h5><a name="func-union-examples" id=
"func-union-examples"></a>15.3.2.1 Examples</h5>
<p>Assume <code>$seq1 = ($item1, $item2), $seq2 = ($item1,
$item2)</code> and <code>$seq3 = ($item2, $item3)</code>.</p>
<ul>
<li>
<p><code>op:union($seq1, $seq1)</code> returns the sequence
<code>($item1, $item2)</code>.</p>
</li>
<li>
<p><code>op:union($seq2, $seq3)</code> returns the sequence
consisting of <code>($item1, $item2, $item3)</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-intersect" id="func-intersect"></a>15.3.3
op:intersect</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:intersect</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()*</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">node()*</code></div>
</div>
<p>Summary: Constructs a sequence containing every node that occurs
in the values of both <code>$parameter1</code> and
<code>$parameter2</code>, eliminating duplicate nodes. Nodes are
returned in document order.</p>
<p>If either operand is the empty sequence, the empty sequence is
returned.</p>
<p>Two nodes are duplicates if they are <a href=
"#func-is-same-node"><code>op:is-same-node()</code></a>.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_op_union_intersect_except">
Section 7.2.14 The op:union, op:intersect, and op:except
operators</a><sup><small>FS</small></sup>.</p>
<p>This function backs up the "intersect" operator.</p>
<div class="div4">
<h5><a name="func-intersect-examples" id=
"func-intersect-examples"></a>15.3.3.1 Examples</h5>
<p>Assume <code>$seq1 = ($item1, $item2), $seq2 = ($item1,
$item2)</code> and <code>$seq3 = ($item2, $item3)</code>.</p>
<ul>
<li>
<p><code>op:intersect($seq1, $seq1)</code> returns the sequence
<code>($item1, $item2)</code>.</p>
</li>
<li>
<p><code>op:intersect($seq2, $seq3)</code> returns the sequence
<code>($item2)</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-except" id="func-except"></a>15.3.4
op:except</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">op:except</code>(<code class=
"arg">$parameter1</code><code class=
"as">&#160;as&#160;</code><code class="type">node()*</code>,
<code class="arg">$parameter2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">node()*</code></div>
</div>
<p>Summary: Constructs a sequence containing every node that occurs
in the value of <code>$parameter1</code>, but not in the value of
<code>$parameter2</code>, eliminating duplicate nodes. Nodes are
returned in document order.</p>
<p>If <code>$parameter1</code> is the empty sequence, the empty
sequence is returned. If <code>$parameter2</code> is the empty
sequence, a sequence is returned containing the nodes in
<code>$parameter1</code> in document order after eliminating
duplicates.</p>
<p>Two nodes are duplicates if they are <a href=
"#func-is-same-node"><code>op:is-same-node()</code></a>.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_op_union_intersect_except">
Section 7.2.14 The op:union, op:intersect, and op:except
operators</a><sup><small>FS</small></sup>.</p>
<p>This function backs up the "except" operator.</p>
<div class="div4">
<h5><a name="func-except-examples" id=
"func-except-examples"></a>15.3.4.1 Examples</h5>
<p>Assume <code>$seq1 = ($item1, $item2), $seq2 = ($item1,
$item2)</code> and <code>$seq3 = ($item2, $item3)</code>.</p>
<ul>
<li>
<p><code>op:except($seq1, $seq2)</code> returns the empty
sequence.</p>
</li>
<li>
<p><code>op:except($seq2, $seq3)</code> returns the sequence
<code>($item1)</code>.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="aggregate-functions" id="aggregate-functions"></a>15.4
Aggregate Functions</h3>
<p>Aggregate functions take a sequence as argument and return a
single value computed from values in the sequence. Except for
<a href="#func-count"><code>fn:count</code></a>, the sequence must
consist of values of a single type or one if its subtypes, or they
must be numeric. <code>xs:untypedAtomic</code> values are permitted
in the input sequence and handled by special conversion rules. The
type of the items in the sequence must also support certain
operations.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-count"><code>fn:count</code></a></td>
<td>Returns the number of items in a sequence.</td>
</tr>
<tr>
<td><a href="#func-avg"><code>fn:avg</code></a></td>
<td>Returns the average of a sequence of values.</td>
</tr>
<tr>
<td><a href="#func-max"><code>fn:max</code></a></td>
<td>Returns the maximum value from a sequence of comparable
values.</td>
</tr>
<tr>
<td><a href="#func-min"><code>fn:min</code></a></td>
<td>Returns the minimum value from a sequence of comparable
values.</td>
</tr>
<tr>
<td><a href="#func-sum"><code>fn:sum</code></a></td>
<td>Returns the sum of a sequence of values.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-count" id="func-count"></a>15.4.1 fn:count</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:count</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<p>Summary: Returns the number of items in the value of
<code>$arg</code>.</p>
<p>Returns 0 if <code>$arg</code> is the empty sequence.</p>
<div class="div4">
<h5><a name="func-count-examples" id=
"func-count-examples"></a>15.4.1.1 Examples</h5>
<p>Assume <code>$seq1 = ($item1, $item2)</code> and <code>$seq3 =
()</code>, the empty sequence.</p>
<ul>
<li>
<p><code>fn:count($seq1)</code> returns <code>2</code>.</p>
</li>
<li>
<p><code>fn:count($seq3)</code> returns <code>0</code>.</p>
</li>
</ul>
<p>Assume <code>$seq2 = (98.5, 98.3, 98.9)</code>.</p>
<ul>
<li>
<p><code>fn:count($seq2)</code> returns <code>3</code>.</p>
</li>
<li>
<p><code>fn:count($seq2[. &gt; 100])</code> returns
<code>0</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-avg" id="func-avg"></a>15.4.2 fn:avg</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:avg</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></div>
</div>
<p>Summary: Returns the average of the values in the input sequence
<code>$arg</code>, that is, the sum of the values divided by the
number of values.</p>
<p>If <code>$arg</code> is the empty sequence, the empty sequence
is returned.</p>
<p>If <code>$arg</code> contains values of type
<code>xs:untypedAtomic</code> they are cast to
<code>xs:double</code>.</p>
<p>Duration values must either all be
<code>xs:yearMonthDuration</code> values or must all be
<code>xs:dayTimeDuration</code> values. For numeric values, the
numeric promotion rules defined in <a href="#op.numeric"><b>6.2
Operators on Numeric Values</b></a> are used to promote all values
to a single common type. After these operations, <code>$arg</code>
must contain items of a single type, which must be one of the four
numeric types, <code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code> or one if its subtypes.</p>
<p>If the above conditions are not met, then a type error is raised
[<a href="#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
<p>Otherwise, returns the average of the values as <code>sum($arg)
div count($arg)</code>; but the implementation may use an otherwise
equivalent algorithm that avoids arithmetic overflow.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum
functions</a><sup><small>FS</small></sup>.</p>
<div class="div4">
<h5><a name="func-avg-examples" id="func-avg-examples"></a>15.4.2.1
Examples</h5>
<p>Assume <code>$d1 = xs:yearMonthDuration("P20Y")</code> and
<code>$d2 = xs:yearMonthDuration("P10M")</code> and <code>$seq3 =
(3, 4, 5)</code>.</p>
<ul>
<li>
<p><code>fn:avg($seq3)</code> returns <code>4.0</code>.</p>
</li>
<li>
<p><code>fn:avg(($d1, $d2))</code> returns a
<code>yearMonthDuration</code> with value <code>125</code>
months.</p>
</li>
<li>
<p><code>fn:avg(($d1, $seq3))</code> raises a type error [<a href=
"#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
<li>
<p><code>fn:avg(())</code> returns <code>()</code>.</p>
</li>
<li>
<p><code>fn:avg((xs:float('INF'), xs:float('-INF')))</code> returns
<code>NaN</code>.</p>
</li>
<li>
<p><code>fn:avg(($seq3, xs:float('NaN')))</code> returns
<code>NaN</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-max" id="func-max"></a>15.4.3 fn:max</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:max</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></div>
<div class="proto"><code class=
"function">fn:max</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>, <code class=
"arg">$collation</code><code class=
"as">&#160;as&#160;</code><code class=
"type">string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></div>
</div>
<p>Summary: Selects an item from the input sequence
<code>$arg</code> whose value is greater than or equal to the value
of every other item in the input sequence. If there are two or more
such items, then the specific item whose value is returned is
<a title="implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>The following rules are applied to the input sequence:</p>
<ul>
<li>
<p>Values of type <code>xs:untypedAtomic</code> in
<code>$arg</code> are cast to <code>xs:double</code>.</p>
</li>
<li>
<p>Numeric and <code>xs:anyURI</code> values are converted to the
least common type that supports the <code>ge</code> operator by a
combination of type promotion and subtype substitution. See
<a href="http://www.w3.org/TR/xpath20/#promotion">Section B.1 Type
Promotion</a><sup><small>XP</small></sup> and <a href=
"http://www.w3.org/TR/xpath20/#mapping">Section B.2 Operator
Mapping</a><sup><small>XP</small></sup>.</p>
</li>
</ul>
<p>The items in the resulting sequence may be reordered in an
arbitrary order. The resulting sequence is referred to below as the
converted sequence. This function returns an item from the
converted sequence rather than the input sequence.</p>
<p>If the converted sequence is empty, the empty sequence is
returned.</p>
<p>All items in <code>$arg</code> must be numeric or derived from a
single base type for which the <code>ge</code> operator is defined.
In addition, the values in the sequence must have a total order. If
date/time values do not have a timezone, they are considered to
have the implicit timezone provided by the dynamic context for
purposes of comparison. Duration values must either all be
<code>xs:yearMonthDuration</code> values or must all be
<code>xs:dayTimeDuration</code> values.</p>
<p>If any of these conditions is not met, then a type error is
raised [<a href="#ERRFORG0006" title=
"err:FORG0006">err:FORG0006</a>].</p>
<p>If the converted sequence contains the value <code>NaN</code>,
the value <code>NaN</code> is returned.</p>
<p>If the items in the value of <code>$arg</code> are of type
<code>xs:string</code> or types derived by restriction from
<code>xs:string</code>, then the determination of the item with the
largest value is made according to the collation that is used. If
the type of the items in <code>$arg</code> is not
<code>xs:string</code> and <code>$collation</code> is specified,
the collation is ignored.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>.</p>
<p>Otherwise, the result of the function is the result of the
expression:</p>
<div class="exampleInner">
<pre>
if (every $v in $c satisfies $c[1] ge $v)
then $c[1]
else fn:max(fn:subsequence($c, 2))
</pre></div>
<p>evaluated with <code>$collation</code> as the default collation
if specified, and with <code>$c</code> as the converted
sequence.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum
functions</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>If the converted sequence contains exactly one value then that
value is returned.</p>
<p>The default type when the <code>fn:max</code> function is
applied to <code>xs:untypedAtomic</code> values is
<code>xs:double</code>. This differs from the default type for
operators such as <code>gt</code>, and for sorting in XQuery and
XSLT, which is <code>xs:string</code>.</p>
</div>
<div class="div4">
<h5><a name="func-max-examples" id="func-max-examples"></a>15.4.3.1
Examples</h5>
<ul>
<li>
<p><code>fn:max((3,4,5))</code> returns <code>5</code>.</p>
</li>
<li>
<p><code>fn:max((5, 5.0e0))</code> returns <code>5.0e0</code>.</p>
</li>
<li>
<p><code>fn:max((3,4,"Zero"))</code> raises a type error [<a href=
"#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
<li>
<p><code>fn:max((fn:current-date(), xs:date("2001-01-01")))</code>
typically returns the current date.</p>
</li>
<li>
<p><code>fn:max(("a", "b", "c"))</code> returns "c" under a typical
default collation.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-min" id="func-min"></a>15.4.4 fn:min</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:min</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></div>
<div class="proto"><code class=
"function">fn:min</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>, <code class=
"arg">$collation</code><code class=
"as">&#160;as&#160;</code><code class=
"type">string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></div>
</div>
<p>Summary: selects an item from the input sequence
<code>$arg</code> whose value is less than or equal to the value of
every other item in the input sequence. If there are two or more
such items, then the specific item whose value is returned is
<a title="implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>The following rules are applied to the input sequence:</p>
<ul>
<li>
<p>Values of type <code>xs:untypedAtomic</code> in
<code>$arg</code> are cast to <code>xs:double</code>.</p>
</li>
<li>
<p>Numeric and <code>xs:anyURI</code> values are converted to the
least common type that supports the <code>le</code> operator by a
combination of type promotion and subtype substitution. See
<a href="http://www.w3.org/TR/xpath20/#promotion">Section B.1 Type
Promotion</a><sup><small>XP</small></sup> and <a href=
"http://www.w3.org/TR/xpath20/#mapping">Section B.2 Operator
Mapping</a><sup><small>XP</small></sup>.</p>
</li>
</ul>
<p>The items in the resulting sequence may be reordered in an
arbitrary order. The resulting sequence is referred to below as the
converted sequence. This function returns an item from the
converted sequence rather than the input sequence.</p>
<p>If the converted sequence is empty, the empty sequence is
returned.</p>
<p>All items in <code>$arg</code> must be numeric or derived from a
single base type for which the <code>le</code> operator is defined.
In addition, the values in the sequence must have a total order. If
date/time values do not have a timezone, they are considered to
have the implicit timezone provided by the dynamic context for the
purpose of comparison. Duration values must either all be
<code>xs:yearMonthDuration</code> values or must all be
<code>xs:dayTimeDuration</code> values.</p>
<p>If any of these conditions is not met, a type error is raised
[<a href="#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
<p>If the converted sequence contains the value <code>NaN</code>,
the value <code>NaN</code> is returned.</p>
<p>If the items in the value of <code>$arg</code> are of type
<code>xs:string</code> or types derived by restriction from
<code>xs:string</code>, then the determination of the item with the
smallest value is made according to the collation that is used. If
the type of the items in <code>$arg</code> is not
<code>xs:string</code> and <code>$collation</code> is specified,
the collation is ignored.</p>
<p>The collation used by the invocation of this function is
determined according to the rules in <a href="#collations"><b>7.3.1
Collations</b></a>.</p>
<p>Otherwise, the result of the function is the result of the
expression:</p>
<div class="exampleInner">
<pre>
if (every $v in $c satisfies $c[1] le $v)
then $c[1]
else fn:min(fn:subsequence($c, 2))
</pre></div>
<p>evaluated with <code>$collation</code> as the default collation
if specified, and with <code>$c</code> as the converted
sequence.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum
functions</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>If the converted sequence contains exactly one value then that
value is returned.</p>
<p>The default type when the <code>fn:min</code> function is
applied to <code>xs:untypedAtomic</code> values is
<code>xs:double</code>. This differs from the default type for
operators such as <code>lt</code>, and for sorting in XQuery and
XSLT, which is <code>xs:string</code>.</p>
</div>
<div class="div4">
<h5><a name="func-min-examples" id="func-min-examples"></a>15.4.4.1
Examples</h5>
<ul>
<li>
<p><code>fn:min((3,4,5))</code> returns <code>3</code>.</p>
</li>
<li>
<p><code>fn:min((5, 5.0e0))</code> returns <code>5.0e0</code>.</p>
</li>
<li>
<p><code>fn:min((3,4,"Zero"))</code> raises a type error [<a href=
"#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
<li>
<p><code>fn:min((xs:float(0.0E0), xs:float(-0.0E0)))</code> can
return either positive or negative zero. <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
does not distinguish between the values positive zero and negative
zero. The result is <a title="implementation dependent" class=
"termref" href="#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
</li>
<li>
<p><code>fn:min((fn:current-date(), xs:date("2001-01-01")))</code>
typically returns <code>xs:date("2001-01-01")</code>.</p>
</li>
<li>
<p><code>fn:min(("a", "b", "c"))</code> returns "a" under a typical
default collation.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-sum" id="func-sum"></a>15.4.5 fn:sum</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:sum</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType</code></div>
</div>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:sum</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$zero</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType?</code></td>
</tr>
</table>
</div>
</div>
<p>Summary: Returns a value obtained by adding together the values
in <code>$arg</code>. If <code>$zero</code> is not specified, then
the value returned for an empty sequence is the
<code>xs:integer</code> value 0. If <code>$zero</code> is
specified, then the value returned for an empty sequence is
<code>$zero</code>.</p>
<p>Any values of type <code>xs:untypedAtomic</code> in
<code>$arg</code> are cast to <code>xs:double</code>. The items in
the resulting sequence may be reordered in an arbitrary order. The
resulting sequence is referred to below as the converted
sequence.</p>
<p>If the converted sequence is empty, then the single-argument
form of the function returns the <code>xs:integer</code> value
<code>0</code>; the two-argument form returns the value of the
argument <code>$zero</code>.</p>
<p>If the converted sequence contains the value <code>NaN</code>,
<code>NaN</code> is returned.</p>
<p>All items in <code>$arg</code> must be numeric or derived from a
single base type. In addition, the type must support addition.
Duration values must either all be
<code>xs:yearMonthDuration</code> values or must all be
<code>xs:dayTimeDuration</code> values. For numeric values, the
numeric promotion rules defined in <a href="#op.numeric"><b>6.2
Operators on Numeric Values</b></a> are used to promote all values
to a single common type. The sum of a sequence of integers will
therefore be an integer, while the sum of a numeric sequence that
includes at least one xs:double will be an xs:double.</p>
<p>If the above conditions are not met, a type error is raised
[<a href="#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
<p>Otherwise, the result of the function, using the second
signature, is the result of the expression:</p>
<div class="exampleInner">
<pre>
if (fn:count($c) eq 0) then
$zero
else if (fn:count($c) eq 1) then
$c[1]
else
$c[1] + fn:sum(subsequence($c, 2))
</pre></div>
<p>where <code>$c</code> is the converted sequence.</p>
<p>The result of the function, using the first signature, is the
result of the expression: <code>fn:sum($arg, 0)</code>.</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum
functions</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>The second argument allows an appropriate value to be defined to
represent the sum of an empty sequence. For example, when summing a
sequence of durations it would be appropriate to return a
zero-length duration of the appropriate type. This argument is
necessary because a system that does dynamic typing cannot
distinguish "an empty sequence of integers", for example, from "an
empty sequence of durations".</p>
<p>If the converted sequence contains exactly one value then that
value is returned.</p>
</div>
<div class="div4">
<h5><a name="func-sum-examples" id="func-sum-examples"></a>15.4.5.1
Examples</h5>
<p>Assume:</p>
<div class="exampleInner">
<pre>
$d1 = xs:yearMonthDuration("P20Y")
$d2 = xs:yearMonthDuration("P10M")
$seq1 = ($d1, $d2)
$seq3 = (3, 4, 5)
</pre></div>
<ul>
<li>
<p><code>fn:sum(($d1, $d2))</code> returns an
<code>xs:yearMonthDuration</code> with a value of <code>250</code>
months.</p>
</li>
<li>
<p><code>fn:sum($seq1[. &lt; xs:yearMonthDuration('P3M')],
xs:yearMonthDuration('P0M'))</code> returns an
<code>xs:yearMonthDuration</code> with a value of <code>0</code>
months.</p>
</li>
<li>
<p><code>fn:sum($seq3)</code> returns <code>12</code>.</p>
</li>
<li>
<p><code>fn:sum(())</code> returns <code>0</code>.</p>
</li>
<li>
<p><code>fn:sum((),())</code> returns <code>()</code>.</p>
</li>
<li>
<p><code>fn:sum((1 to 100)[.&lt;0], 0)</code> returns
<code>0</code>.</p>
</li>
<li>
<p><code>fn:sum(($d1, 9E1))</code> raises an error [<a href=
"#ERRFORG0006" title="err:FORG0006">err:FORG0006</a>].</p>
</li>
</ul>
</div>
</div>
</div>
<div class="div2">
<h3><a name="fns-that-generate-sequences" id=
"fns-that-generate-sequences"></a>15.5 Functions and Operators that
Generate Sequences</h3>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-to"><code>op:to</code></a></td>
<td>Returns the sequence containing every <code>xs:integer</code>
between the values of the operands.</td>
</tr>
<tr>
<td><a href="#func-id"><code>fn:id</code></a></td>
<td>Returns the sequence of element nodes having an ID value
matching the one or more of the supplied IDREF values.</td>
</tr>
<tr>
<td><a href="#func-idref"><code>fn:idref</code></a></td>
<td>Returns the sequence of element or attribute nodes with an
IDREF value matching one or more of the supplied ID values.</td>
</tr>
<tr>
<td><a href="#func-doc"><code>fn:doc</code></a></td>
<td>Returns a document node retrieved using the specified URI.</td>
</tr>
<tr>
<td><a href=
"#func-doc-available"><code>fn:doc-available</code></a></td>
<td>Returns <code>true</code> if a document node can be retrieved
using the specified URI.</td>
</tr>
<tr>
<td><a href="#func-collection"><code>fn:collection</code></a></td>
<td>Returns a sequence of nodes retrieved using the specified URI
or the nodes in the default collection.</td>
</tr>
</tbody>
</table>
<div class="div3">
<h4><a name="func-to" id="func-to"></a>15.5.1 op:to</h4>
<div class="exampleInner">
<div class="proto"><code class="function">op:to</code>(<code class=
"arg">$firstval</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:integer</code>,
<code class="arg">$lastval</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:integer</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer*</code></div>
</div>
<p>Summary: Returns the sequence containing every
<code>xs:integer</code> whose value is between the value of
<code>$firstval</code> (inclusive) and the value of
<code>$lastval</code> (inclusive), in monotonic order. If the value
of the first operand is greater than the value of the second, the
empty sequence is returned. If the values of the two operands are
equal, a sequence containing a single <code>xs:integer</code> equal
to the value is returned.</p>
<p>This function backs up the "to" operator.</p>
<div class="div4">
<h5><a name="func-to-examples" id="func-to-examples"></a>15.5.1.1
Examples</h5>
<ul>
<li>
<p><code>1 to 3</code> returns <code>(1, 2, 3)</code></p>
</li>
<li>
<p><code>3 to 1</code> returns <code>()</code></p>
</li>
<li>
<p><code>5 to 5</code> returns <code>5</code></p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="func-id" id="func-id"></a>15.5.2 fn:id</h4>
<div class="exampleInner">
<div class="proto"><code class="function">fn:id</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">element()*</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class="function">fn:id</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string*</code>, <code class=
"arg">$node</code><code class="as">&#160;as&#160;</code><code class="type">
node()</code>)<code class="as">&#160;as&#160;</code><code class=
"return-type">element()*</code></div>
</div>
<p>Summary: Returns the sequence of element nodes that have an
<code>ID</code> value matching the value of one or more of the
<code>IDREF</code> values supplied in <code>$arg</code> .</p>
<p>The function returns a sequence, in document order with
duplicates eliminated, containing every element node <code>E</code>
that satisfies all the following conditions:</p>
<ol class="enumar">
<li>
<p><code>E</code> is in the target document. The target document is
the document containing <code>$node</code>, or the document
containing the context item (<code>.</code>) if the second argument
is omitted. The behavior of the function if <code>$node</code> is
omitted is exactly the same as if the context item had been passed
as <code>$node</code>. If <code>$node</code>, or the context item
if the second argument is omitted, is a node in a tree whose root
is not a document node [<a href="#ERRFODC0001" title=
"err:FODC0001">err:FODC0001</a>] is raised. If the second argument
is the context item, or is omitted, the following errors may be
raised: if there is no context item, [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>; if
the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
</li>
<li>
<p><code>E</code> has an <code>ID</code> value equal to one of the
candidate <code>IDREF</code> values, where:</p>
<ul>
<li>
<p>An element has an <code>ID</code> value equal to <code>V</code>
if either or both of the following conditions are true:</p>
<ul>
<li>
<p>The <code>is-id</code> property (See <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-is-id">Section 5.5 is-id
Accessor</a><sup><small>DM</small></sup>.) of the element node is
true, and the typed value of the element node is equal to V under
the rules of the <code>eq</code> operator using the Unicode code
point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).</p>
</li>
<li>
<p>The element has an attribute node whose <code>is-id</code>
property (See <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-is-id">Section 5.5 is-id
Accessor</a><sup><small>DM</small></sup>.) is true and whose typed
value is equal to <code>V</code> under the rules of the
<code>eq</code> operator using the Unicode code point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).</p>
</li>
</ul>
</li>
<li>
<p>Each <code>xs:string</code> in <code>$arg</code> is parsed as if
it were of type <code>IDREFS</code>, that is, each
<code>xs:string</code> in <code>$arg</code> is treated as a
whitespace-separated sequence of tokens, each acting as an
<code>IDREF</code>. These tokens are then included in the list of
candidate <code>IDREF</code>s. If any of the tokens is not a
lexically valid <code>IDREF</code> (that is, if it is not lexically
an <code>xs:NCName</code>), it is ignored. Formally, the candidate
<code>IDREF</code> values are the strings in the sequence given by
the expression:</p>
<div class="exampleInner">
<pre>
for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ')
[. castable as xs:IDREF]
</pre></div>
</li>
</ul>
</li>
<li>
<p>If several elements have the same <code>ID</code> value, then
<code>E</code> is the one that is first in document order.</p>
</li>
</ol>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>If the data model is constructed from an Infoset, an attribute
will have the <code>is-id</code> property if the corresponding
attribute in the Infoset had an attribute type of <code>ID</code>:
typically this means the attribute was declared as an
<code>ID</code> in a DTD.</p>
<p>If the data model is constructed from a PSVI, an element or
attribute will have the <code>is-id</code> property if its
schema-defined type is <code>xs:ID</code> or a type derived by
restriction from <code>xs:ID</code>.</p>
<p>No error is raised in respect of a candidate <code>IDREF</code>
value that does not match the <code>ID</code> of any element in the
document. If no candidate <code>IDREF</code> value matches the
<code>ID</code> value of any element, the function returns the
empty sequence.</p>
<p>It is not necessary that the supplied argument should have type
<code>xs:IDREF</code> or <code>xs:IDREFS</code>, or that it should
be derived from a node with the <code>is-idrefs</code>
property.</p>
<p>An element may have more than one <code>ID</code> value. This
can occur with synthetic data models or with data models
constructed from a PSVI where the element and one of its attributes
are both typed as <code>xs:ID</code>.</p>
<p>If the source document is well-formed but not valid, it is
possible for two or more elements to have the same <code>ID</code>
value. In this situation, the function will select the first such
element.</p>
<p>It is also possible in a well-formed but invalid document to
have an element or attribute that has the is-id property but whose
value does not conform to the lexical rules for the
<code>xs:ID</code> type. Such a node will never be selected by this
function.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-idref" id="func-idref"></a>15.5.3 fn:idref</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:idref</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()*</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:idref</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string*</code>, <code class=
"arg">$node</code><code class="as">&#160;as&#160;</code><code class="type">
node()</code>)<code class="as">&#160;as&#160;</code><code class=
"return-type">node()*</code></div>
</div>
<p>Summary: Returns the sequence of element or attribute nodes with
an <code>IDREF</code> value matching the value of one or more of
the <code>ID</code> values supplied in <code>$arg</code>.</p>
<p>The function returns a sequence, in document order with
duplicates eliminated, containing every element or attribute node
<code>$N</code> that satisfies all the following conditions:</p>
<ol class="enumar">
<li>
<p><code>$N</code> is in the target document. The target document
is the document containing <code>$node</code> or the document
containing the context item (<code>.</code>) if the second argument
is omitted. The behavior of the function if <code>$node</code> is
omitted is exactly the same as if the context item had been passed
as <code>$node</code>. If <code>$node</code>, or the context item
if the second argument is omitted, is a node in a tree whose root
is not a document node [<a href="#ERRFODC0001" title=
"err:FODC0001">err:FODC0001</a>] is raised. If the second argument
is the context item, or is omitted, the following errors may be
raised: if there is no context item [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>; if
the context item is not a node [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
</li>
<li>
<p><code>$N</code> has an <code>IDREF</code> value equal to one of
the candidate <code>ID</code> values, where:</p>
<ul>
<li>
<p>A node <code>$N</code> has an <code>IDREF</code> value equal to
<code>V</code> if both of the following conditions are true:</p>
<ul>
<li>
<p>The <code>is-idrefs</code> property (See <a href=
"http://www.w3.org/TR/xpath-datamodel/#dm-is-idrefs">Section 5.6
is-idrefs Accessor</a><sup><small>DM</small></sup>.)of
<code>$N</code> is <code>true</code></p>
</li>
<li>
<p>The sequence</p>
<div class="exampleInner">
<pre>
fn:tokenize(fn:normalize-space($N),
' ')
</pre></div>
contains a string that is equal to <code>V</code> under the rules
of the <code>eq</code> operator using the Unicode code point
collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>).</li>
</ul>
</li>
<li>
<p>Each <code>xs:string</code> in <code>$arg</code> is parsed as if
it were of lexically of type <code>xs:ID</code>. These
<code>xs:string</code>s are then included in the list of candidate
<code>xs:ID</code>s. If any of the strings in <code>$arg</code> is
not a lexically valid <code>xs:ID</code> (that is, if it is not
lexically an <code>xs:NCName</code>), it is ignored. More formally,
the candidate <code>ID</code> values are the strings in the
sequence</p>
<div class="exampleInner">
<pre>
$arg[. castable as xs:NCName]
</pre></div>
</li>
</ul>
</li>
</ol>
<div class="note">
<p class="prefix"><b>Notes:</b></p>
<p>An element or attribute typically acquires the
<code>is-idrefs</code> property by being validated against the
schema type <code>xs:IDREF</code> or <code>xs:IDREFS</code>, or
(for attributes only) by being described as of type
<code>IDREF</code> or <code>IDREFS</code> in a DTD.</p>
<p>No error is raised in respect of a candidate <code>ID</code>
value that does not match the <code>IDREF</code> value of any
element or attribute in the document. If no candidate
<code>ID</code> value matches the <code>IDREF</code> value of any
element or attribute, the function returns the empty sequence.</p>
<p>It is possible for two or more nodes to have an
<code>IDREF</code> value that matches a given candidate
<code>ID</code> value. In this situation, the function will return
all such nodes. However, each matching node will be returned at
most once, regardless how many candidate <code>ID</code> values it
matches.</p>
<p>It is possible in a well-formed but invalid document to have a
node whose <code>is-idrefs</code> property is true but that does
not conform to the lexical rules for the <code>xs:IDREF</code>
type. The effect of the above rules is that ill-formed candidate
<code>ID</code> values and ill-formed <code>IDREF</code> values are
ignored.</p>
</div>
</div>
<div class="div3">
<h4><a name="func-doc" id="func-doc"></a>15.5.4 fn:doc</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:doc</code>(<code class="arg">$uri</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">document-node()?</code></div>
</div>
<p>Summary: Retrieves a document using an <code>xs:anyURI</code>,
which may include a fragment identifier, supplied as an
<code>xs:string</code>. If <code>$uri</code> is not a valid
<code>xs:anyURI</code>, an error is raised [<a href="#ERRFODC0005"
title="err:FODC0005">err:FODC0005</a>]. If it is a relative URI
Reference, it is resolved relative to the value of the base URI
property from the static context. The resulting absolute URI
Reference is promoted to an <code>xs:string</code>. If the
<b>Available documents</b> discussed in <a href=
"http://www.w3.org/TR/xpath20/#eval_context">Section 2.1.2 Dynamic
Context</a><sup><small>XP</small></sup> provides a mapping from
this string to a document node, the function returns that document
node. If the <b>Available documents</b> provides no mapping for the
string, an error is raised [<a href="#ERRFODC0005" title=
"err:FODC0005">err:FODC0005</a>].</p>
<p>If <code>$uri</code> is the empty sequence, the result is an
empty sequence.</p>
<p>By default, this function is <a title="stable" class="termref"
href="#stable"><span class="arrow">·</span>stable<span class=
"arrow">·</span></a>. Two calls on this function return the same
document node if the same URI Reference (after resolution to an
absolute URI Reference) is supplied to both calls. Thus, the
following expression (if it does not raise an error) will always be
true:</p>
<div class="exampleInner">
<pre>
doc("foo.xml") is doc("foo.xml")
</pre></div>
<p>However, for performance reasons, implementations may provide a
user option to evaluate the function without a guarantee of
stability. The manner in which any such option is provided is
implementation-defined. If the user has not selected such an
option, a call of the function must either return a stable result
or must raise an error: [<a href="#ERRFODC0003" title=
"err:FODC0003">err:FODC0003</a>].</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_doc_collection">Section
7.2.5 The fn:collection and fn:doc
functions</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>If <code>$uri</code> is read from a source document, it is
generally appropriate to resolve it relative to the base URI
property of the relevant node in the source document. This can be
achieved by calling the <a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a> function, and
passing the resulting absolute URI as an argument to the
<code>fn:doc</code> function.</p>
</div>
<p>If two calls to this function supply different absolute URI
References as arguments, the same document node may be returned if
the implementation can determine that the two arguments refer to
the same resource.</p>
<p>By defining the semantics of this function in terms of a
string-to-document-node mapping in the dynamic context, the
specification is acknowledging that the results of this function
are outside the purview of the language specification itself, and
depend entirely on the run-time environment in which the expression
is evaluated. This run-time environment includes not only an
unpredictable collection of resources ("the web"), but configurable
machinery for locating resources and turning their contents into
document nodes within the XPath data model. Both the set of
resources that are reachable, and the mechanisms by which those
resources are parsed and validated, are <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>One possible processing model for this function is as follows.
The resource identified by the URI Reference is retrieved. If the
resource cannot be retrieved, an error is raised [<a href=
"#ERRFODC0002" title="err:FODC0002">err:FODC0002</a>]. The data
resulting from the retrieval action is then parsed as an XML
document and a tree is constructed in accordance with the <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a>. If
the top-level media type is known and is "text", the content 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. If the contents cannot be parsed successfully, an
error is raised [<a href="#ERRFODC0002" title=
"err:FODC0002">err:FODC0002</a>]. Otherwise, the result of the
function is the document node at the root of the resulting tree.
This tree is then optionally validated against a schema.</p>
<p>Various aspects of this processing are <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. Implementations may provide external
configuration options that allow any aspect of the processing to be
controlled by the user. In particular:</p>
<ul>
<li>
<p>The set of URI schemes that the implementation recognizes is
implementation-defined. Implementations may allow the mapping of
URIs to resources to be configured by the user, using mechanisms
such as catalogs or user-written URI handlers.</p>
</li>
<li>
<p>The handling of non-XML media types is implementation-defined.
Implementations may allow instances of the data model to be
constructed from non-XML resources, under user control.</p>
</li>
<li>
<p>It is <a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> whether DTD validation and/or schema
validation is applied to the source document.</p>
</li>
<li>
<p>Implementations may provide user-defined error handling options
that allow processing to continue following an error in retrieving
a resource, or in parsing and validating its content. When errors
have been handled in this way, the function may return either an
empty sequence, or a fallback document provided by the error
handler.</p>
</li>
<li>
<p>Implementations may provide user options that relax the
requirement for the function to return stable results.</p>
</li>
</ul>
</div>
<div class="div3">
<h4><a name="func-doc-available" id="func-doc-available"></a>15.5.5
fn:doc-available</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:doc-available</code>(<code class=
"arg">$uri</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</div>
<p>Summary: If <a href="#func-doc"><code>fn:doc($uri)</code></a>
returns a document node, this function returns <code>true</code>.
If <code>$uri</code> is not a valid <code>xs:anyURI</code>, an
error is raised [<a href="#ERRFODC0005" title=
"err:FODC0005">err:FODC0005</a>]. Otherwise, this function returns
<code>false</code>.</p>
<p>If this function returns <code>true</code>, then calling
<a href="#func-doc"><code>fn:doc($uri)</code></a> within the same
<a title="execution scope" class="termref" href=
"#execution-scope"><span class="arrow">·</span>execution
scope<span class="arrow">·</span></a> must return a document node.
However, if non-stable processing has been selected for the
<a href="#func-doc"><code>fn:doc</code></a> function, this
guarantee is lost.</p>
</div>
<div class="div3">
<h4><a name="func-collection" id="func-collection"></a>15.5.6
fn:collection</h4>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:collection</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()*</code></div>
</div>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:collection</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()*</code></div>
</div>
<p>Summary: This function takes an <code>xs:string</code> as
argument and returns a sequence of nodes obtained by interpreting
<code>$arg</code> as an <code>xs:anyURI</code> and resolving it
according to the mapping specified in <b>Available collections</b>
described in <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>. If <b>Available
collections</b> provides a mapping from this string to a sequence
of nodes, the function returns that sequence. If <b>Available
collections</b> maps the string to an empty sequence, then the
function returns an empty sequence. If <b>Available collections</b>
provides no mapping for the string, an error is raised [<a href=
"#ERRFODC0004" title="err:FODC0004">err:FODC0004</a>]. If
<code>$arg</code> is not specified, the function returns the
sequence of the nodes in the default collection in the dynamic
context. See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>. If the value of the
default collection is undefined an error is raised [<a href=
"#ERRFODC0002" title="err:FODC0002">err:FODC0002</a>].</p>
<p>If the <code>$arg</code> is a relative <code>xs:anyURI</code>,
it is resolved against the value of the base-URI property from the
static context. If <code>$arg</code> is not a valid
<code>xs:anyURI</code>, an error is raised [<a href="#ERRFODC0004"
title="err:FODC0004">err:FODC0004</a>].</p>
<p>If <code>$arg</code> is the empty sequence, the function behaves
as if it had been called without an argument. See above.</p>
<p>By default, this function is <a title="stable" class="termref"
href="#stable"><span class="arrow">·</span>stable<span class=
"arrow">·</span></a>. This means that repeated calls on the
function with the same argument will return the same result.
However, for performance reasons, implementations may provide a
user option to evaluate the function without a guarantee of
stability. The manner in which any such option is provided is
<a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. If the user has not selected such an option,
a call to this function must either return a stable result or must
raise an error: [<a href="#ERRFODC0003" title=
"err:FODC0003">err:FODC0003</a>].</p>
<p>For detailed type semantics, see <a href=
"http://www.w3.org/TR/xquery-semantics/#sec_fn_doc_collection">Section
7.2.5 The fn:collection and fn:doc
functions</a><sup><small>FS</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>This function provides a facility for users to work with a
collection of documents which may be contained in a directory or
rows of a Relational table or other implementation-specific
construct. An implementation may also use external variables to
identify external resources, but <code>fn:collection()</code>
provides functionality not provided by external variables.
Specifying resources using URIs is useful because URIs are dynamic,
can be parameterized, and do not rely on an external
environment.</p>
</div>
</div>
</div>
</div>
<div class="div1">
<h2><a name="context" id="context"></a>16 Context Functions</h2>
<p>The following functions are defined to obtain information from
the dynamic context.</p>
<table summary="Function/operator summary" border="1">
<thead>
<tr>
<th>Function</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#func-position"><code>fn:position</code></a></td>
<td>Returns the position of the context item within the sequence of
items currently being processed.</td>
</tr>
<tr>
<td><a href="#func-last"><code>fn:last</code></a></td>
<td>Returns the number of items in the sequence of items currently
being processed.</td>
</tr>
<tr>
<td><a href=
"#func-current-dateTime"><code>fn:current-dateTime</code></a></td>
<td>Returns the current <code>xs:dateTime</code>.</td>
</tr>
<tr>
<td><a href=
"#func-current-date"><code>fn:current-date</code></a></td>
<td>Returns the current <code>xs:date</code>.</td>
</tr>
<tr>
<td><a href=
"#func-current-time"><code>fn:current-time</code></a></td>
<td>Returns the current <code>xs:time</code>.</td>
</tr>
<tr>
<td><a href=
"#func-implicit-timezone"><code>fn:implicit-timezone</code></a></td>
<td>Returns the value of the implicit timezone property from the
dynamic context.</td>
</tr>
<tr>
<td><a href=
"#func-default-collation"><code>fn:default-collation</code></a></td>
<td>Returns the value of the default collation property from the
static context.</td>
</tr>
<tr>
<td><a href=
"#func-static-base-uri"><code>fn:static-base-uri</code></a></td>
<td>Returns the value of the Base URI property from the static
context.</td>
</tr>
</tbody>
</table>
<div class="div2">
<h3><a name="func-position" id="func-position"></a>16.1
fn:position</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:position</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<p>Summary: Returns the context position from the dynamic context.
(See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) If the context item is
undefined, an error is raised: [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>.</p>
</div>
<div class="div2">
<h3><a name="func-last" id="func-last"></a>16.2 fn:last</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:last</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</div>
<p>Summary: Returns the context size from the dynamic context. (See
<a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) If the context item is
undefined, an error is raised: [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPDY0002" title=
"err:XPDY0002">err:XPDY0002</a>]<sup><small>XP</small></sup>.</p>
</div>
<div class="div2">
<h3><a name="func-current-dateTime" id=
"func-current-dateTime"></a>16.3 fn:current-dateTime</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:current-dateTime</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dateTime</code></div>
</div>
<p>Summary: Returns the current dateTime (with timezone) from the
dynamic context. (See <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.) This is an
<code>xs:dateTime</code> that is current at some time during the
evaluation of a query or transformation in which
<code>fn:current-dateTime()</code> is executed. This function is
<a title="stable" class="termref" href="#stable"><span class=
"arrow">·</span>stable<span class="arrow">·</span></a>. The precise
instant during the query or transformation represented by the value
of <code>fn:current-dateTime()</code> is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="div3">
<h4><a name="func-current-dateTime-examples" id=
"func-current-dateTime-examples"></a>16.3.1 Examples</h4>
<ul>
<li>
<p><code>fn:current-dateTime()</code> returns an
<code>xs:dateTime</code> corresponding to the current date and
time. For example, an invocation of
<code>fn:current-dateTime()</code> might return
<code>2004-05-12T18:17:15.125Z</code> corresponding to the current
time on May 12, 2004 in timezone <code>Z</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-current-date" id="func-current-date"></a>16.4
fn:current-date</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:current-date</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:date</code></div>
</div>
<p>Summary: Returns <code>xs:date(fn:current-dateTime())</code>.
This is an <code>xs:date</code> (with timezone) that is current at
some time during the evaluation of a query or transformation in
which <code>fn:current-date()</code> is executed. This function is
<a title="stable" class="termref" href="#stable"><span class=
"arrow">·</span>stable<span class="arrow">·</span></a>. The precise
instant during the query or transformation represented by the value
of <code>fn:current-date()</code> is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="div3">
<h4><a name="func-current-date-examples" id=
"func-current-date-examples"></a>16.4.1 Examples</h4>
<ul>
<li>
<p><code>fn:current-date()</code> returns an <code>xs:date</code>
corresponding to the current date and time. For example, an
invocation of <code>fn:current-date()</code> might return
<code>2004-05-12+01:00</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-current-time" id="func-current-time"></a>16.5
fn:current-time</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:current-time</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:time</code></div>
</div>
<p>Summary: Returns <code>xs:time(fn:current-dateTime())</code>.
This is an <code>xs:time</code> (with timezone) that is current at
some time during the evaluation of a query or transformation in
which <code>fn:current-time()</code> is executed. This function is
<a title="stable" class="termref" href="#stable"><span class=
"arrow">·</span>stable<span class="arrow">·</span></a>. The precise
instant during the query or transformation represented by the value
of <code>fn:current-time()</code> is <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<div class="div3">
<h4><a name="func-current-time-examples" id=
"func-current-time-examples"></a>16.5.1 Examples</h4>
<ul>
<li>
<p><code>fn:current-time()</code> returns an <code>xs:time</code>
corresponding to the current date and time. For example, an
invocation of <code>fn:current-time()</code> might return
<code>23:17:00.000-05:00</code>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="func-implicit-timezone" id=
"func-implicit-timezone"></a>16.6 fn:implicit-timezone</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:implicit-timezone</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:dayTimeDuration</code></div>
</div>
<p>Summary: Returns the value of the implicit timezone property
from the dynamic context. Components of the dynamic context are
discussed in <a href=
"http://www.w3.org/TR/xpath20/#id-xp-evaluation-context-components">
Section C.2 Dynamic Context
Components</a><sup><small>XP</small></sup>.</p>
</div>
<div class="div2">
<h3><a name="func-default-collation" id=
"func-default-collation"></a>16.7 fn:default-collation</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:default-collation</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Summary: Returns the value of the default collation property
from the static context. Components of the static context are
discussed in <a href=
"http://www.w3.org/TR/xpath20/#id-xp-static-context-components">Section
C.1 Static Context Components</a><sup><small>XP</small></sup>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The default collation property can never be undefined. If it is
not explicitly defined, a system defined default can be invoked. If
this is not provided, the Unicode code point collation
(<code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>)
is used.</p>
</div>
</div>
<div class="div2">
<h3><a name="func-static-base-uri" id=
"func-static-base-uri"></a>16.8 fn:static-base-uri</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:static-base-uri</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyURI?</code></div>
</div>
<p>Summary: Returns the value of the Base URI property from the
static context. If the Base URI property is undefined, the empty
sequence is returned. Components of the static context are
discussed in <a href=
"http://www.w3.org/TR/xpath20/#id-xp-static-context-components">Section
C.1 Static Context Components</a><sup><small>XP</small></sup> .</p>
</div>
</div>
<div class="div1">
<h2><a name="casting" id="casting"></a>17 Casting</h2>
<p>Constructor functions and cast expressions accept an expression
and return a value of a given type. They both convert a source
value, <em>SV</em>, of a source type, <em>ST</em>, to a target
value, <em>TV</em>, of the given target type, <em>TT</em>, with
identical semantics and different syntax. The name of the
constructor function is the same as the name of the built-in
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> datatype or the datatype defined in <a href=
"http://www.w3.org/TR/xpath-datamodel/#types">Section 2.6
Types</a><sup><small>DM</small></sup> of <a href=
"#xpath-datamodel">[XQuery 1.0 and XPath 2.0 Data Model]</a> (see
<a href="#constructor-functions-for-xsd-types"><b>5.1 Constructor
Functions for XML Schema Built-in Types</b></a>) or the
user-derived datatype (see <a href=
"#constructor-functions-for-user-defined-types"><b>5.4 Constructor
Functions for User-Defined Types</b></a>) that is the target for
the conversion, and the semantics are exactly the same as for a
cast expression; for example," <code>xs:date("2003-01-01")</code> "
means exactly the same as " <code>"2003-01-01"</code> cast as
<code>xs:date?</code> ".</p>
<p>The cast expression takes a type name to indicate the target
type of the conversion. See <a href=
"http://www.w3.org/TR/xpath20/#id-cast">Section 3.10.2
Cast</a><sup><small>XP</small></sup>. If the type name allows the
empty sequence and the expression to be cast is the empty sequence,
the empty sequence is returned. If the type name does not allow the
empty sequence and the expression to be cast is the empty sequence,
a type error is raised [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>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.</p>
<p>Casting from primitive type to primitive type is discussed in
<a href="#casting-from-primitive-to-primitive"><b>17.1 Casting from
primitive types to primitive types</b></a>. Casting to derived
types is discussed in <a href="#casting-to-derived-types"><b>17.2
Casting to derived types</b></a>. Casting from derived types is
discussed in <a href="#casting-from-derived-to-parent"><b>17.3
Casting from derived types to parent types</b></a>, <a href=
"#casting-within-branch"><b>17.4 Casting within a branch of the
type hierarchy</b></a> and <a href=
"#casting-across-hierarchy"><b>17.5 Casting across the type
hierarchy</b></a>.</p>
<p>When casting from <code>xs:string</code> the semantics in
<a href="#casting-from-strings"><b>17.1.1 Casting from xs:string
and xs:untypedAtomic</b></a> apply, regardless of target type.</p>
<div class="div2">
<h3><a name="casting-from-primitive-to-primitive" id=
"casting-from-primitive-to-primitive"></a>17.1 Casting from
primitive types to primitive types</h3>
<p>This section defines casting between the 19 primitive types
defined in <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a> as well as <code>xs:untypedAtomic</code>,
<code>xs:integer</code> and the two derived types of
<code>xs:duration</code> (<code>xs:yearMonthDuration</code> and
<code>xs:dayTimeDuration</code>). These four types are not
primitive types but they are treated as primitive types in this
section. 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 succeed for some values in the value space
and fails for others.</p>
<p><a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> defines <code>xs:NOTATION</code> as an abstract type.
Thus, casting to <code>xs:NOTATION</code> from any other type
including <code>xs:NOTATION</code> is not permitted and raises
[<a href="http://www.w3.org/TR/xpath20/#ERRXPST0080" title=
"err:XPST0080">err:XPST0080</a>]<sup><small>XP</small></sup>.
However, casting from one subtype of <code>xs:NOTATION</code> to
another subtype of <code>xs:NOTATION</code> is permitted.</p>
<p>Casting is not supported to or from
<code>xs:anySimpleType</code>. Thus, there is no row or column for
this type in the table below. For any node that has not been
validated or has been validated as <code>xs:anySimpleType</code>,
the typed value of the node is an atomic value of type
<code>xs:untypedAtomic</code>. There are no atomic values with the
type annotation <code>xs:anySimpleType</code> at runtime. Casting
to a type that is not atomic raises [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPST0051" title=
"err:XPST0051">err:XPST0051</a>]<sup><small>XP</small></sup>.</p>
<p>Similarly, casting is not supported to or from
<code>xs:anyAtomicType</code> and will raise error [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPST0080" title=
"err:XPST0080">err:XPST0080</a>]<sup><small>XP</small></sup>. There
are no atomic values with the type annotation
<code>xs:anyAtomicType</code> at runtime, although this can be a
statically inferred type.</p>
<p>If casting is attempted from an <em>ST</em> to a <em>TT</em> for
which casting is not supported, as defined in the table below, a
type error is raised [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup>.</p>
<p>In the following table, the columns and rows are identified by
short codes that identify simple types as follows:</p>
<blockquote>
<p>uA = xs:untypedAtomic<br />
aURI = xs:anyURI<br />
b64 = xs:base64Binary<br />
bool = xs:boolean<br />
dat = xs:date<br />
gDay = xs:gDay<br />
dbl = xs:double<br />
dec = xs:decimal<br />
dT = xs:dateTime<br />
dTD = xs:dayTimeDuration<br />
dur = xs:duration<br />
flt = xs:float<br />
hxB = xs:hexBinary<br />
gMD = xs:gMonthDay<br />
gMon = xs:gMonth<br />
int = xs:integer<br />
NOT = xs:NOTATION<br />
QN = xs:QName<br />
str = xs:string<br />
tim = xs:time<br />
gYM = xs:gYearMonth<br />
yMD = xs:yearMonthDuration<br />
gYr = xs:gYear</p>
</blockquote>
<p>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.</p>
<table class="casting" summary="Casting table" border="1"
cellpadding="1" id="casting-to-primitives-table">
<col width="5%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<col width="3%" span="1" />
<thead>
<tr>
<th><span class="cancast" title="S\T">S\T</span></th>
<th><span class="cancast" title="untypedAtomic">uA</span></th>
<th><span class="cancast" title="string">str</span></th>
<th><span class="cancast" title="float">flt</span></th>
<th><span class="cancast" title="double">dbl</span></th>
<th><span class="cancast" title="decimal">dec</span></th>
<th><span class="cancast" title="integer">int</span></th>
<th><span class="cancast" title="duration">dur</span></th>
<th><span class="cancast" title="yearMonthDuration">yMD</span></th>
<th><span class="cancast" title="dayTimeDuration">dTD</span></th>
<th><span class="cancast" title="dateTime">dT</span></th>
<th><span class="cancast" title="time">tim</span></th>
<th><span class="cancast" title="date">dat</span></th>
<th><span class="cancast" title="gYearMonth">gYM</span></th>
<th><span class="cancast" title="gYear">gYr</span></th>
<th><span class="cancast" title="gMonthDay">gMD</span></th>
<th><span class="cancast" title="gDay">gDay</span></th>
<th><span class="cancast" title="gMonth">gMon</span></th>
<th><span class="cancast" title="boolean">bool</span></th>
<th><span class="cancast" title="base64Binary">b64</span></th>
<th><span class="cancast" title="hexBinary">hxB</span></th>
<th><span class="cancast" title="anyURI">aURI</span></th>
<th><span class="cancast" title="QName">QN</span></th>
<th><span class="cancast" title="NOTATION">NOT</span></th>
</tr>
</thead>
<tbody>
<tr>
<th><span class="cancast" title="untypedAtomic">uA</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to string? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to float? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to double? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to integer? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to duration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to yearMonthDuration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to dayTimeDuration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to dateTime? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to time? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to date? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to gYearMonth? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to gYear? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to gMonthDay? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to gDay? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to gMonth? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to boolean? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to base64Binary? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast untypedAtomic to hexBinary? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to anyURI? Maybe">M</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast untypedAtomic to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="string">str</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast string to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast string to string? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to float? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to double? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to integer? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to duration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast string to yearMonthDuration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title=
"Cast string to dayTimeDuration? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to dateTime? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to time? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to date? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to gYearMonth? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to gYear? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to gMonthDay? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to gDay? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to gMonth? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to boolean? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to base64Binary? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to hexBinary? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to anyURI? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to QName? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast string to NOTATION? Maybe">M</span></td>
</tr>
<tr>
<th><span class="cancast" title="float">flt</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast float to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast float to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast float to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast float to double? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast float to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast float to integer? Maybe">M</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to gMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast float to boolean? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast float to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="double">dbl</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast double to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast double to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast double to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast double to double? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast double to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast double to integer? Maybe">M</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast double to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to gMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast double to boolean? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast double to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="decimal">dec</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast decimal to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to gMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to boolean? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast decimal to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="integer">int</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast integer to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to gMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast integer to boolean? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast integer to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="duration">dur</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast duration to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast duration to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to integer? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast duration to duration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast duration to yearMonthDuration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast duration to dayTimeDuration? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast duration to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="yearMonthDuration">yMD</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to integer? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to duration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to yearMonthDuration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to dayTimeDuration? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast yearMonthDuration to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast yearMonthDuration to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="dayTimeDuration">dTD</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to integer? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to duration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to yearMonthDuration? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to dayTimeDuration? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dayTimeDuration to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dayTimeDuration to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="dateTime">dT</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dateTime to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast dateTime to dayTimeDuration? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to dateTime? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to time? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to date? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to gYearMonth? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to gYear? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to gMonthDay? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to gDay? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to gMonth? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast dateTime to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="time">tim</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast time to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast time to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast time to time? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast time to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="date">dat</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to dayTimeDuration? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to dateTime? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to time? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to date? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to gYearMonth? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to gYear? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to gMonthDay? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to gDay? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast date to gMonth? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast date to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="gYearMonth">gYM</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast gYearMonth to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast gYearMonth to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast gYearMonth to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to date? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to gYearMonth? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYearMonth to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="gYear">gYr</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to gYearMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to gYear? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gYear to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="gMonthDay">gMD</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast gMonthDay to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast gMonthDay to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast gMonthDay to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to gYear? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to gMonthDay? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonthDay to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="gDay">gDay</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to gMonthDay? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to gDay? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gDay to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="gMonth">gMon</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast gMonth to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to gDay? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to gMonth? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast gMonth to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="boolean">bool</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast boolean to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to gMonth? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to boolean? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast boolean to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="base64Binary">b64</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast base64Binary to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast base64Binary to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast base64Binary to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to boolean? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast base64Binary to base64Binary? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to hexBinary? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast base64Binary to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="hexBinary">hxB</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title=
"Cast hexBinary to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast hexBinary to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast hexBinary to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to boolean? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to base64Binary? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to hexBinary? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast hexBinary to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="anyURI">aURI</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast anyURI to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to hexBinary? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to anyURI? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to QName? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast anyURI to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="QName">QN</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast QName to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast QName to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to anyURI? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast QName to QName? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast QName to NOTATION? No">N</span></td>
</tr>
<tr>
<th><span class="cancast" title="NOTATION">NOT</span></th>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to untypedAtomic? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to duration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast NOTATION to yearMonthDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title=
"Cast NOTATION to dayTimeDuration? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to time? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to date? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to gYearMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to gYear? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to gMonthDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to gDay? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to gMonth? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to base64Binary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to hexBinary? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to anyURI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to QName? No">N</span></td>
<td class="castM" align="center" valign="middle"><span class=
"cancast" title="Cast NOTATION to NOTATION? Maybe">M</span></td>
</tr>
</tbody>
</table>
<p>The following sub-sections define the semantics of casting from
a primitive type to a primitive type. Semantics of casting to and
from a derived type are defined in sections <a href=
"#casting-to-derived-types"><b>17.2 Casting to derived
types</b></a>, <a href="#casting-from-derived-to-parent"><b>17.3
Casting from derived types to parent types</b></a>, <a href=
"#casting-within-branch"><b>17.4 Casting within a branch of the
type hierarchy</b></a> and <a href=
"#casting-across-hierarchy"><b>17.5 Casting across the type
hierarchy</b></a>.</p>
<div class="div3">
<h4><a name="casting-from-strings" id=
"casting-from-strings"></a>17.1.1 Casting from xs:string and
xs:untypedAtomic</h4>
<p>When the supplied value is an instance of <code>xs:string</code>
or an instance of <code>xs:untypedAtomic</code>, it is treated as
being a string value and mapped to a typed value of the target type
as defined in <a href="#xmlschema-2">[XML Schema Part 2: Datatypes
Second Edition]</a>. Whitespace normalization is applied as
indicated by the whiteSpace facet for the datatype. The resulting
whitespace-normalized string must be a valid lexical form for the
datatype. The semantics of casting are identical to XML Schema
validation. For example, <code>"13" cast as xs:unsignedInt</code>
returns the <code>xs:unsignedInt</code> typed value
<code>13</code>. This could also be written
<code>xs:unsignedInt("13")</code>.</p>
<p>When casting from <code>xs:string</code> or
<code>xs:untypedAtomic</code> to a derived type where the derived
type is restricted by a pattern facet, the lexical form is first
checked against the pattern before further casting is attempted
(See <a href="#casting-to-derived-types"><b>17.2 Casting to derived
types</b></a>). If the lexical form does not conform to the
pattern, error [<a href="#ERRFORG0001" title=
"err:FORG0001">err:FORG0001</a>] is raised.</p>
<p>Consider a user-defined Schema whose target namespace is bound
to the prefix <code>mySchema</code> which defines a restriction of
<code>xs:boolean</code> called <code>trueBool</code> which allows
only the lexical forms "<code>1</code>" and "<code>0</code>".
<code>"true" cast as mySchema:trueBool</code> would fail with
[<a href="#ERRFORG0001" title="err:FORG0001">err:FORG0001</a>]. If
the Schema also defines a datatype called <code>height</code> as a
restriction of <code>xs:integer</code> with a maximum value of
<code>84</code> then <code>"100" cast as mySchema:height</code>
would also fail with [<a href="#ERRFORG0001" title=
"err:FORG0001">err:FORG0001</a>].</p>
<p>Casting is permitted from <code>xs:string</code> and
<code>xs:untypedAtomic</code> to any primitive atomic type or any
atomic type derived by restriction, except <code>xs:QName</code> or
<code>xs:NOTATION</code>. Casting to <code>xs:NOTATION</code> is
not permitted because it is an abstract type.</p>
<p>Casting is permitted from <code>xs:string</code> literals to
<code>xs:QName</code> and types derived from
<code>xs:NOTATION</code>. If the argument to such a cast is
computed dynamically, [<a href=
"http://www.w3.org/TR/xpath20/#ERRXPTY0004" title=
"err:XPTY0004">err:XPTY0004</a>]<sup><small>XP</small></sup> is
raised if the value is of any type other than <code>xs:QName</code>
or <code>xs:NOTATION</code> respectively (including the case where
it is an <code>xs:string</code>).</p>
<p>In casting to numerics, if the value is too large or too small
to be accurately represented by the implementation, it is handled
as an overflow or underflow as defined in <a href=
"#op.numeric"><b>6.2 Operators on Numeric Values</b></a>.</p>
<p>In casting to <code>xs:decimal</code> or to a type derived from
<code>xs:decimal</code>, if the value is not too large or too small
but nevertheless cannot be represented accurately with the number
of decimal digits available to the implementation, the
implementation may round to the nearest representable value or may
raise a dynamic error [<a href="#ERRFOCA0006" title=
"err:FOCA0006">err:FOCA0006</a>]. The choice of rounding algorithm
and the choice between rounding and error behavior and is
implementation-defined.</p>
<p>In casting to a date or time value, if the value is too large or
too small to be represented by the implementation, error [<a href=
"#ERRFODT0001" title="err:FODT0001">err:FODT0001</a>] is
raised.</p>
<p>In casting to a duration value, if the value is too large or too
small to be represented by the implementation, error [<a href=
"#ERRFODT0002" title="err:FODT0002">err:FODT0002</a>] is
raised.</p>
<p>For <code>xs:anyURI</code>, the extent to which an
implementation validates the lexical form of <code>xs:anyURI</code>
is <a title="implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a>.</p>
<p>If the cast fails for any other reason, error [<a href=
"#ERRFORG0001" title="err:FORG0001">err:FORG0001</a>] is
raised.</p>
</div>
<div class="div3">
<h4><a name="casting-to-string" id="casting-to-string"></a>17.1.2
Casting to xs:string and xs:untypedAtomic</h4>
<p>Casting is permitted from any primitive type to the primitive
types <code>xs:string</code> and <code>xs:untypedAtomic</code>.</p>
<p>When a value of any simple type is cast as
<code>xs:string</code>, the derivation of the
<code>xs:string</code> value <em>TV</em> depends on the <em>ST</em>
and on the <em>SV</em>, as follows.</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:string</code> or a type derived from
<code>xs:string</code>, <em>TV</em> is <em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:anyURI</code>, the type conversion is
performed without escaping any characters.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:QName</code> or
<code>xs:NOTATION</code>:</p>
<ul>
<li>
<p>if the qualified name has a prefix <em>TV</em> is
<code>(</code><a href=
"#func-concat"><code>fn:concat(fn:prefix-from-QName(</code></a><em><code>
SV</code></em><code>)</code>, <code>":"</code>, <a href=
"#func-local-name-from-QName"><code>fn:local-name-from-QName(</code></a><em>
<code>SV</code></em><code>))</code>.</p>
</li>
<li>
<p>otherwise <em>TV</em> is the local-name.</p>
</li>
</ul>
</li>
<li>
<p>If <em>ST</em> is a numeric type, the following rules apply:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:integer</code>, <em>TV</em> is the
canonical lexical representation of <em>SV</em> as defined in
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a>. There is no decimal point.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:decimal</code>, then:</p>
<ul>
<li>
<p>If <em>SV</em> is in the value space of <code>xs:integer</code>,
that is, if there are no significant digits after the decimal
point, then the value is converted from an <code>xs:decimal</code>
to an <code>xs:integer</code> and the resulting
<code>xs:integer</code> is converted to an <code>xs:string</code>
using the rule above.</p>
</li>
<li>
<p>Otherwise, the canonical lexical representation of <em>SV</em>
is returned, as defined in <a href="#xmlschema-2">[XML Schema Part
2: Datatypes Second Edition]</a>.</p>
</li>
</ul>
</li>
<li>
<p>If <em>ST</em> is <code>xs:float</code> or
<code>xs:double</code>, then:</p>
<ul>
<li>
<p><em>TV</em> will be an <code>xs:string</code> in the lexical
space of <code>xs:double</code> or <code>xs:float</code> that when
converted to an <code>xs:double</code> or <code>xs:float</code>
under the rules of <a href="#casting-from-strings"><b>17.1.1
Casting from xs:string and xs:untypedAtomic</b></a> produces a
value that is equal to <em>SV</em>, or is "NaN" if <em>SV</em> is
<code>NaN</code>. In addition, <em>TV</em> must satisfy the
constraints in the following sub-bullets.</p>
<ul>
<li>
<p>If <em>SV</em> has an absolute value that is greater than or
equal to 0.000001 (one millionth) and less than 1000000 (one
million), then the value is converted to an <code>xs:decimal</code>
and the resulting <code>xs:decimal</code> is converted to an
<code>xs:string</code> according to the rules above, as though
using an implementation of <code>xs:decimal</code> that imposes no
limits on the <code>totalDigits</code> or
<code>fractionDigits</code> facets.</p>
</li>
<li>
<p>If <em>SV</em> has the value positive or negative zero,
<em>TV</em> is "0" or "-0" respectively.</p>
</li>
<li>
<p>If <em>SV</em> is positive or negative infinity, <em>TV</em> is
the string "<code>INF</code>" or "<code>-INF</code>"
respectively.</p>
</li>
<li>
<p>In other cases, the result consists of a mantissa, which has the
lexical form of an <code>xs:decimal</code>, followed by the letter
"E", followed by an exponent which has the lexical form of an
<code>xs:integer</code>. Leading zeroes and "+" signs are
prohibited in the exponent. For the mantissa, there must be a
decimal point, and there must be exactly one digit before the
decimal point, which must be non-zero. The "+" sign is prohibited.
There must be at least one digit after the decimal point. Apart
from this mandatory digit, trailing zero digits are prohibited.</p>
</li>
</ul>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The above rules allow more than one representation of the same
value. For example, the <code>xs:float</code> value whose exact
decimal representation is 1.26743223E15 might be represented by any
of the strings "1.26743223E15", "1.26743222E15" or "1.26743224E15"
(inter alia). It is implementation-dependent which of these
representations is chosen.</p>
</div>
</li>
</ul>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, <code>xs:date</code>
or <code>xs:time</code>, <em>TV</em> is the local value. The
components of <em>TV</em> are individually cast to
<code>xs:string</code> using the functions described in <a href=
"#casting-to-datetimes">[casting-to-datetimes]</a> and the results
are concatenated together. The <code>year</code> component is cast
to <code>xs:string</code> using
<code>eg:convertYearToString</code>. The <code>month</code>,
<code>day</code>, <code>hour</code> and <code>minute</code>
components are cast to <code>xs:string</code> using
<code>eg:convertTo2CharString</code>. The <code>second</code>
component is cast to <code>xs:string</code> using
<code>eg:convertSecondsToString</code>. The timezone component, if
present, is cast to <code>xs:string</code> using
<code>eg:convertTZtoString</code>.</p>
<p>Note that the hours component of the resulting string will never
be <code>"24"</code>. Midnight is always represented as
<code>"00:00:00"</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code>, <em>TV</em> is the canonical
representation of <em>SV</em> as defined in <a href=
"#dt-yearMonthDuration"><b>10.3.1 xs:yearMonthDuration</b></a> or
<a href="#dt-dayTimeDuration"><b>10.3.2 xs:dayTimeDuration</b></a>,
respectively.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:duration</code> then let <em>SYM</em>
be <em><code>SV</code></em> <code>cast as
xs:yearMonthDuration</code>, and let <em>SDT</em> be
<em><code>SV</code></em> <code>cast as xs:dayTimeDuration</code>;
Now, let the next intermediate value, <em>TYM</em>, be
<em><code>SYM</code></em> <code>cast as</code>
<em><code>TT</code></em>, and let <em>TDT</em> be
<em><code>SDT</code></em> <code>cast as</code>
<em><code>TT</code></em>. If <em>TYM</em> is "P0M", then
<em>TV</em> is <em>TDT</em>. Otherwise, <em>TYM</em> and
<em>TDT</em> are merged according to the following rules:</p>
<ol class="enumar">
<li>
<p>If <em>TDT</em> is "PT0S", then <em>TV</em> is <em>TYM</em>.</p>
</li>
<li>
<p>Otherwise, <em>TV</em> is the concatenation of all the
characters in <em>TYM</em> and all the characters except the first
"P" and the optional negative sign in <em>TDT</em>.</p>
</li>
</ol>
</li>
<li>
<p>In all other cases, <em>TV</em> is the <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
canonical representation of <em>SV</em>. For datatypes that do not
have a canonical lexical representation defined an <a title=
"implementation dependent" class="termref" href=
"#implementation-dependent"><span class=
"arrow">·</span>implementation dependent<span class=
"arrow">·</span></a> canonical representation may be used.</p>
</li>
</ul>
<p>To cast as <code>xs:untypedAtomic</code> the value is cast as
<code>xs:string</code>, as described above, and the type annotation
changed to <code>xs:untypedAtomic</code>.</p>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>The string representations of numeric values are backwards
compatible with XPath 1.0 except for the special values positive
and negative infinity, negative zero and values outside the range
<code>1.0e-6</code> to <code>1.0e+6</code>.</p>
</div>
</div>
<div class="div3">
<h4><a name="casting-to-numerics" id=
"casting-to-numerics"></a>17.1.3 Casting to numeric types</h4>
<div class="div4">
<h5><a name="casting-to-float" id="casting-to-float"></a>17.1.3.1
Casting to xs:float</h5>
<p>When a value of any simple type is cast as
<code>xs:float</code>, the <code>xs:float</code> <em>TV</em> is
derived from the <em>ST</em> and the <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:float</code>, then <em>TV</em> is
<em>SV</em> and the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:double</code>, then <em>TV</em> is
obtained as follows:</p>
<ul>
<li>
<p>if <em>SV</em> is the <code>xs:double</code> value
<code>INF</code>, <code>-INF</code>, <code>NaN</code>, positive
zero, or negative zero, then <em>TV</em> is the
<code>xs:float</code> value <code>INF</code>, <code>-INF</code>,
<code>NaN</code>, positive zero, or negative zero respectively.</p>
</li>
<li>
<p>otherwise, <em>SV</em> can be expressed in the form <code>m ×
2^e</code> where the mantissa <code>m</code> and exponent
<code>e</code> are signed <code>xs:integer</code>s whose value
range is defined in <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a>, and the following rules apply:</p>
<ul>
<li>
<p>if <code>m</code> (the mantissa of <em>SV</em>) is outside the
permitted range for the mantissa of an <code>xs:float</code> value
<code>(-2^24-1 to +2^24-1)</code>, then it is divided by
<code>2^N</code> where <code>N</code> is the lowest positive
<code>xs:integer</code> that brings the result of the division
within the permitted range, and the exponent <code>e</code> is
increased by <code>N</code>. This is integer division (in effect,
the binary value of the mantissa is truncated on the right). Let
<code>M</code> be the mantissa and <code>E</code> the exponent
after this adjustment.</p>
</li>
<li>
<p>if <code>E</code> exceeds <code>104</code> (the maximum exponent
value in the value space of <code>xs:float</code>) then <em>TV</em>
is the <code>xs:float</code> value <code>INF</code> or
<code>-INF</code> depending on the sign of <code>M</code>.</p>
</li>
<li>
<p>if <code>E</code> is less than <code>-149</code> (the minimum
exponent value in the value space of <code>xs:float</code>) then
<em>TV</em> is the <code>xs:float</code> value positive or negative
zero depending on the sign of <code>M</code></p>
</li>
<li>
<p>otherwise, <em>TV</em> is the <code>xs:float</code> value
<code>M × 2^E</code>.</p>
</li>
</ul>
</li>
</ul>
</li>
<li>
<p>If <em>ST</em> is <code>xs:decimal</code>, or
<code>xs:integer</code>, then <em>TV</em> is <code>xs:float(</code>
<em>SV</em> <code>cast as xs:string)</code> and the conversion is
complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:boolean</code>, <em>SV</em> is
converted to <code>1.0E0</code> if <em>SV</em> is <code>true</code>
and to <code>0.0E0</code> if <em>SV</em> is <code>false</code> and
the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Implementations <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> return negative zero for <code>"-0.0E0" cast
as xs:float</code>. <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a> does not distinguish between the
values positive zero and negative zero.</p>
</div>
</div>
<div class="div4">
<h5><a name="casting-to-double" id="casting-to-double"></a>17.1.3.2
Casting to xs:double</h5>
<p>When a value of any simple type is cast as
<code>xs:double</code>, the <code>xs:double</code> value
<em>TV</em> is derived from the <em>ST</em> and the <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:double</code>, then <em>TV</em> is
<em>SV</em> and the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:float</code> or a type derived from
<code>xs:float</code>, then <em>TV</em> is obtained as follows:</p>
<ul>
<li>
<p>if <em>SV</em> is the <code>xs:float</code> value
<code>INF</code>, <code>-INF</code>, <code>NaN</code>, positive
zero, or negative zero, then <em>TV</em> is the
<code>xs:double</code> value <code>INF</code>, <code>-INF</code>,
<code>NaN</code>, positive zero, or negative zero respectively.</p>
</li>
<li>
<p>otherwise, <em>SV</em> can be expressed in the form <code>m ×
2^e</code> where the mantissa <code>m</code> and exponent
<code>e</code> are signed <code>xs:integer</code> values whose
value range is defined in <a href="#xmlschema-2">[XML Schema Part
2: Datatypes Second Edition]</a>, and <em>TV</em> is the
<code>xs:double</code> value <code>m × 2^e</code>.</p>
</li>
</ul>
</li>
<li>
<p>If <em>ST</em> is <code>xs:decimal</code> or
<code>xs:integer</code>, then <em>TV</em> is
<code>xs:double(</code> <em>SV</em> <code>cast as xs:string)</code>
and the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:boolean</code>, <em>SV</em> is
converted to <code>1.0E0</code> if <em>SV</em> is <code>true</code>
and to <code>0.0E0</code> if <em>SV</em> is <code>false</code> and
the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
<div class="note">
<p class="prefix"><b>Note:</b></p>
<p>Implementations <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> return negative zero for <code>"-0.0E0" cast
as xs:double</code>. <a href="#xmlschema-2">[XML Schema Part 2:
Datatypes Second Edition]</a> does not distinguish between the
values positive zero and negative zero.</p>
</div>
</div>
<div class="div4">
<h5><a name="casting-to-decimal" id=
"casting-to-decimal"></a>17.1.3.3 Casting to xs:decimal</h5>
<p>When a value of any simple type is cast as
<code>xs:decimal</code>, the <code>xs:decimal</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:decimal</code>,
<code>xs:integer</code> or a type derived from them, then
<em>TV</em> is <em>SV</em>, converted to an <code>xs:decimal</code>
value if need be, and the conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:float</code> or
<code>xs:double</code>, then <em>TV</em> is the
<code>xs:decimal</code> value, within the set of
<code>xs:decimal</code> values that the implementation is capable
of representing, that is numerically closest to <em>SV</em>. If two
values are equally close, then the one that is closest to zero is
chosen. If <em>SV</em> is too large to be accommodated as an
<code>xs:decimal</code>, (see <a href="#xmlschema-2">[XML Schema
Part 2: Datatypes Second Edition]</a> for <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> limits on numeric values) an error is raised
[<a href="#ERRFOCA0001" title="err:FOCA0001">err:FOCA0001</a>]. If
<em>SV</em> is one of the special <code>xs:float</code> or
<code>xs:double</code> values <code>NaN</code>, <code>INF</code>,
or <code>-INF</code>, an error is raised [<a href="#ERRFOCA0002"
title="err:FOCA0002">err:FOCA0002</a>].</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:boolean</code>, <em>SV</em> is
converted to <code>1.0</code> if <em>SV</em> is <code>1</code> or
<code>true</code> and to <code>0.0</code> if <em>SV</em> is
<code>0</code> or <code>false</code> and the conversion is
complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</div>
<div class="div4">
<h5><a name="casting-to-integer" id=
"casting-to-integer"></a>17.1.3.4 Casting to xs:integer</h5>
<p>When a value of any simple type is cast as
<code>xs:integer</code>, the <code>xs:integer</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:integer</code>, or a type derived
from <code>xs:integer</code>, then <em>TV</em> is <em>SV</em>,
converted to an <code>xs:integer</code> value if need be, and the
conversion is complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:decimal</code>, <code>xs:float</code>
or <code>xs:double</code>, then <em>TV</em> is <em>SV</em> with the
fractional part discarded and the value converted to
<code>xs:integer</code>. Thus, casting <code>3.1456</code> returns
<code>3</code> and <code>-17.89</code> returns <code>-17</code>.
Casting <code>3.124E1</code> returns <code>31</code>. If
<em>SV</em> is too large to be accommodated as an integer, (see
<a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> for <a title="implementation-defined" class="termref"
href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> limits on numeric values) an error is raised
[<a href="#ERRFOCA0003" title="err:FOCA0003">err:FOCA0003</a>]. If
<em>SV</em> is one of the special <code>xs:float</code> or
<code>xs:double</code> values <code>NaN</code>, <code>INF</code>,
or <code>-INF</code>, an error is raised [<a href="#ERRFOCA0002"
title="err:FOCA0002">err:FOCA0002</a>].</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:boolean</code>, <em>SV</em> is
converted to <code>1</code> if <em>SV</em> is <code>1</code> or
<code>true</code> and to <code>0</code> if <em>SV</em> is
<code>0</code> or <code>false</code> and the conversion is
complete.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</div>
</div>
<div class="div3">
<h4><a name="casting-to-durations" id=
"casting-to-durations"></a>17.1.4 Casting to duration types</h4>
<p>When a value of type <code>xs:untypedAtomic</code>,
<code>xs:string</code>, a type derived from <code>xs:string</code>,
<code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code> is cast as
<code>xs:duration</code>, <code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code>, <em>TV</em> is derived from
<em>ST</em> and <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is the same as <em>TT</em>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:duration</code>, or a type derived
from <code>xs:duration</code>, but not
<code>xs:dayTimeDuration</code> or a type derived from
<code>xs:dayTimeDuration</code>, and <em>TT</em> is
<code>xs:yearMonthDuration</code>, then <em>TV</em> is derived from
<em>SV</em> by removing the day, hour, minute and second components
from <em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:duration</code>, or a type derived
from <code>duration</code>, but not
<code>xs:yearMonthDuration</code> or a type derived from
<code>xs:yearMonthDuration</code>, and <em>TT</em> is
<code>xs:dayTimeDuration</code>, then <em>TV</em> is derived from
<em>SV</em> by removing the year and month components from
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code>, and <em>TT</em> is
<code>xs:duration</code>, then <em>TV</em> is derived from
<em>SV</em> as discussed in <a href=
"#casting-from-derived-to-parent"><b>17.3 Casting from derived
types to parent types</b></a>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:yearMonthDuration</code> and
<em>TT</em> is <code>xs:dayTimeDuration</code>, the cast is
permitted and returns a <code>xs:dayTimeDuration</code> with value
0.0 seconds.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dayTimeDuration</code> and
<em>TT</em> is <code>xs:yearMonthDuration</code>, the cast is
permitted and returns a <code>xs:yearMonthDuration</code> with
value 0 months.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
<p>Note that casting from <code>xs:duration</code> to
<code>xs:yearMonthDuration</code> or
<code>xs:dayTimeDuration</code> loses information. To avoid this,
users can cast the <code>xs:duration</code> value to both an
<code>xs:yearMonthDuration</code> and an
<code>xs:dayTimeDuration</code> and work with both values.</p>
</div>
<div class="div3">
<h4><a name="casting-to-datetimes" id=
"casting-to-datetimes"></a>17.1.5 Casting to date and time
types</h4>
<p>In several situations, casting to date and time types requires
the extraction of a component from <em>SV</em> or from the result
of <a href=
"#func-current-dateTime"><code>fn:current-dateTime</code></a> and
converting it to an <code>xs:string</code>. These conversions must
follow certain rules. For example, converting an
<code>xs:integer</code> year value requires converting to an
<code>xs:string</code> with four or more characters, preceded by a
minus sign if the value is negative.</p>
<p>This document defines four functions to perform these
conversions. These functions are for illustrative purposes only and
make no recommendations as to style or efficiency. References to
these functions from the following text are not normative.</p>
<p>The arguments to these functions come from functions defined in
this document. Thus, the functions below assume that they are
correct and do no range checking on them.</p>
<div class="exampleInner">
<pre>
declare function eg:convertYearToString($year as xs:integer) as xs:string
{
let $plusMinus := if ($year &gt;= 0) then "" else "-"
let $yearString := fn:abs($year) cast as xs:string
let $length := fn:length($yearString)
return
if ($length = 1) then fn:concat($plusMinus, "000", $yearString)
else
if ($length = 2) then fn:concat($plusMinus, "00", $yearString)
else
if ($length = 3) then fn:concat($plusMinus, "0", $yearString)
else fn:concat($plusMinus, $yearString)
}
</pre></div>
<div class="exampleInner">
<pre>
declare function eg:convertTo2CharString($value as xs:integer) as xs:string
{
let $string := $value cast as xs:string
return
if (fn:length($string) = 1) then fn:concat("0", $string)
else $string
}
</pre></div>
<div class="exampleInner">
<pre>
declare function eg:convertSecondsToString($seconds as xs:decimal) as xs:string
{
let $string := $seconds cast as xs:string
let $intLength := fn:length(($seconds cast as xs:integer) cast as xs:string)
return
if ($intLength = 1) then fn:concat("0", $string)
else $string
}
</pre></div>
<div class="exampleInner">
<pre>
declare function eg:convertTZtoString($tz as xs:dayTimeDuration?) as xs:string
{
if (empty($tz)) then ""
else
let $tzh := fn:hours-from-dayTimeDuration($tz)
let $tzm := fn:minutes-from-dayTimeDuration($tz)
let $plusMinus := if ($tzh &gt;= 0) then "+" else "-"
let $tzhString := eg:convertTo2CharString(fn:abs($tzh))
let $tzmString := eg:convertTo2CharString(fn:abs($tzm))
return fn:concat($plusMinus, $tzhString, ":", $tzmString)
}
</pre></div>
<p>Conversion from primitive types to date and time types follows
the rules below.</p>
<ol class="enumar">
<li>
<p>When a value of any primitive type is cast as
<code>xs:dateTime</code>, the <code>xs:dateTime</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then let <em>SYR</em> be
<code>eg:convertYearToString( fn:year-from-date(</code> <em>SV</em>
<code>))</code>, let <em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-date(</code> <em>SV</em> <code>))</code>, let
<em>SDA</em> be <code>eg:convertTo2CharString(
fn:day-from-date(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-date(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:dateTime( fn:concat(</code> <em>SYR</em>
<code>, '-',</code> <em>SMO</em> <code>, '-',</code> <em>SDA</em>
<code>, 'T00:00:00 '</code>, <em>STZ</em> <code>) )</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:time</code>, the <code>xs:time</code> value <em>TV</em> is
derived from <em>ST</em> and <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:time</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then <em>TV</em> is
<code>xs:time( fn:concat( eg:convertTo2CharString(
fn:hours-from-dateTime(</code> <em>SV</em> <code>)), ':',
eg:convertTo2CharString( fn:minutes-from-dateTime(</code>
<em>SV</em> <code>)), ':', eg:convertSecondsToString(
fn:seconds-from-dateTime(</code> <em>SV</em> <code>)),
eg:convertTZtoString( fn:timezone-from-dateTime(</code> <em>SV</em>
<code>)) ))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:date</code>, the <code>xs:date</code> value <em>TV</em> is
derived from <em>ST</em> and <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then let
<em>SYR</em> be <code>eg:convertYearToString(
fn:year-from-dateTime(</code> <em>SV</em> <code>))</code>, let
<em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-dateTime(</code> <em>SV</em> <code>))</code>, let
<em>SDA</em> be <code>eg:convertTo2CharString(
fn:day-from-dateTime(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be
<code>eg:convertTZtoString(fn:timezone-from-dateTime(</code>
<em>SV</em> <code>))</code>; <em>TV</em> is <code>xs:date(
fn:concat(</code> <em>SYR</em> <code>, '-',</code> <em>SMO</em>
<code>, '-',</code> <em>SDA</em>, <em>STZ</em> <code>)
)</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:gYearMonth</code>, the <code>xs:gYearMonth</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:gYearMonth</code>, then <em>TV</em>
is <em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then let
<em>SYR</em> be <code>eg:convertYearToString(
fn:year-from-dateTime(</code> <em>SV</em> <code>))</code>, let
<em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-dateTime(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-dateTime(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gYearMonth( fn:concat(</code> <em>SYR</em>
<code>, '-',</code> <em>SMO</em>, <em>STZ</em> <code>)
)</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then let <em>SYR</em> be
<code>eg:convertYearToString( fn:year-from-date(</code> <em>SV</em>
<code>))</code>, let <em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-date(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-date(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gYearMonth( fn:concat(</code> <em>SYR</em>
<code>, '-',</code> <em>SMO</em>, <em>STZ</em> <code>)
)</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:gYear</code>, the <code>xs:gYear</code> value <em>TV</em>
is derived from <em>ST</em> and <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:gYear</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, let <em>SYR</em> be
<code>eg:convertYearToString( fn:year-from-dateTime(</code>
<em>SV</em> <code>))</code> and let <em>STZ</em> be
<code>eg:convertTZtoString( fn:timezone-from-dateTime(</code>
<em>SV</em> <code>))</code>; <em>TV</em> is
<code>xs:gYear(fn:concat(</code> <em>SYR</em>, <em>STZ</em>
<code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, let <em>SYR</em> be
<code>eg:convertYearToString( fn:year-from-date(</code> <em>SV</em>
<code>))</code>; and let <em>STZ</em> be
<code>eg:convertTZtoString( fn:timezone-from-date(</code>
<em>SV</em> <code>))</code>; <em>TV</em> is
<code>xs:gYear(fn:concat(</code> <em>SYR</em>, <em>STZ</em>
<code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:gMonthDay</code>, the <code>xs:gMonthDay</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:gMonthDay</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then let
<em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-dateTime(</code> <em>SV</em> <code>))</code>, let
<em>SDA</em> be <code>eg:convertTo2CharString(
fn:day-from-dateTime(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-dateTime(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gYearMonth( fn:concat(</code>
<code>'--',</code> <em>SMO</em> <code>'-',</code> <em>SDA</em>,
<em>STZ</em> <code>) )</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then let <em>SMO</em> be
<code>eg:convertTo2CharString( fn:month-from-date(</code>
<em>SV</em> <code>))</code>, let <em>SDA</em> be
<code>eg:convertTo2CharString( fn:day-from-date(</code> <em>SV</em>
<code>))</code> and let <em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-date(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gYearMonth( fn:concat(</code>
<code>'--',</code> <em>SMO</em> <code>, '-',</code> <em>SDA</em>,
<em>STZ</em> <code>) )</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:gDay</code>, the <code>xs:gDay</code> value <em>TV</em> is
derived from <em>ST</em> and <em>SV</em> as follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:gDay</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then let
<em>SDA</em> be <code>eg:convertTo2CharString(
fn:day-from-dateTime(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-dateTime(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gDay( fn:concat( '---'</code>,
<em>SDA</em>, <em>STZ</em> <code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then let <em>SDA</em> be
<code>eg:convertTo2CharString( fn:day-from-date(</code> <em>SV</em>
<code>))</code> and let <em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-date(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gDay( fn:concat( '---'</code>,
<em>SDA</em>, <em>STZ</em> <code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
<li>
<p>When a value of any primitive type is cast as
<code>xs:gMonth</code>, the <code>xs:gMonth</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:gMonth</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:dateTime</code>, then let
<em>SMO</em> be <code>eg:convertTo2CharString(
fn:month-from-dateTime(</code> <em>SV</em> <code>))</code> and let
<em>STZ</em> be <code>eg:convertTZtoString(
fn:timezone-from-dateTime(</code> <em>SV</em> <code>))</code>;
<em>TV</em> is <code>xs:gMonth( fn:concat( '--'</code> ,
<em>SMO</em>, <em>STZ</em> <code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:date</code>, then let <em>SMO</em> be
<code>eg:convertTo2CharString( fn:month-from-date(</code>
<em>SV</em> <code>))</code> and let <em>STZ</em> be
<code>eg:convertTZtoString( fn:timezone-from-date(</code>
<em>SV</em> <code>))</code>; <em>TV</em> is <code>xs:gMonth(
fn:concat( '--'</code>, <em>SMO</em>, <em>STZ</em>
<code>))</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</li>
</ol>
</div>
<div class="div3">
<h4><a name="casting-boolean" id="casting-boolean"></a>17.1.6
Casting to xs:boolean</h4>
<p>When a value of any primitive type is cast as
<code>xs:boolean</code>, the <code>xs:boolean</code> value
<em>TV</em> is derived from <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:boolean</code>, then <em>TV</em> is
<em>SV</em>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> and <em>SV</em>
is <code>0</code>, <code>+0</code>, <code>-0</code>,
<code>0.0</code>, <code>0.0E0</code> or <code>NaN</code>, then
<em>TV</em> is <code>false</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:float</code>, <code>xs:double</code>,
<code>xs:decimal</code> or <code>xs:integer</code> and <em>SV</em>
is not one of the above values, then <em>TV</em> is
<code>true</code>.</p>
</li>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code>, see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</div>
<div class="div3">
<h4><a name="casting-to-binary" id="casting-to-binary"></a>17.1.7
Casting to xs:base64Binary and xs:hexBinary</h4>
<p>Values of type <code>xs:base64Binary</code> can be cast as
<code>xs:hexBinary</code> and vice versa, since the two types have
the same value space. Casting to <code>xs:base64Binary</code> and
<code>xs:hexBinary</code> is also supported from the same type and
from <code>xs:untypedAtomic</code>, <code>xs:string</code> and
subtypes of <code>xs:string</code> using <a href=
"#xmlschema-2">[XML Schema Part 2: Datatypes Second Edition]</a>
semantics.</p>
</div>
<div class="div3">
<h4><a name="casting-to-anyuri" id="casting-to-anyuri"></a>17.1.8
Casting to xs:anyURI</h4>
<p>Casting to <code>xs:anyURI</code> is supported only from the
same type, <code>xs:untypedAtomic</code> or
<code>xs:string</code>.</p>
<p>When a value of any primitive type is cast as
<code>xs:anyURI</code>, the <code>xs:anyURI</code> value
<em>TV</em> is derived from the <em>ST</em> and <em>SV</em> as
follows:</p>
<ul>
<li>
<p>If <em>ST</em> is <code>xs:untypedAtomic</code> or
<code>xs:string</code> see <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
</ul>
</div>
</div>
<div class="div2">
<h3><a name="casting-to-derived-types" id=
"casting-to-derived-types"></a>17.2 Casting to derived types</h3>
<p>Casting a value to a derived type can be separated into four
cases. Note that <code>xs:untypedAtomic</code>,
<code>xs:integer</code> and the two derived types of
<code>xs:duration</code>:<code>xs:yearMonthDuration</code> and
<code>xs:dayTimeDuration</code> are treated as primitive types.</p>
<ol class="enumar">
<li>
<p>When <em>SV</em> is an instance of a type that is derived by
restriction from <em>TT</em>. This is described in section <a href=
"#casting-from-derived-to-parent"><b>17.3 Casting from derived
types to parent types</b></a>.</p>
</li>
<li>
<p>When <em>SV</em> is an instance of a type derived by restriction
from the same primitive type as <em>TT</em>. This is described in
<a href="#casting-within-branch"><b>17.4 Casting within a branch of
the type hierarchy</b></a>.</p>
</li>
<li>
<p>When the derived type is derived, directly or indirectly, from a
different primitive type than the primitive type of <em>ST</em>.
This is described in <a href="#casting-across-hierarchy"><b>17.5
Casting across the type hierarchy</b></a>.</p>
</li>
<li>
<p>When <em>SV</em> is an instance of the <em>TT</em>, the cast
always succeeds (Identity cast).</p>
</li>
</ol>
</div>
<div class="div2">
<h3><a name="casting-from-derived-to-parent" id=
"casting-from-derived-to-parent"></a>17.3 Casting from derived
types to parent types</h3>
<p>Except in the case of <code>xs:NOTATION</code>, it is always
possible to cast a value of any atomic type to an atomic type from
which it is derived, directly or indirectly, by restriction. For
example, it is possible to cast an <code>xs:unsignedShort</code> to
an <code>xs:unsignedInt</code>, an <code>xs:integer</code>, or an
<code>xs:decimal</code>. 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 the same value as the
original, but will have a new type annotation.</p>
</div>
<div class="div2">
<h3><a name="casting-within-branch" id=
"casting-within-branch"></a>17.4 Casting within a branch of the
type hierarchy</h3>
<p>It is possible to cast an <em>SV</em> to a <em>TT</em> if the
type of the <em>SV</em> and the <em>TT</em> 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. This includes the case
where the target type is derived from the type of the supplied
value, as well as the case where the type of the supplied value is
derived from the target type. For example, an instance of
<code>xs:byte</code> can be cast as <code>xs:unsignedShort</code>,
provided the value is not negative.</p>
<p>If the value does not conform to the facets defined for the
target type, then an error is raised [<a href="#ERRFORG0001" title=
"err:FORG0001">err:FORG0001</a>]. See <a href="#xmlschema-2">[XML
Schema Part 2: Datatypes Second Edition]</a>. 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 for the source type (or the
result of casting the value to an <code>xs:string</code>, in the
case of types that have no canonical lexical representation defined
for them).</p>
<p>Note that this will cause casts to fail if the pattern excludes
the canonical lexical representation of the source type. For
example, if the type <code>my:distance</code> is defined as a
restriction of <code>xs:decimal</code> with a pattern that requires
two digits after the decimal point, casting of an
<code>xs:integer</code> to <code>my:distance</code> will always
fail, because the canonical representation of an
<code>xs:integer</code> does not conform to this pattern.</p>
<p>In some cases, casting from a parent type to a derived type
requires special rules. See <a href=
"#casting-to-durations"><b>17.1.4 Casting to duration types</b></a>
for rules regarding casting to <code>xs:yearMonthDuration</code>
and <code>xs:dayTimeDuration</code>. See <a href=
"#casting-to-ENTITY"><b>17.4.1 Casting to xs:ENTITY</b></a>, below,
for casting to <code>xs:ENTITY</code> and types derived from
it.</p>
<div class="div3">
<h4><a name="casting-to-ENTITY" id="casting-to-ENTITY"></a>17.4.1
Casting to xs:ENTITY</h4>
<p><a href="#xmlschema-2">[XML Schema Part 2: Datatypes Second
Edition]</a> says that "The value space of ENTITY is the set of all
strings that match the NCName production ... and have been declared
as an unparsed entity in a document type definition." However,
<a href="#xslt20">[XSL Transformations (XSLT) Version 2.0]</a> and
<a href="#xquery">[XQuery 1.0: An XML Query Language]</a> do not
check that constructed values of type <code>xs:ENTITY</code> match
declared unparsed entities. Thus, this rule is relaxed in this
specification and, in casting to <code>xs:ENTITY</code> and types
derived from it, no check is made that the values correspond to
declared unparsed entities.</p>
</div>
</div>
<div class="div2">
<h3><a name="casting-across-hierarchy" id=
"casting-across-hierarchy"></a>17.5 Casting across the type
hierarchy</h3>
<p>When the <em>ST</em> and the <em>TT</em> are derived, directly
or indirectly, from different primitive types, this is called
casting across the type hierarchy. Casting across the type
hierarchy is logically equivalent to three separate steps performed
in order. Errors can occur in either of the latter two steps.</p>
<ol class="enumar">
<li>
<p>Cast the <em>SV</em>, up the hierarchy, to the primitive type of
the source, as described in <a href=
"#casting-from-derived-to-parent"><b>17.3 Casting from derived
types to parent types</b></a>.</p>
<ol class="enumla">
<li>
<p>If <em>SV</em> is an instance of <code>xs:string</code> or
<code>xs:untypedAtomic</code>, check its value against the pattern
facet of <em>TT</em>, and raise an error [<a href="#ERRFORG0001"
title="err:FORG0001">err:FORG0001</a>] if the check fails.</p>
</li>
</ol>
</li>
<li>
<p>Cast the value to the primitive type of <em>TT</em>, as
described in <a href="#casting-from-primitive-to-primitive"><b>17.1
Casting from primitive types to primitive types</b></a>.</p>
<ul>
<li>
<p>If <em>TT</em> is derived from <code>xs:NOTATION</code>, assume
for the purposes of this rule that casting to
<code>xs:NOTATION</code> succeeds.</p>
</li>
</ul>
</li>
<li>
<p>Cast the value down to the <em>TT</em>, as described in <a href=
"#casting-within-branch"><b>17.4 Casting within a branch of the
type hierarchy</b></a></p>
</li>
</ol>
</div>
</div>
</div>
<div class="back">
<div class="div1">
<h2><a name="biblio" id="biblio"></a>A References</h2>
<div class="div2">
<h3><a name="normative-biblio" id="normative-biblio"></a>A.1
Normative References</h3>
<dl>
<dt class="label"><span><a name="ieee754" id="ieee754"></a>IEEE
754-1985</span></dt>
<dd>
<div>IEEE. <em>IEEE Standard for Binary Floating-Point
Arithmetic.</em></div>
</dd>
<dt class="label"><span><a name="LDML" id="LDML"></a>Locale Data
Markup Language</span></dt>
<dd>
<div>Unicode Technical Standard #35, Locale Data Markup Language.
Available at: <a href=
"http://www.unicode.org/unicode/reports/tr35/">http://www.unicode.org/unicode/reports/tr35/</a></div>
</dd>
<dt class="label"><span><a name="rfc2396" id="rfc2396"></a>RFC
2396</span></dt>
<dd>
<div>IETF. <em>RFC 2396: Uniform Resource Identifiers (URI):
Generic Syntax.</em> Available at: <a href=
"http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</a></div>
</dd>
<dt class="label"><span><a name="rfc3986" id="rfc3986"></a>RFC
3986</span></dt>
<dd>
<div>IETF. <em>RFC 3986: Uniform Resource Identifiers (URI):
Generic Syntax.</em> Available at: <a href=
"http://www.ietf.org/rfc/rfc3986.txt">http://www.ietf.org/rfc/rfc3986.txt</a></div>
</dd>
<dt class="label"><span><a name="rfc3987" id="rfc3987"></a>RFC
3987</span></dt>
<dd>
<div>IETF. <em>RFC 3987: Internationalized Resource Identifiers
(IRIs).</em> Available at: <a href=
"http://www.ietf.org/rfc/rfc3987.txt">http://www.ietf.org/rfc/rfc3987.txt</a></div>
</dd>
<dt class="label"><span><a name="charmod" id=
"charmod"></a>Character Model for the World Wide Web 1.0:
Fundamentals</span></dt>
<dd>
<div>Character Model for the World Wide Web 1.0: Fundamentals.
Available at: <a href=
"http://www.w3.org/TR/2005/REC-charmod-20050215/">http://www.w3.org/TR/2005/REC-charmod-20050215/</a></div>
</dd>
<dt class="label"><span><a name="charmod-normalization" id=
"charmod-normalization"></a>Character Model for the World Wide Web
1.0: Normalization</span></dt>
<dd>
<div>Character Model for the World Wide Web 1.0: Normalization,
Last Call Working Draft. Available at: <a href=
"http://www.w3.org/TR/2004/WD-charmod-norm-20040225/">http://www.w3.org/TR/2004/WD-charmod-norm-20040225/</a></div>
</dd>
<dt class="label"><span><a name="ISO10967" id="ISO10967"></a>ISO
10967</span></dt>
<dd>
<div>ISO (International Organization for Standardization).
<em>ISO/IEC 10967-1:1994, Information technology—Language
Independent Arithmetic—Part 1: Integer and floating point
arithmetic</em> [Geneva]: International Organization for
Standardization, 1994. Available from: <a href=
"http://www.iso.ch/">http://www.iso.ch/</a></div>
</dd>
<dt class="label"><span><a name="Unicode4" id="Unicode4"></a>The
Unicode Standard</span></dt>
<dd>
<div>The Unicode Consortium, Reading, MA, Addison-Wesley, 2003.
<em>The Unicode Standard</em> as updated from time to time by the
publication of new versions. See <a href=
"http://www.unicode.org/unicode/standard/versions">http://www.unicode.org/unicode/standard/versions</a>
for the latest version and additional information on versions of
the standard and of the Unicode Character Database. The version of
Unicode to be used is <a title="implementation-defined" class=
"termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>, but implementations are recommended to use
the latest Unicode version; currently, Version 4.0.00,
Addison-Wesley, 2003 ISBN 0-321-18578-1</div>
</dd>
<dt class="label"><span><a name="Unicode-Collations" id=
"Unicode-Collations"></a>Unicode Collation Algorithm</span></dt>
<dd>
<div>Unicode Technical Standard #10, Unicode Collation Algorithm.
Available at: <a href=
"http://www.unicode.org/unicode/reports/tr10/">http://www.unicode.org/unicode/reports/tr10/</a></div>
</dd>
<dt class="label"><span><a name="Unicode-Regex" id=
"Unicode-Regex"></a>Unicode Regular Expressions</span></dt>
<dd>
<div>Unicode Technical Standard #18, Unicode Regular Expressions.
Available at: <a href=
"http://www.unicode.org/unicode/reports/tr18/">http://www.unicode.org/unicode/reports/tr18/</a></div>
</dd>
<dt class="label"><span><a name="REC-xml" id=
"REC-xml"></a>Extensible Markup Language (XML) 1.0 Recommendation
(Third Edition)</span></dt>
<dd>
<div>World Wide Web Consortium. <em>Extensible Markup Language
(XML) 1.0 Third Edition.</em> Available at: <a href=
"http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a></div>
</dd>
<dt class="label"><span><a name="xml11" id="xml11"></a>Extensible
Markup Language (XML) 1.1 Recommendation</span></dt>
<dd>
<div>World Wide Web Consortium. <em>Extensible Markup Language
(XML) 1.1.</em> Available at: <a href=
"http://www.w3.org/TR/2004/REC-xml11-20040204/">http://www.w3.org/TR/2004/REC-xml11-20040204/</a></div>
</dd>
<dt class="label"><span><a name="xpath20" id="xpath20"></a>XML Path
Language (XPath) 2.0</span></dt>
<dd>
<div>World Wide Web Consortium. XML Path Language (XPath) Version
2.0. Available at: <a href=
"http://www.w3.org/TR/xpath20/">http://www.w3.org/TR/xpath20/</a></div>
</dd>
<dt class="label"><span><a name="xslt20" id="xslt20"></a>XSL
Transformations (XSLT) Version 2.0</span></dt>
<dd>
<div>World Wide Web Consortium. XSL Transformations Version 2.0.
Available at: <a href=
"http://www.w3.org/TR/xslt20/">http://www.w3.org/TR/xslt20/</a></div>
</dd>
<dt class="label"><span><a name="xpath-datamodel" id=
"xpath-datamodel"></a>XQuery 1.0 and XPath 2.0 Data
Model</span></dt>
<dd>
<div>World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Data Model
(XDM). Available at: <a href=
"http://www.w3.org/TR/query-datamodel/">http://www.w3.org/TR/query-datamodel/</a></div>
</dd>
<dt class="label"><span><a name="xquery-semantics" id=
"xquery-semantics"></a>XQuery 1.0 and XPath 2.0 Formal
Semantics</span></dt>
<dd>
<div>World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Formal
Semantics. Available at: <a href=
"http://www.w3.org/TR/query-semantics/">http://www.w3.org/TR/query-semantics/</a></div>
</dd>
<dt class="label"><span><a name="xquery" id="xquery"></a>XQuery
1.0: An XML Query Language</span></dt>
<dd>
<div>World Wide Web Consortium. XQuery 1.0: An XML Query Language.
Available at: <a href=
"http://www.w3.org/TR/xquery/">http://www.w3.org/TR/xquery/</a></div>
</dd>
<dt class="label"><span><a name="xmlschema-1" id=
"xmlschema-1"></a>XML Schema Part 1: Structures Second
Edition</span></dt>
<dd>
<div>XML Schema Part 1: Structures Second Edition, Oct 28 2004.
Available at: <a href=
"http://www.w3.org/TR/xmlschema-1/">http://www.w3.org/TR/xmlschema-1/</a></div>
</dd>
<dt class="label"><span><a name="xmlschema-2" id=
"xmlschema-2"></a>XML Schema Part 2: Datatypes Second
Edition</span></dt>
<dd>
<div>XML Schema Part 2: Datatypes Second Edition, Oct. 28 2004.
Available at: <a href=
"http://www.w3.org/TR/xmlschema-2/">http://www.w3.org/TR/xmlschema-2/</a></div>
</dd>
<dt class="label"><span><a name="REC-xml-names" id=
"REC-xml-names"></a>Namespaces in XML</span></dt>
<dd>
<div>Namespaces in XML. Available at: <a href=
"http://www.w3.org/TR/1999/REC-xml-names-19990114/">http://www.w3.org/TR/1999/REC-xml-names-19990114/</a></div>
</dd>
</dl>
</div>
<div class="div2">
<h3><a name="non-normative-biblio" id=
"non-normative-biblio"></a>A.2 Non-normative References</h3>
<dl>
<dt class="label"><span><a name="HTML40" id="HTML40"></a>HTML
4.0</span></dt>
<dd>
<div>HTML 4.01 Recommendation, 24 December 1999. Available at:
<a href=
"http://www.w3.org/TR/REC-html40/">http://www.w3.org/TR/REC-html40/</a></div>
</dd>
<dt class="label"><span><a name="ISO8601" id="ISO8601"></a>ISO
8601</span></dt>
<dd>
<div>ISO (International Organization for Standardization).
<em>Representations of dates and times, 2000-08-03.</em> Available
from: <a href="http://www.iso.ch/">http://www.iso.ch/"</a></div>
</dd>
<dt class="label"><span><a name="Working-With-Timezones" id=
"Working-With-Timezones"></a>Working With Timezones</span></dt>
<dd>
<div>World Wide Web Consortium Working Group Note. <em>Working With
Timezones, October 13, 2005.</em> Available at: <a href=
"http://www.w3.org/TR/2005/NOTE-timezone-20051013/">http://www.w3.org/TR/2005/NOTE-timezone-20051013/</a></div>
</dd>
<dt class="label"><span><a name="xpath" id="xpath"></a>XML Path
Language (XPath) Version 1.0</span></dt>
<dd>
<div>World Wide Web Consortium. XML Path Language (XPath) Version
1.0 Available at: <a href=
"http://www.w3.org/TR/xpath">http://www.w3.org/TR/xpath</a></div>
</dd>
</dl>
</div>
</div>
<div class="div1">
<h2><a name="changelog" id="changelog"></a>B Change Log for this
Version of the Document</h2>
<p>This draft includes corrections and changes based on <a href=
"http://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&amp;short_desc_type=allwordssubstr&amp;short_desc=&amp;product=XPath+%2F+XQuery+%2F+XSLT&amp;component=Functions+and+Operators&amp;version=Proposed+Recommendation&amp;long_desc_type=allwordssubstr&amp;long_desc=&amp;bug_file_loc_type=allwordssubstr&amp;bug_file_loc=&amp;status_whiteboard_type=allwordssubstr&amp;status_whiteboard=&amp;keywords_type=allwords&amp;keywords=&amp;bug_status=RESOLVED&amp;bug_status=VERIFIED&amp;bug_status=CLOSED&amp;emailtype1=substring&amp;email1=&amp;emailtype2=substring&amp;email2=&amp;bugidtype=include&amp;bug_id=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp;cmdtype=doit&amp;order=Reuse+same+sort+as+last+time&amp;field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=">
public comments</a> recorded in the W3C public Bugzilla repository
(<a href=
"http://www.w3.org/Bugs/Public/">http://www.w3.org/Bugs/Public/</a>)
used for issue tracking on the <a href=
"http://www.w3.org/TR/2006/PR-xpath-functions-20061121/">Proposed
Recommendation</a> of 21 November 2006. A list of changes since the
publication of the <a href=
"http://www.w3.org/TR/2006/PR-xpath-functions-20061121/">Proposed
Recommendation</a> appears below.</p>
<ul>
<li>
<p><b>Bug 1207: Is unsignedInt("+123") an error?</b></p>
<p>The rules for casting from <code>xs:string</code> to derived
types were felt to be unclear. This was resolved by adding a
sentence at the end of <a href="#casting"><b>17 Casting</b></a>
that says "When casting from <code>xs:string</code> the semantics
in <a href="#casting-from-strings"><b>17.1.1 Casting from xs:string
and xs:untypedAtomic</b></a> apply, regardless of target type."</p>
</li>
<li>
<p><b>Bug 4030: Ambiguity re. normalization of the result of
fn:concat</b></p>
<p>It was not clear whether the result of result of <a href=
"#func-concat"><code>fn:concat</code></a> may not be normalized or
must not be normalized. This was resolved by changing the first
setence in the note in <a href=
"#func-concat"><code>fn:concat</code></a> to say "Unicode
normalization is not automatically applied to the result of
<a href="#func-concat"><code>fn:concat</code></a>".</p>
</li>
<li>
<p><b>Bug 4036: Ambiguity re. matching of argument to
fn:lang</b></p>
<p>The rules for matching the argument to <a href=
"#func-lang"><code>fn:lang</code></a> with the value of the
<code>xml:lang</code> attribute were felt to be imprecise. This was
resolved by changing the final paragraph to read "Otherwise, the
function returns true if and only if, based on a caseless default
match as specified in [The Unicode Standard], either (1)
<code>$testlang</code> is equal to the string-value of the relevant
<code>xml:lang</code> attribute, or (2) <code>$testlang</code> is
equal to some substring of the string-value of the relevant
<code>xml:lang</code> attribute that starts at the start of the
string-value and ends immediately before a hyphen (x2D)."</p>
</li>
<li>
<p><b>fn:iri-to-uri</b></p>
<p>Added a note that says that if the argument contains a character
that is prohibited in an IRI that character must be percent
encoded.</p>
</li>
</ul>
</div>
<div class="div1">
<h2><a name="error-summary" id="error-summary"></a>C Error
Summary</h2>
<p>The error text provided with these errors is non-normative.</p>
<dl>
<dt><a name="ERRFOER0000" id="ERRFOER0000"></a>err:FOER0000,
Unidentified error.</dt>
<dd>
<p>Unidentified error.</p>
</dd>
<dt><a name="ERRFOAR0001" id="ERRFOAR0001"></a>err:FOAR0001,
Division by zero.</dt>
<dd>
<p>This error is raised whenever an attempt is made to divide by
zero.</p>
</dd>
<dt><a name="ERRFOAR0002" id="ERRFOAR0002"></a>err:FOAR0002,
Numeric operation overflow/underflow.</dt>
<dd>
<p>This error is raised whenever numeric operations result in an
overflow or underflow.</p>
</dd>
<dt><a name="ERRFOCA0001" id="ERRFOCA0001"></a>err:FOCA0001, Input
value too large for decimal.</dt>
<dt><a name="ERRFOCA0002" id="ERRFOCA0002"></a>err:FOCA0002,
Invalid lexical value.</dt>
<dt><a name="ERRFOCA0003" id="ERRFOCA0003"></a>err:FOCA0003, Input
value too large for integer.</dt>
<dt><a name="ERRFOCA0005" id="ERRFOCA0005"></a>err:FOCA0005, NaN
supplied as float/double value.</dt>
<dt><a name="ERRFOCA0006" id="ERRFOCA0006"></a>err:FOCA0006, String
to be cast to decimal has too many digits of precision.</dt>
<dt><a name="ERRFOCH0001" id="ERRFOCH0001"></a>err:FOCH0001, Code
point not valid.</dt>
<dt><a name="ERRFOCH0002" id="ERRFOCH0002"></a>err:FOCH0002,
Unsupported collation.</dt>
<dt><a name="ERRFOCH0003" id="ERRFOCH0003"></a>err:FOCH0003,
Unsupported normalization form.</dt>
<dt><a name="ERRFOCH0004" id="ERRFOCH0004"></a>err:FOCH0004,
Collation does not support collation units.</dt>
<dt><a name="ERRFODC0001" id="ERRFODC0001"></a>err:FODC0001, No
context document.</dt>
<dt><a name="ERRFODC0002" id="ERRFODC0002"></a>err:FODC0002, Error
retrieving resource.</dt>
<dt><a name="ERRFODC0003" id="ERRFODC0003"></a>err:FODC0003,
Function stability not defined.</dt>
<dt><a name="ERRFODC0004" id="ERRFODC0004"></a>err:FODC0004,
Invalid argument to fn:collection.</dt>
<dt><a name="ERRFODC0005" id="ERRFODC0005"></a>err:FODC0005,
Invalid argument to fn:doc or fn:doc-available.</dt>
<dt><a name="ERRFODT0001" id="ERRFODT0001"></a>err:FODT0001,
Overflow/underflow in date/time operation.</dt>
<dt><a name="ERRFODT0002" id="ERRFODT0002"></a>err:FODT0002,
Overflow/underflow in duration operation.</dt>
<dt><a name="ERRFODT0003" id="ERRFODT0003"></a>err:FODT0003,
Invalid timezone value.</dt>
<dt><a name="ERRFONS0004" id="ERRFONS0004"></a>err:FONS0004, No
namespace found for prefix.</dt>
<dt><a name="ERRFONS0005" id="ERRFONS0005"></a>err:FONS0005,
Base-uri not defined in the static context.</dt>
<dt><a name="ERRFORG0001" id="ERRFORG0001"></a>err:FORG0001,
Invalid value for cast/constructor.</dt>
<dt><a name="ERRFORG0002" id="ERRFORG0002"></a>err:FORG0002,
Invalid argument to fn:resolve-uri().</dt>
<dt><a name="ERRFORG0003" id="ERRFORG0003"></a>err:FORG0003,
fn:zero-or-one called with a sequence containing more than one
item.</dt>
<dt><a name="ERRFORG0004" id="ERRFORG0004"></a>err:FORG0004,
fn:one-or-more called with a sequence containing no items.</dt>
<dt><a name="ERRFORG0005" id="ERRFORG0005"></a>err:FORG0005,
fn:exactly-one called with a sequence containing zero or more than
one item.</dt>
<dt><a name="ERRFORG0006" id="ERRFORG0006"></a>err:FORG0006,
Invalid argument type.</dt>
<dt><a name="ERRFORG0008" id="ERRFORG0008"></a>err:FORG0008, Both
arguments to fn:dateTime have a specified timezone.</dt>
<dt><a name="ERRFORG0009" id="ERRFORG0009"></a>err:FORG0009, Error
in resolving a relative URI against a base URI in
fn:resolve-uri.</dt>
<dt><a name="ERRFORX0001" id="ERRFORX0001"></a>err:FORX0001,
Invalid regular expression. flags</dt>
<dt><a name="ERRFORX0002" id="ERRFORX0002"></a>err:FORX0002,
Invalid regular expression.</dt>
<dt><a name="ERRFORX0003" id="ERRFORX0003"></a>err:FORX0003,
Regular expression matches zero-length string.</dt>
<dt><a name="ERRFORX0004" id="ERRFORX0004"></a>err:FORX0004,
Invalid replacement string.</dt>
<dt><a name="ERRFOTY0012" id="ERRFOTY0012"></a>err:FOTY0012,
Argument node does not have a typed value.</dt>
</dl>
</div>
<div class="div1">
<h2><a name="xpath1-compatibility" id="xpath1-compatibility"></a>D
Compatibility with XPath 1.0 (Non-Normative)</h2>
<p>This appendix summarizes the relationship between certain
functions defined in <a href="#xpath">[XML Path Language (XPath)
Version 1.0]</a> and the corresponding functions defined in this
document. The first column of the table provides the signature of
functions defined in this document. The second column provides the
signature of the corresponding function in <a href="#xpath">[XML
Path Language (XPath) Version 1.0]</a>. The third column discusses
the differences in the semantics of the corresponding functions.
The functions appear in the order they appear in <a href=
"#xpath">[XML Path Language (XPath) Version 1.0]</a>.</p>
<p>The evaluation of the arguments to the functions defined in this
document depends on whether the XPath 1.0 compatibility mode is on
or off. See <a href="#xpath20">[XML Path Language (XPath) 2.0]</a>.
If the mode is on, the following conversions are applied, in order,
before the argument value is passed to the function:</p>
<ul>
<li>
<p>If the expected type is a single item or an optional single
item, (examples: <code>xs:string, xs:string?, xs:untypedAtomic,
xs:untypedAtomic?, node(), node()?, item(), item()?</code>), then
the given value <code>V</code> is effectively replaced by <a href=
"#func-subsequence"><code>fn:subsequence(V, 1, 1)</code></a>.</p>
</li>
<li>
<p>If the expected type is <code>xs:string</code> or
<code>xs:string?</code>, then the given value <code>V</code> is
effectively replaced by <a href=
"#func-string"><code>fn:string(V)</code></a>.</p>
</li>
<li>
<p>If the expected type is numeric or optional numeric, then the
given value <code>V</code> is effectively replaced by <a href=
"#func-number"><code>fn:number(V)</code></a>.</p>
</li>
<li>
<p>Otherwise, the given value is unchanged.</p>
</li>
</ul>
<table summary="Issues list" border="1" width="100%">
<col width="33%" span="1" />
<col width="33%" span="1" />
<col width="33%" span="1" />
<tbody>
<tr>
<th>XQuery 1.0 and XPath 2.0</th>
<th>XPath 1.0</th>
<th>Notes</th>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:last</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</td>
<td><code>last() =&gt; number</code></td>
<td>Precision of numeric results may be different.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:position</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</td>
<td><code>position() =&gt; number</code></td>
<td>Precision of numeric results may be different.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:count</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer</code></div>
</td>
<td><code>count(node-set) =&gt; number</code></td>
<td>Precision of numeric results may be different.</td>
</tr>
<tr>
<td>
<div class="proto"><code class="function">fn:id</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">element()*</code></div>
</td>
<td><code>id(object) =&gt; node-set</code></td>
<td>XPath 2.0 behavior is different for boolean and numeric
arguments. The recognition of a node as an id value is sensitive to
the manner in which the datamodel is constructed. In XPath 1.0 the
whole string is treated as a unit. In XPath 2.0 each string is
treated as a list.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:local-name</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>local-name(node-set?) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if argument has more than one node.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:local-name</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:namespace-uri</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>namespace-uri(node-set?) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if argument has more than one node.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:namespace-uri</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:name</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td><code>name(node-set?) =&gt; string</code></td>
<td>If compatibility mode is off, an error will occur if argument
has more than one node. The rules for determining the prefix are
more precisely defined in <a href="#xpath20">[XML Path Language
(XPath) 2.0]</a>. Function is not "well-defined" for parentless
attribute nodes.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:string</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>string(object) =&gt; string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if argument has more than one node. Representations of numeric
values are XPath 1.0 compatible except for the special values
positive and negative infinity, and for values outside the range
1.0e-6 to 1.0e+6.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:string</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:concat</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>,</td>
</tr>
<tr>
<td valign="baseline"><span class="varargs">...</span></td>
<td valign="baseline">)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
<td><code>concat(string, string, string*) =&gt; string</code></td>
<td>If compatibility mode is off, an error will occur if an
argument has more than one node. If compatibility mode on, the
first node in the sequence is used.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:starts-with</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td rowspan="2"><code>starts-with(string, string) =&gt;
boolean</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if either argument has more than one node or is a number or a
boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:starts-with</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:contains</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td rowspan="2"><code>contains(string, string) =&gt;
boolean</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if either argument has more than one node or is a number or a
boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:contains</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:substring-before</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>substring-before(string, string) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if either argument has more than one node or is a number or a
boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring-before</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:substring-after</code>(<code class=
"arg">$arg1</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$arg2</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>substring-after(string, string) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if either argument has more than one node or is a number or a
boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring-after</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$collation</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">fn:substring</code>(</td>
<td valign="baseline"><code class="arg">$sourceString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$startingLoc</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
<td rowspan="2"><code>substring(string, number, number?) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if <code>$sourceString</code> has more than one node or is a number
or a boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:substring</code>(</td>
<td valign="baseline"><code class="arg">$sourceString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$startingLoc</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">xs:double</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$length</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:double</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:string-length</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</td>
<td rowspan="2"><code>string-length(string?) =&gt;
number</code></td>
<td rowspan="2">If compatibility mode is off, numbers and booleans
will give errors for first arg. Also, multiple nodes will give
error.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:string-length</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer?</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:normalize-space</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
<td rowspan="2"><code>normalize-space(string?) =&gt;
string</code></td>
<td rowspan="2">If compatibility mode is off, an error will occur
if <code>$arg</code> has more than one node or is a number or a
boolean. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:normalize-space</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="3"><code class=
"function">fn:translate</code>(</td>
<td valign="baseline"><code class="arg">$arg</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$mapString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$transString</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></td>
</tr>
</table>
</div>
</td>
<td><code>translate(string, string, string)=&gt; string</code></td>
<td>.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:boolean</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td><code>boolean(object) =&gt; boolean</code></td>
<td></td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:not</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">item()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td><code>not(boolean) =&gt; boolean</code></td>
<td></td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:true</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td><code>true() =&gt; boolean</code></td>
<td></td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:false</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td><code>false() =&gt; boolean</code></td>
<td></td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:lang</code>(<code class=
"arg">$testlang</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:string</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:boolean</code></div>
</td>
<td><code>lang(string) =&gt; boolean</code></td>
<td>If compatibility mode is off, numbers and booleans will give
errors. Also, multiple nodes will give error. If compatibility mode
is on, implicit conversion is performed.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:number</code>()<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double</code></div>
</td>
<td rowspan="2"><code>number(object?) =&gt; number</code></td>
<td rowspan="2">Error if argument has more than one node when not
in compatibility node.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:number</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:double</code></div>
</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:sum</code>(<code class="arg">$arg</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">xs:anyAtomicType</code></div>
</td>
<td><code>sum(node-set) =&gt; number</code></td>
<td>2.0 raises an error if sequence contains values that cannot be
added together such as NMTOKENS and other subtypes of string. 1.0
returns <code>NaN</code>.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:floor</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</td>
<td><code>floor(number)=&gt; number</code></td>
<td>In 2.0, if argument is <code>()</code>, the result is
<code>()</code>. In 1.0, the result is <code>NaN</code>. If
compatibility mode is off, an error will occur with more than one
node. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:ceiling</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</td>
<td><code>ceiling(number)=&gt; number</code></td>
<td>In 2.0, if argument is <code>()</code>, the result is
<code>()</code>. In 1.0, the result is <code>NaN</code>. If
compatibility mode is off, an error will occur with more than one
node. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
<tr>
<td>
<div class="proto"><code class=
"function">fn:round</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">numeric?</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-varies">numeric?</code></div>
</td>
<td><code>round(number)=&gt; number</code></td>
<td>In 2.0, if argument is <code>()</code>, the result is
<code>()</code>. In 1.0, the result is <code>NaN</code>. If
compatibility mode is off, an error will occur with more than one
node. If compatibility mode is on, implicit conversion is
performed.</td>
</tr>
</tbody>
</table>
</div>
<div class="div1">
<h2><a name="examples" id="examples"></a>E Illustrative
User-written Functions (Non-Normative)</h2>
<p>Certain functions that were proposed for inclusion in this
function library have been excluded on the basis that it is
straightforward for users to implement these functions themselves
using XSLT 2.0 or XQuery 1.0.</p>
<p>This Appendix provides sample implementations of some of these
functions.</p>
<p>To emphasize that these functions are examples of functions that
vendors may write, their names carry the prefix 'eg'. Vendors are
free to define such functions in any namespace. A group of vendors
may also choose to create a collection of such useful functions and
put them in a common namespace.</p>
<div class="div2">
<h3><a name="if-empty-if-absent" id="if-empty-if-absent"></a>E.1
eg:if-empty and eg:if-absent</h3>
<p>In some situations, users may want to provide default values for
missing information that may be signaled by elements that are
omitted, have no value or have the empty sequence as their value.
For example, a missing middle initial may be indicated by omitting
the element or a non-existent bonus signaled with an empty
sequence. This section includes examples of functions that provide
such defaults. These functions return
<code>xs:anyAtomicType*</code>. Users may want to write functions
that return more specific types.</p>
<div class="div3">
<h4><a name="if-empty" id="if-empty"></a>E.1.1 eg:if-empty</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">eg:if-empty</code>(</td>
<td valign="baseline"><code class="arg">$node</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">node()?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$value</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>If the first argument is the empty sequence or an element
without simple or complex content, if-empty() returns the second
argument; otherwise, it returns the content of the first
argument.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:if-empty" as="xs:anyAtomicType*"&gt;
&lt;xsl:param name="node" as="node()?"/&gt;
&lt;xsl:param name="value" as="xs:anyAtomicType"/&gt;
&lt;xsl:choose&gt;
&lt;xsl:when test="$node and $node/child::node()"&gt;
&lt;xsl:sequence select="fn:data($node)"/&gt;
&lt;/xsl:when&gt;
&lt;xsl:otherwise&gt;
&lt;xsl:sequence select="$value"/&gt;
&lt;/xsl:otherwise&gt;
&lt;/xsl:choose&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:if-empty (
$node as node()?,
$value as xs:anyAtomicType) as xs:anyAtomicType*
{
if ($node and $node/child::node())
then fn:data($node)
else $value
}
</pre></div>
</div>
<div class="div3">
<h4><a name="if-absent" id="if-absent"></a>E.1.2 eg:if-absent</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">eg:if-absent</code>(</td>
<td valign="baseline"><code class="arg">$node</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class="type">node()?</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$value</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>If the first argument is the empty sequence, if-absent() returns
the second argument; otherwise, it returns the content of the first
argument.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:if-absent"&gt;
&lt;xsl:param name="node" as="node()?"/&gt;
&lt;xsl:param name="value" as="xs:anyAtomicType"/&gt;
&lt;xsl:choose&gt;
&lt;xsl:when test="$node"&gt;
&lt;xsl:sequence select="fn:data($node)"/&gt;
&lt;/xsl:when&gt;
&lt;xsl:otherwise&gt;
&lt;xsl:sequence select="$value"/&gt;
&lt;/xsl:otherwise&gt;
&lt;/xsl:choose&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:if-absent (
$node as node()?,
$value as xs:anyAtomicType) as xs:anyAtomicType*
{
if ($node)
then fn:data($node)
else $value
}
</pre></div>
</div>
</div>
<div class="div2">
<h3><a name="union-intersect-except-on-values" id=
"union-intersect-except-on-values"></a>E.2 union, intersect and
except on sequences of values</h3>
<div class="div3">
<h4><a name="value-union" id="value-union"></a>E.2.1
eg:value-union</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">eg:value-union</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>This function returns a sequence containing all the distinct
items in $arg1 and $arg2, in an undefined order.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
xsl:function name="eg:value-union" as="xs:anyAtomicType*"&gt;
&lt;xsl:param name="arg1" as="xs:anyAtomicType*"/&gt;
&lt;xsl:param name="arg2" as="xs:anyAtomicType*"/&gt;
&lt;xsl:sequence
select="fn:distinct-values(($arg1, $arg2))"/&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:value-union (
$arg1 as xs:anyAtomicType*,
$arg2 as xs:anyAtomicType*) as xs:anyAtomicType*
{
fn:distinct-values(($arg1, $arg2))
}
</pre></div>
</div>
<div class="div3">
<h4><a name="value-intersect" id="value-intersect"></a>E.2.2
eg:value-intersect</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">eg:value-intersect</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>This function returns a sequence containing all the distinct
items that appear in both $arg1 and $arg2, in an undefined
order.</p>
<p>XSLT implementation&gt;</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:value-intersect" as="xs:anyAtomicType*"&gt;
&lt;xsl:param name="arg1" as="xs:anyAtomicType*"/&gt;
&lt;xsl:param name="arg2" as="xs:anyAtomicType*"/&gt;
&lt;xsl:sequence
select="fn:distinct-values($arg1[.=$arg2])"/&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:value-intersect (
$arg1 as xs:anyAtomicType*,
$arg2 as xs:anyAtomicType* ) as xs:anyAtomicType*
{
fn:distinct-values($arg1[.=$arg2])
}
</pre></div>
</div>
<div class="div3">
<h4><a name="value-except" id="value-except"></a>E.2.3
eg:value-except</h4>
<div class="exampleInner">
<div class="proto">
<table border="0" cellpadding="0" cellspacing="0" summary=
"Function/operator prototype">
<tr>
<td valign="baseline" rowspan="2"><code class=
"function">eg:value-except</code>(</td>
<td valign="baseline"><code class="arg">$arg1</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>,</td>
</tr>
<tr>
<td valign="baseline"><code class="arg">$arg2</code></td>
<td valign="baseline"><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:anyAtomicType*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:anyAtomicType*</code></td>
</tr>
</table>
</div>
</div>
<p>This function returns a sequence containing all the distinct
items that appear in $arg1 but not in $arg2, in an undefined
order.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:value-except" as="xs:anyAtomicType*"&gt;
&lt;xsl:param name="arg1" as="xs:anyAtomicType*"/&gt;
&lt;xsl:param name="arg2" as="xs:anyAtomicType*"/&gt;
&lt;xsl:sequence
select="fn:distinct-values($arg1[not(.=$arg2)])"/&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:value-except (
$arg1 as xs:anyAtomicType*,
$arg2 as xs:anyAtomicType*) as xs:anyAtomicType*
{
fn:distinct-values($arg1[not(.=$arg2)])
}
</pre></div>
</div>
</div>
<div class="div2">
<h3><a name="index-of-node" id="index-of-node"></a>E.3
eg:index-of-node</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">eg:index-of-node</code>(<code class=
"arg">$seqParam</code><code class=
"as">&#160;as&#160;</code><code class="type">node()*</code>,
<code class="arg">$srchParam</code><code class=
"as">&#160;as&#160;</code><code class=
"type">node()</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:integer*</code></div>
</div>
<p>This function returns a sequence of positive integers giving the
positions within the sequence <code>$seqParam</code> of nodes that
are identical to <code>$srchParam</code>.</p>
<p>The nodes in the sequence <code>$seqParam</code> are compared
with <code>$srchParam</code> under the rules for the
<code>is</code> operator. If a node compares identical, then the
position of that node in the sequence <code>$srchParam</code> is
included in the result.</p>
<p>If the value of <code>$seqParam</code> is the empty sequence, or
if no node in <code>$seqParam</code> matches $srchParam, then the
empty sequence is returned.</p>
<p>The index is 1-based, not 0-based.</p>
<p>The result sequence is in ascending numeric order.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:index-of-node" as="xs:integer*"&gt;
&lt;xsl:param name="sequence" as="node()*"/&gt;
&lt;xsl:param name="srch" as="node()"/&gt;
&lt;xsl:for-each select="$sequence"&gt;
&lt;xsl:if test=". is $srch"&gt;
&lt;xsl:sequence select="position()"/&gt;
&lt;/xsl:if&gt;
&lt;/xsl:for-each&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:index-of-node($sequence as node()*, $srch as node()) as xs:integer*
{
for $n at $i in $sequence where ($n is $srch) return $i
}
</pre></div>
</div>
<div class="div2">
<h3><a name="string-pad" id="string-pad"></a>E.4 eg:string-pad</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">eg:string-pad</code>(<code class=
"arg">$padString</code><code class=
"as">&#160;as&#160;</code><code class="type">xs:string?</code>,
<code class="arg">$padCount</code><code class=
"as">&#160;as&#160;</code><code class=
"type">xs:integer</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">xs:string</code></div>
</div>
<p>Returns a <code>xs:string</code> consisting of a given number of
copies of an <code>xs:string</code> argument concatenated
together.</p>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:string-pad" as="xs:string"&gt;
&lt;xsl:param name="padString" as="xs:string?"/&gt;
&lt;xsl:param name="padCount" as="xs:integer"/&gt;
&lt;xsl:sequence select="fn:string-join((for $i in 1 to $padCount
return $padString), '')"/&gt;
&lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function eg:string-pad (
$padString as xs:string?,
$padCount as xs:integer) as xs:string
{
fn:string-join((for $i in 1 to $padCount return $padString), "")
}
</pre></div>
<p>This returns the zero-length string if <code>$padString</code>
is the empty sequence, which is consistent with the general
principle that if an <code>xs:string</code> argument is the empty
sequence it is treated as if it were the zero-length string.</p>
</div>
<div class="div2">
<h3><a name="func-distinct-nodes-stable" id=
"func-distinct-nodes-stable"></a>E.5 eg:distinct-nodes-stable</h3>
<div class="exampleInner">
<div class="proto"><code class=
"function">fn:eg:distinct-nodes-stable</code>(<code class=
"arg">$arg</code><code class="as">&#160;as&#160;</code><code class=
"type">node()*</code>)<code class=
"as">&#160;as&#160;</code><code class=
"return-type">node()*</code></div>
</div>
<p>This function illustrates one possible implementation of a
distinct-nodes function. It removes duplicate nodes by identity,
preserving the first occurrence of each node.</p>
<p>XPath</p>
<div class="exampleInner">
<pre>
$arg[empty(subsequence($arg, 1, position()-1) intersect .)]
</pre></div>
<p>XSLT implementation</p>
<div class="exampleInner">
<pre>
&lt;xsl:function name="eg:distinct-nodes-stable" as="node()*"&gt;
&lt;xsl:param name="arg" as="node()*"/&gt;
&lt;xsl:sequence
select="$arg[empty(subsequence($arg, 1, position()-1) intersect .)]"/&gt; &lt;/xsl:function&gt;
</pre></div>
<p>XQuery implementation</p>
<div class="exampleInner">
<pre>
declare function distinct-nodes-stable ($arg as node()*) as node()*
{
for $a at $apos in $arg
let $before_a := fn:subsequence($arg, 1, $apos - 1)
where every $ba in $before_a satisfies not($ba is $a)
return $a
}
</pre></div>
</div>
</div>
<div class="div1">
<h2><a name="impl-def" id="impl-def"></a>F Checklist of
Implementation-Defined Features (Non-Normative)</h2>
<p>This appendix provides a summary of features defined in this
specification whose effect is explicitly <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. The conformance rules require vendors to
provide documentation that explains how these choices have been
exercised.</p>
<ol class="enumar">
<li>
<p>The destination of the trace output is <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. See <a href="#func-trace"><b>4 The Trace
Function</b></a>.</p>
</li>
<li>
<p>For <code>xs:integer</code> operations, implementations that
support limited-precision integer operations <a title="must" class=
"termref" href="#must"><span class="arrow">·</span>must<span class=
"arrow">·</span></a> either raise an error [<a href="#ERRFOAR0002"
title="err:FOAR0002">err:FOAR0002</a>] or provide an <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> mechanism that allows users to choose between
raising an error and returning a result that is modulo the largest
representable integer value. See <a href="#op.numeric"><b>6.2
Operators on Numeric Values</b></a>.</p>
</li>
<li>
<p>For <code>xs:decimal</code> values the number of digits of
precision returned by the numeric operators is <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. See <a href="#op.numeric"><b>6.2 Operators on
Numeric Values</b></a>. See also <a href=
"#casting-to-decimal"><b>17.1.3.3 Casting to xs:decimal</b></a> and
<a href="#casting-to-integer"><b>17.1.3.4 Casting to
xs:integer</b></a></p>
</li>
<li>
<p>If the number of digits in the result of a numeric operation
exceeds the number of digits that the implementation supports, the
result is truncated or rounded in an <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> manner. See <a href="#op.numeric"><b>6.2
Operators on Numeric Values</b></a>. See also <a href=
"#casting-to-decimal"><b>17.1.3.3 Casting to xs:decimal</b></a> and
<a href="#casting-to-integer"><b>17.1.3.4 Casting to
xs:integer</b></a></p>
</li>
<li>
<p>It is <a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> which version of Unicode is supported by the
features defined in this specification, but it is recommended that
the most recent version of Unicode be used. See <a href=
"#string-types"><b>7.1 String Types</b></a>.</p>
</li>
<li>
<p>For <a href="#func-normalize-unicode"><b>7.4.6
fn:normalize-unicode</b></a>, conforming implementations <a title=
"must" class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> support
normalization form "NFC" and <a title="may" class="termref" href=
"#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> support normalization forms "NFD", "NFKC",
"NFKD", "FULLY-NORMALIZED". They <a title="may" class="termref"
href="#may"><span class="arrow">·</span>may<span class=
"arrow">·</span></a> also support other normalization forms with
<a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> semantics.</p>
</li>
<li>
<p>The ability to decompose strings into collation units suitable
for substring matching is an <a title="implementation-defined"
class="termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> property of a collation. See <a href=
"#substring.functions"><b>7.5 Functions Based on Substring
Matching</b></a>.</p>
</li>
<li>
<p>All <em>minimally conforming</em> processors <a title="must"
class="termref" href="#must"><span class=
"arrow">·</span>must<span class="arrow">·</span></a> support year
values with a minimum of 4 digits (i.e., YYYY) and a minimum
fractional second precision of 1 millisecond or three digits (i.e.,
s.sss). However, <em>conforming processors</em> <a title="may"
class="termref" href="#may"><span class=
"arrow">·</span>may<span class="arrow">·</span></a> set larger
<a title="implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a> limits on the maximum number of digits they
support in these two situations. See <a href=
"#date-time-duration-conformance"><b>10.1.1 Limits and
Precision</b></a>.</p>
</li>
<li>
<p>The result of casting a string to <code>xs:decimal</code>, when
the resulting value is not too large or too small but nevertheless
has too many decimal digits to be accurately represented, is
implementation-defined. See <a href=
"#casting-from-strings"><b>17.1.1 Casting from xs:string and
xs:untypedAtomic</b></a>.</p>
</li>
<li>
<p>Various aspects of the processing provided by <a href=
"#func-doc"><b>15.5.4 fn:doc</b></a> are <a title=
"implementation-defined" class="termref" href=
"#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>. Implementations may provide external
configuration options that allow any aspect of the processing to be
controlled by the user.</p>
</li>
<li>
<p>The manner in which implementations provide options to weaken
the <a title="stable" class="termref" href="#stable"><span class=
"arrow">·</span>stable<span class="arrow">·</span></a>
characteristic of <a href="#func-collection"><b>15.5.6
fn:collection</b></a> and <a href="#func-doc"><b>15.5.4
fn:doc</b></a> are <a title="implementation-defined" class=
"termref" href="#implementation-defined"><span class=
"arrow">·</span>implementation-defined<span class=
"arrow">·</span></a>.</p>
</li>
</ol>
</div>
<div class="div1">
<h2><a name="quickref" id="quickref"></a>G Function and Operator
Quick Reference (Non-Normative)</h2>
<div class="div2">
<h3><a name="quickref-section" id="quickref-section"></a>G.1
Functions and Operators by Section</h3>
<dl>
<dt class="label">2 Accessors</dt>
<dd>
<dl>
<dt class="label">2.1 fn:node-name</dt>
<dd>
<div class="protoref"><a href=
"#func-node-name"><code>fn:node-name</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:QName?</code></div>
</dd>
<dt class="label">2.2 fn:nilled</dt>
<dd>
<div class="protoref"><a href=
"#func-nilled"><code>fn:nilled</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>xs:boolean?</code></div>
</dd>
<dt class="label">2.3 fn:string</dt>
<dd>
<div class="protoref"><a href=
"#func-string"><code>fn:string</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-string"><code>fn:string</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()?</code>)<code>&#160;as&#160;</code><code>xs:string</code></div>
</dd>
<dt class="label">2.4 fn:data</dt>
<dd>
<div class="protoref"><a href=
"#func-data"><code>fn:data</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType*</code></div>
</dd>
<dt class="label">2.5 fn:base-uri</dt>
<dd>
<div class="protoref"><a href=
"#func-base-uri"><code>fn:base-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
<div class="protoref"><a href=
"#func-base-uri"><code>fn:base-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
</dd>
<dt class="label">2.6 fn:document-uri</dt>
<dd>
<div class="protoref"><a href=
"#func-document-uri"><code>fn:document-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
</dd>
</dl>
</dd>
<dt class="label">3 The Error Function</dt>
<dd>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>()<code>&#160;as&#160;</code><code>
none</code></div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName</code>)<code>&#160;as&#160;</code><code>none</code></div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName?</code>,
<code>$description</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>none</code></div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName?</code>,
<code>$description</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$error-object</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>none</code></div>
</dd>
<dt class="label">4 The Trace Function</dt>
<dd>
<div class="protoref"><a href=
"#func-trace"><code>fn:trace</code></a>(<code>$value</code><code>&#160;as&#160;</code><code>
item()*</code>,
<code>$label</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
</dd>
<dt class="label">5 Constructor Functions</dt>
<dd>
<dl>
<dt class="label">5.2 A Special Constructor Function for
xs:dateTime</dt>
<dd>
<div class="protoref"><a href=
"#func-dateTime"><code>fn:dateTime</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code></div>
</dd>
</dl>
</dd>
<dt class="label">6 Functions and Operators on Numerics</dt>
<dd>
<dl>
<dt class="label">6.2 Operators on Numeric Values</dt>
<dd>
<div class="protoref"><a href=
"#func-numeric-add"><code>op:numeric-add</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-subtract"><code>op:numeric-subtract</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-multiply"><code>op:numeric-multiply</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-integer-divide"><code>op:numeric-integer-divide</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:integer</code></div>
<div class="protoref"><a href=
"#func-numeric-mod"><code>op:numeric-mod</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-unary-plus"><code>op:numeric-unary-plus</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric</code>)<code>&#160;as&#160;</code><code>
numeric</code></div>
<div class="protoref"><a href=
"#func-numeric-unary-minus"><code>op:numeric-unary-minus</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric</code>)<code>&#160;as&#160;</code><code>
numeric</code></div>
</dd>
<dt class="label">6.3 Comparison Operators on Numeric Values</dt>
<dd>
<div class="protoref"><a href=
"#func-numeric-equal"><code>op:numeric-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-numeric-less-than"><code>op:numeric-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-numeric-greater-than"><code>op:numeric-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">6.4 Functions on Numeric Values</dt>
<dd>
<div class="protoref"><a href=
"#func-abs"><code>fn:abs</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code></div>
<div class="protoref"><a href=
"#func-ceiling"><code>fn:ceiling</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code></div>
<div class="protoref"><a href=
"#func-floor"><code>fn:floor</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code></div>
<div class="protoref"><a href=
"#func-round"><code>fn:round</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code></div>
<div class="protoref"><a href=
"#func-round-half-to-even"><code>fn:round-half-to-even</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric?</code>)<code>&#160;as&#160;</code><code>
numeric?</code></div>
<div class="protoref"><a href=
"#func-round-half-to-even"><code>fn:round-half-to-even</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric?</code>,
<code>$precision</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>numeric?</code></div>
</dd>
</dl>
</dd>
<dt class="label">7 Functions on Strings</dt>
<dd>
<dl>
<dt class="label">7.2 Functions to Assemble and Disassemble
Strings</dt>
<dd>
<div class="protoref"><a href=
"#func-codepoints-to-string"><code>fn:codepoints-to-string</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:integer*</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-string-to-codepoints"><code>fn:string-to-codepoints</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code></div>
</dd>
<dt class="label">7.3 Equality and Comparison of Strings</dt>
<dd>
<div class="protoref"><a href=
"#func-compare"><code>fn:compare</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-compare"><code>fn:compare</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-codepoint-equal"><code>fn:codepoint-equal</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean?</code></div>
</dd>
<dt class="label">7.4 Functions on String Values</dt>
<dd>
<div class="protoref"><a href=
"#func-concat"><code>fn:concat</code></a>(<code>$arg1</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>,
<span class=
"varargs">...</span>)<code>&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-string-join"><code>fn:string-join</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string*</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-substring"><code>fn:substring</code></a>(<code>$sourceString</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-substring"><code>fn:substring</code></a>(<code>$sourceString</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>,
<code>$length</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-string-length"><code>fn:string-length</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code></div>
<div class="protoref"><a href=
"#func-string-length"><code>fn:string-length</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:integer</code></div>
<div class="protoref"><a href=
"#func-normalize-space"><code>fn:normalize-space</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-normalize-space"><code>fn:normalize-space</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$normalizationForm</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-upper-case"><code>fn:upper-case</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-lower-case"><code>fn:lower-case</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-translate"><code>fn:translate</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$mapString</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$transString</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-encode-for-uri"><code>fn:encode-for-uri</code></a>(<code>$uri-part</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-iri-to-uri"><code>fn:iri-to-uri</code></a>(<code>$iri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-escape-html-uri"><code>fn:escape-html-uri</code></a>(<code>$uri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
</dd>
<dt class="label">7.5 Functions Based on Substring Matching</dt>
<dd>
<div class="protoref"><a href=
"#func-contains"><code>fn:contains</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-contains"><code>fn:contains</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-starts-with"><code>fn:starts-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-starts-with"><code>fn:starts-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-ends-with"><code>fn:ends-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-ends-with"><code>fn:ends-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-substring-before"><code>fn:substring-before</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-substring-before"><code>fn:substring-before</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-substring-after"><code>fn:substring-after</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-substring-after"><code>fn:substring-after</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
</dd>
<dt class="label">7.6 String Functions that Use Pattern
Matching</dt>
<dd>
<div class="protoref"><a href=
"#func-matches"><code>fn:matches</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-matches"><code>fn:matches</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-replace"><code>fn:replace</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$replacement</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-replace"><code>fn:replace</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$replacement</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code></div>
<div class="protoref"><a href=
"#func-tokenize"><code>fn:tokenize</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string*</code></div>
<div class="protoref"><a href=
"#func-tokenize"><code>fn:tokenize</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string*</code></div>
</dd>
</dl>
</dd>
<dt class="label">8 Functions on anyURI</dt>
<dd>
<dl>
<dt class="label">8.1 fn:resolve-uri</dt>
<dd>
<div class="protoref"><a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a>(<code>$relative</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
<div class="protoref"><a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a>(<code>$relative</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$base</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:anyURI?</code></div>
</dd>
</dl>
</dd>
<dt class="label">9 Functions and Operators on Boolean Values</dt>
<dd>
<dl>
<dt class="label">9.1 Additional Boolean Constructor Functions</dt>
<dd>
<div class="protoref"><a href=
"#func-true"><code>fn:true</code></a>()<code>&#160;as&#160;</code><code>
xs:boolean</code></div>
<div class="protoref"><a href=
"#func-false"><code>fn:false</code></a>()<code>&#160;as&#160;</code><code>
xs:boolean</code></div>
</dd>
<dt class="label">9.2 Operators on Boolean Values</dt>
<dd>
<div class="protoref"><a href=
"#func-boolean-equal"><code>op:boolean-equal</code></a>(<code>$value1</code><code>
&#160;as&#160;</code><code>xs:boolean</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-boolean-less-than"><code>op:boolean-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:boolean</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-boolean-greater-than"><code>op:boolean-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:boolean</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">9.3 Functions on Boolean Values</dt>
<dd>
<div class="protoref"><a href=
"#func-not"><code>fn:not</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
</dl>
</dd>
<dt class="label">10 Functions and Operators on Durations, Dates
and Times</dt>
<dd>
<dl>
<dt class="label">10.4 Comparison Operators on Duration, Date and
Time Values</dt>
<dd>
<div class="protoref"><a href=
"#func-yearMonthDuration-less-than"><code>op:yearMonthDuration-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-yearMonthDuration-greater-than"><code>op:yearMonthDuration-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-dayTimeDuration-less-than"><code>op:dayTimeDuration-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-dayTimeDuration-greater-than"><code>op:dayTimeDuration-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-duration-equal"><code>op:duration-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:duration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:duration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-dateTime-less-than"><code>op:dateTime-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-dateTime-greater-than"><code>op:dateTime-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-date-equal"><code>op:date-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-date-less-than"><code>op:date-less-than</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-date-greater-than"><code>op:date-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-time-equal"><code>op:time-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-time-less-than"><code>op:time-less-than</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-time-greater-than"><code>op:time-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-gYearMonth-equal"><code>op:gYearMonth-equal</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:gYearMonth</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gYearMonth</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-gYear-equal"><code>op:gYear-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gYear</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gYear</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-gMonthDay-equal"><code>op:gMonthDay-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gMonthDay</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gMonthDay</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-gMonth-equal"><code>op:gMonth-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gMonth</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gMonth</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-gDay-equal"><code>op:gDay-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gDay</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gDay</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">10.5 Component Extraction Functions on Durations,
Dates and Times</dt>
<dd>
<div class="protoref"><a href=
"#func-years-from-duration"><code>fn:years-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-months-from-duration"><code>fn:months-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-days-from-duration"><code>fn:days-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-hours-from-duration"><code>fn:hours-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-minutes-from-duration"><code>fn:minutes-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-seconds-from-duration"><code>fn:seconds-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:decimal?</code></div>
<div class="protoref"><a href=
"#func-year-from-dateTime"><code>fn:year-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-month-from-dateTime"><code>fn:month-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-day-from-dateTime"><code>fn:day-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-hours-from-dateTime"><code>fn:hours-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-minutes-from-dateTime"><code>fn:minutes-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code></div>
<div class="protoref"><a href=
"#func-seconds-from-dateTime"><code>fn:seconds-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:decimal?</code></div>
<div class="protoref"><a href=
"#func-timezone-from-dateTime"><code>fn:timezone-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code></div>
<div class="protoref"><a href=
"#func-year-from-date"><code>fn:year-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code></div>
<div class="protoref"><a href=
"#func-month-from-date"><code>fn:month-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code></div>
<div class="protoref"><a href=
"#func-day-from-date"><code>fn:day-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code></div>
<div class="protoref"><a href=
"#func-timezone-from-date"><code>fn:timezone-from-date</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:dayTimeDuration?</code></div>
<div class="protoref"><a href=
"#func-hours-from-time"><code>fn:hours-from-time</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code></div>
<div class="protoref"><a href=
"#func-minutes-from-time"><code>fn:minutes-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code></div>
<div class="protoref"><a href=
"#func-seconds-from-time"><code>fn:seconds-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:decimal?</code></div>
<div class="protoref"><a href=
"#func-timezone-from-time"><code>fn:timezone-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:dayTimeDuration?</code></div>
</dd>
<dt class="label">10.6 Arithmetic Operators on Durations</dt>
<dd>
<div class="protoref"><a href=
"#func-add-yearMonthDurations"><code>op:add-yearMonthDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code></div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDurations"><code>op:subtract-yearMonthDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code></div>
<div class="protoref"><a href=
"#func-multiply-yearMonthDuration"><code>op:multiply-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code></div>
<div class="protoref"><a href=
"#func-divide-yearMonthDuration"><code>op:divide-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code></div>
<div class="protoref"><a href=
"#func-divide-yearMonthDuration-by-yearMonthDuration"><code>op:divide-yearMonthDuration-by-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:decimal</code></div>
<div class="protoref"><a href=
"#func-add-dayTimeDurations"><code>op:add-dayTimeDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDurations"><code>op:subtract-dayTimeDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
<div class="protoref"><a href=
"#func-multiply-dayTimeDuration"><code>op:multiply-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
<div class="protoref"><a href=
"#func-divide-dayTimeDuration"><code>op:divide-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
<div class="protoref"><a href=
"#func-divide-dayTimeDuration-by-dayTimeDuration"><code>op:divide-dayTimeDuration-by-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:decimal</code></div>
</dd>
<dt class="label">10.7 Timezone Adjustment Functions on Dates and
Time Values</dt>
<dd>
<div class="protoref"><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code></div>
<div class="protoref"><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code></div>
<div class="protoref"><a href=
"#func-adjust-date-to-timezone"><code>fn:adjust-date-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:date?</code></div>
<div class="protoref"><a href=
"#func-adjust-date-to-timezone"><code>fn:adjust-date-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:date?</code></div>
<div class="protoref"><a href=
"#func-adjust-time-to-timezone"><code>fn:adjust-time-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:time?</code></div>
<div class="protoref"><a href=
"#func-adjust-time-to-timezone"><code>fn:adjust-time-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:time?</code></div>
</dd>
<dt class="label">10.8 Arithmetic Operators on Durations, Dates and
Times</dt>
<dd>
<div class="protoref"><a href=
"#func-subtract-dateTimes"><code>op:subtract-dateTimes</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code></div>
<div class="protoref"><a href=
"#func-subtract-dates"><code>op:subtract-dates</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code></div>
<div class="protoref"><a href=
"#func-subtract-times"><code>op:subtract-times</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
<div class="protoref"><a href=
"#func-add-yearMonthDuration-to-dateTime"><code>op:add-yearMonthDuration-to-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code></div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-dateTime"><code>op:add-dayTimeDuration-to-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code></div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDuration-from-dateTime"><code>op:subtract-yearMonthDuration-from-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code></div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-dateTime"><code>op:subtract-dayTimeDuration-from-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code></div>
<div class="protoref"><a href=
"#func-add-yearMonthDuration-to-date"><code>op:add-yearMonthDuration-to-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code></div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-date"><code>op:add-dayTimeDuration-to-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code></div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDuration-from-date"><code>op:subtract-yearMonthDuration-from-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code></div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-date"><code>op:subtract-dayTimeDuration-from-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code></div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-time"><code>op:add-dayTimeDuration-to-time</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:time</code></div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-time"><code>op:subtract-dayTimeDuration-from-time</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:time</code></div>
</dd>
</dl>
</dd>
<dt class="label">11 Functions Related to QNames</dt>
<dd>
<dl>
<dt class="label">11.1 Additional Constructor Functions for
QNames</dt>
<dd>
<div class="protoref"><a href=
"#func-resolve-QName"><code>fn:resolve-QName</code></a>(<code>$qname</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:QName?</code></div>
<div class="protoref"><a href=
"#func-QName"><code>fn:QName</code></a>(<code>$paramURI</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$paramQName</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:QName</code></div>
</dd>
<dt class="label">11.2 Functions and Operators Related to
QNames</dt>
<dd>
<div class="protoref"><a href=
"#func-QName-equal"><code>op:QName-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:QName</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:QName</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-prefix-from-QName"><code>fn:prefix-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:NCName?</code></div>
<div class="protoref"><a href=
"#func-local-name-from-QName"><code>fn:local-name-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:NCName?</code></div>
<div class="protoref"><a href=
"#func-namespace-uri-from-QName"><code>fn:namespace-uri-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
<div class="protoref"><a href=
"#func-namespace-uri-for-prefix"><code>fn:namespace-uri-for-prefix</code></a>(<code>
$prefix</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:anyURI?</code></div>
<div class="protoref"><a href=
"#func-in-scope-prefixes"><code>fn:in-scope-prefixes</code></a>(<code>
$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:string*</code></div>
</dd>
</dl>
</dd>
<dt class="label">12 Operators on base64Binary and hexBinary</dt>
<dd>
<dl>
<dt class="label">12.1 Comparisons of base64Binary and hexBinary
Values</dt>
<dd>
<div class="protoref"><a href=
"#func-hexBinary-equal"><code>op:hexBinary-equal</code></a>(<code>$value1</code><code>
&#160;as&#160;</code><code>xs:hexBinary</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:hexBinary</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-base64Binary-equal"><code>op:base64Binary-equal</code></a>(<code>
$value1</code><code>&#160;as&#160;</code><code>xs:base64Binary</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:base64Binary</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
</dl>
</dd>
<dt class="label">13 Operators on NOTATION</dt>
<dd>
<dl>
<dt class="label">13.1 Operators on NOTATION</dt>
<dd>
<div class="protoref"><a href=
"#func-NOTATION-equal"><code>op:NOTATION-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:NOTATION</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:NOTATION</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
</dl>
</dd>
<dt class="label">14 Functions and Operators on Nodes</dt>
<dd>
<dl>
<dt class="label">14.1 fn:name</dt>
<dd>
<div class="protoref"><a href=
"#func-name"><code>fn:name</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-name"><code>fn:name</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>xs:string</code></div>
</dd>
<dt class="label">14.2 fn:local-name</dt>
<dd>
<div class="protoref"><a href=
"#func-local-name"><code>fn:local-name</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code></div>
<div class="protoref"><a href=
"#func-local-name"><code>fn:local-name</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:string</code></div>
</dd>
<dt class="label">14.3 fn:namespace-uri</dt>
<dd>
<div class="protoref"><a href=
"#func-namespace-uri"><code>fn:namespace-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI</code></div>
<div class="protoref"><a href=
"#func-namespace-uri"><code>fn:namespace-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI</code></div>
</dd>
<dt class="label">14.4 fn:number</dt>
<dd>
<div class="protoref"><a href=
"#func-number"><code>fn:number</code></a>()<code>&#160;as&#160;</code><code>
xs:double</code></div>
<div class="protoref"><a href=
"#func-number"><code>fn:number</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType?</code>)<code>&#160;as&#160;</code><code>xs:double</code></div>
</dd>
<dt class="label">14.5 fn:lang</dt>
<dd>
<div class="protoref"><a href=
"#func-lang"><code>fn:lang</code></a>(<code>$testlang</code><code>&#160;as&#160;</code><code>
xs:string?</code>)<code>&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-lang"><code>fn:lang</code></a>(<code>$testlang</code><code>&#160;as&#160;</code><code>
xs:string?</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">14.6 op:is-same-node</dt>
<dd>
<div class="protoref"><a href=
"#func-is-same-node"><code>op:is-same-node</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">14.7 op:node-before</dt>
<dd>
<div class="protoref"><a href=
"#func-node-before"><code>op:node-before</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">14.8 op:node-after</dt>
<dd>
<div class="protoref"><a href=
"#func-node-after"><code>op:node-after</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
</dd>
<dt class="label">14.9 fn:root</dt>
<dd>
<div class="protoref"><a href=
"#func-root"><code>fn:root</code></a>()<code>&#160;as&#160;</code><code>
node()</code></div>
<div class="protoref"><a href=
"#func-root"><code>fn:root</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>node()?</code></div>
</dd>
</dl>
</dd>
<dt class="label">15 Functions and Operators on Sequences</dt>
<dd>
<dl>
<dt class="label">15.1 General Functions and Operators on
Sequences</dt>
<dd>
<div class="protoref"><a href=
"#func-boolean"><code>fn:boolean</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-concatenate"><code>op:concatenate</code></a>(<code>$seq1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$seq2</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-index-of"><code>fn:index-of</code></a>(<code>$seqParam</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$srchParam</code><code>&#160;as&#160;</code><code>xs:anyAtomicType</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code></div>
<div class="protoref"><a href=
"#func-index-of"><code>fn:index-of</code></a>(<code>$seqParam</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$srchParam</code><code>&#160;as&#160;</code><code>xs:anyAtomicType</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code></div>
<div class="protoref"><a href=
"#func-empty"><code>fn:empty</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-exists"><code>fn:exists</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-distinct-values"><code>fn:distinct-values</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code></div>
<div class="protoref"><a href=
"#func-distinct-values"><code>fn:distinct-values</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code></div>
<div class="protoref"><a href=
"#func-insert-before"><code>fn:insert-before</code></a>(<code>$target</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$position</code><code>&#160;as&#160;</code><code>xs:integer</code>,
<code>$inserts</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-remove"><code>fn:remove</code></a>(<code>$target</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$position</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-reverse"><code>fn:reverse</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-subsequence"><code>fn:subsequence</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-subsequence"><code>fn:subsequence</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>,
<code>$length</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>item()*</code></div>
<div class="protoref"><a href=
"#func-unordered"><code>fn:unordered</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()*</code></div>
</dd>
<dt class="label">15.2 Functions That Test the Cardinality of
Sequences</dt>
<dd>
<div class="protoref"><a href=
"#func-zero-or-one"><code>fn:zero-or-one</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()?</code></div>
<div class="protoref"><a href=
"#func-one-or-more"><code>fn:one-or-more</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()+</code></div>
<div class="protoref"><a href=
"#func-exactly-one"><code>fn:exactly-one</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()</code></div>
</dd>
<dt class="label">15.3 Equals, Union, Intersection and Except</dt>
<dd>
<div class="protoref"><a href=
"#func-deep-equal"><code>fn:deep-equal</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-deep-equal"><code>fn:deep-equal</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>item()*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code></div>
<div class="protoref"><a href=
"#func-union"><code>op:union</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code></div>
<div class="protoref"><a href=
"#func-intersect"><code>op:intersect</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code></div>
<div class="protoref"><a href=
"#func-except"><code>op:except</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code></div>
</dd>
<dt class="label">15.4 Aggregate Functions</dt>
<dd>
<div class="protoref"><a href=
"#func-count"><code>fn:count</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:integer</code></div>
<div class="protoref"><a href=
"#func-avg"><code>fn:avg</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
<div class="protoref"><a href=
"#func-max"><code>fn:max</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
<div class="protoref"><a href=
"#func-max"><code>fn:max</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
<div class="protoref"><a href=
"#func-min"><code>fn:min</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
<div class="protoref"><a href=
"#func-min"><code>fn:min</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
<div class="protoref"><a href=
"#func-sum"><code>fn:sum</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType</code></div>
<div class="protoref"><a href=
"#func-sum"><code>fn:sum</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$zero</code><code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code></div>
</dd>
<dt class="label">15.5 Functions and Operators that Generate
Sequences</dt>
<dd>
<div class="protoref"><a href=
"#func-to"><code>op:to</code></a>(<code>$firstval</code><code>&#160;as&#160;</code><code>
xs:integer</code>,
<code>$lastval</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code></div>
<div class="protoref"><a href=
"#func-id"><code>fn:id</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>)<code>&#160;as&#160;</code><code>element()*</code></div>
<div class="protoref"><a href=
"#func-id"><code>fn:id</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>element()*</code></div>
<div class="protoref"><a href=
"#func-idref"><code>fn:idref</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>)<code>&#160;as&#160;</code><code>node()*</code></div>
<div class="protoref"><a href=
"#func-idref"><code>fn:idref</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>node()*</code></div>
<div class="protoref"><a href=
"#func-doc"><code>fn:doc</code></a>(<code>$uri</code><code>&#160;as&#160;</code><code>
xs:string?</code>)<code>&#160;as&#160;</code><code>document-node()?</code></div>
<div class="protoref"><a href=
"#func-doc-available"><code>fn:doc-available</code></a>(<code>$uri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:boolean</code></div>
<div class="protoref"><a href=
"#func-collection"><code>fn:collection</code></a>()<code>&#160;as&#160;</code><code>
node()*</code></div>
<div class="protoref"><a href=
"#func-collection"><code>fn:collection</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
node()*</code></div>
</dd>
</dl>
</dd>
<dt class="label">16 Context Functions</dt>
<dd>
<dl>
<dt class="label">16.1 fn:position</dt>
<dd>
<div class="protoref"><a href=
"#func-position"><code>fn:position</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code></div>
</dd>
<dt class="label">16.2 fn:last</dt>
<dd>
<div class="protoref"><a href=
"#func-last"><code>fn:last</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code></div>
</dd>
<dt class="label">16.3 fn:current-dateTime</dt>
<dd>
<div class="protoref"><a href=
"#func-current-dateTime"><code>fn:current-dateTime</code></a>()<code>
&#160;as&#160;</code><code>xs:dateTime</code></div>
</dd>
<dt class="label">16.4 fn:current-date</dt>
<dd>
<div class="protoref"><a href=
"#func-current-date"><code>fn:current-date</code></a>()<code>&#160;as&#160;</code><code>
xs:date</code></div>
</dd>
<dt class="label">16.5 fn:current-time</dt>
<dd>
<div class="protoref"><a href=
"#func-current-time"><code>fn:current-time</code></a>()<code>&#160;as&#160;</code><code>
xs:time</code></div>
</dd>
<dt class="label">16.6 fn:implicit-timezone</dt>
<dd>
<div class="protoref"><a href=
"#func-implicit-timezone"><code>fn:implicit-timezone</code></a>()<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code></div>
</dd>
<dt class="label">16.7 fn:default-collation</dt>
<dd>
<div class="protoref"><a href=
"#func-default-collation"><code>fn:default-collation</code></a>()<code>
&#160;as&#160;</code><code>xs:string</code></div>
</dd>
<dt class="label">16.8 fn:static-base-uri</dt>
<dd>
<div class="protoref"><a href=
"#func-static-base-uri"><code>fn:static-base-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI?</code></div>
</dd>
</dl>
</dd>
</dl>
</div>
<div class="div2">
<h3><a name="quickref-alpha" id="quickref-alpha"></a>G.2 Functions
and Operators Alphabetically</h3>
<div class="protoref"><a href=
"#func-abs"><code>fn:abs</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code>
<a href="#func-abs">6.4.1</a>)</div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-date"><code>op:add-dayTimeDuration-to-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code><a href=
"#func-add-dayTimeDuration-to-date">10.8.9</a>)</div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-dateTime"><code>op:add-dayTimeDuration-to-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code><a href=
"#func-add-dayTimeDuration-to-dateTime">10.8.5</a>)</div>
<div class="protoref"><a href=
"#func-add-dayTimeDuration-to-time"><code>op:add-dayTimeDuration-to-time</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:time</code><a href=
"#func-add-dayTimeDuration-to-time">10.8.12</a>)</div>
<div class="protoref"><a href=
"#func-add-dayTimeDurations"><code>op:add-dayTimeDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-add-dayTimeDurations">10.6.6</a>)</div>
<div class="protoref"><a href=
"#func-add-yearMonthDuration-to-date"><code>op:add-yearMonthDuration-to-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code><a href=
"#func-add-yearMonthDuration-to-date">10.8.8</a>)</div>
<div class="protoref"><a href=
"#func-add-yearMonthDuration-to-dateTime"><code>op:add-yearMonthDuration-to-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code><a href=
"#func-add-yearMonthDuration-to-dateTime">10.8.4</a>)</div>
<div class="protoref"><a href=
"#func-add-yearMonthDurations"><code>op:add-yearMonthDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code><a href=
"#func-add-yearMonthDurations">10.6.1</a>)</div>
<div class="protoref"><a href=
"#func-adjust-date-to-timezone"><code>fn:adjust-date-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:date?</code><a href=
"#func-adjust-date-to-timezone">10.7.2</a>)</div>
<div class="protoref"><a href=
"#func-adjust-date-to-timezone"><code>fn:adjust-date-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:date?</code><a href=
"#func-adjust-date-to-timezone">10.7.2</a>)</div>
<div class="protoref"><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code><a href=
"#func-adjust-dateTime-to-timezone">10.7.1</a>)</div>
<div class="protoref"><a href=
"#func-adjust-dateTime-to-timezone"><code>fn:adjust-dateTime-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code><a href=
"#func-adjust-dateTime-to-timezone">10.7.1</a>)</div>
<div class="protoref"><a href=
"#func-adjust-time-to-timezone"><code>fn:adjust-time-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:time?</code><a href=
"#func-adjust-time-to-timezone">10.7.3</a>)</div>
<div class="protoref"><a href=
"#func-adjust-time-to-timezone"><code>fn:adjust-time-to-timezone</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>,
<code>$timezone</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration?</code>)<code>
&#160;as&#160;</code><code>xs:time?</code><a href=
"#func-adjust-time-to-timezone">10.7.3</a>)</div>
<div class="protoref"><a href=
"#func-avg"><code>fn:avg</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>
<a href="#func-avg">15.4.2</a>)</div>
<div class="protoref"><a href=
"#func-base-uri"><code>fn:base-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href="#func-base-uri">2.5</a>)</div>
<div class="protoref"><a href=
"#func-base-uri"><code>fn:base-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href="#func-base-uri">2.5</a>)</div>
<div class="protoref"><a href=
"#func-base64Binary-equal"><code>op:base64Binary-equal</code></a>(<code>
$value1</code><code>&#160;as&#160;</code><code>xs:base64Binary</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:base64Binary</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-base64Binary-equal">12.1.2</a>)</div>
<div class="protoref"><a href=
"#func-boolean"><code>fn:boolean</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code>
<a href="#func-boolean">15.1.1</a>)</div>
<div class="protoref"><a href=
"#func-boolean-equal"><code>op:boolean-equal</code></a>(<code>$value1</code><code>
&#160;as&#160;</code><code>xs:boolean</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-boolean-equal">9.2.1</a>)</div>
<div class="protoref"><a href=
"#func-boolean-greater-than"><code>op:boolean-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:boolean</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-boolean-greater-than">9.2.3</a>)</div>
<div class="protoref"><a href=
"#func-boolean-less-than"><code>op:boolean-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:boolean</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:boolean</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-boolean-less-than">9.2.2</a>)</div>
<div class="protoref"><a href=
"#func-ceiling"><code>fn:ceiling</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code>
<a href="#func-ceiling">6.4.2</a>)</div>
<div class="protoref"><a href=
"#func-codepoint-equal"><code>fn:codepoint-equal</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean?</code><a href=
"#func-codepoint-equal">7.3.3</a>)</div>
<div class="protoref"><a href=
"#func-codepoints-to-string"><code>fn:codepoints-to-string</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:integer*</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-codepoints-to-string">7.2.1</a>)</div>
<div class="protoref"><a href=
"#func-collection"><code>fn:collection</code></a>()<code>&#160;as&#160;</code><code>
node()*</code><a href="#func-collection">15.5.6</a>)</div>
<div class="protoref"><a href=
"#func-collection"><code>fn:collection</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
node()*</code><a href="#func-collection">15.5.6</a>)</div>
<div class="protoref"><a href=
"#func-compare"><code>fn:compare</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-compare">7.3.2</a>)</div>
<div class="protoref"><a href=
"#func-compare"><code>fn:compare</code></a>(<code>$comparand1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$comparand2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-compare">7.3.2</a>)</div>
<div class="protoref"><a href=
"#func-concat"><code>fn:concat</code></a>(<code>$arg1</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>,
<span class=
"varargs">...</span>)<code>&#160;as&#160;</code><code>xs:string</code>
<a href="#func-concat">7.4.1</a>)</div>
<div class="protoref"><a href=
"#func-concatenate"><code>op:concatenate</code></a>(<code>$seq1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$seq2</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-concatenate">15.1.2</a>)</div>
<div class="protoref"><a href=
"#func-contains"><code>fn:contains</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-contains">7.5.1</a>)</div>
<div class="protoref"><a href=
"#func-contains"><code>fn:contains</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-contains">7.5.1</a>)</div>
<div class="protoref"><a href=
"#func-count"><code>fn:count</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:integer</code>
<a href="#func-count">15.4.1</a>)</div>
<div class="protoref"><a href=
"#func-current-date"><code>fn:current-date</code></a>()<code>&#160;as&#160;</code><code>
xs:date</code><a href="#func-current-date">16.4</a>)</div>
<div class="protoref"><a href=
"#func-current-dateTime"><code>fn:current-dateTime</code></a>()<code>
&#160;as&#160;</code><code>xs:dateTime</code><a href=
"#func-current-dateTime">16.3</a>)</div>
<div class="protoref"><a href=
"#func-current-time"><code>fn:current-time</code></a>()<code>&#160;as&#160;</code><code>
xs:time</code><a href="#func-current-time">16.5</a>)</div>
<div class="protoref"><a href=
"#func-data"><code>fn:data</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType*</code>
<a href="#func-data">2.4</a>)</div>
<div class="protoref"><a href=
"#func-date-equal"><code>op:date-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-date-equal">10.4.9</a>)</div>
<div class="protoref"><a href=
"#func-date-greater-than"><code>op:date-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-date-greater-than">10.4.11</a>)</div>
<div class="protoref"><a href=
"#func-date-less-than"><code>op:date-less-than</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-date-less-than">10.4.10</a>)</div>
<div class="protoref"><a href=
"#func-dateTime"><code>fn:dateTime</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>
&#160;as&#160;</code><code>xs:dateTime?</code><a href=
"#func-dateTime">5.2</a>)</div>
<div class="protoref"><a href=
"#func-dateTime-equal"><code>op:dateTime-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-dateTime-equal">10.4.6</a>)</div>
<div class="protoref"><a href=
"#func-dateTime-greater-than"><code>op:dateTime-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-dateTime-greater-than">10.4.8</a>)</div>
<div class="protoref"><a href=
"#func-dateTime-less-than"><code>op:dateTime-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-dateTime-less-than">10.4.7</a>)</div>
<div class="protoref"><a href=
"#func-day-from-date"><code>fn:day-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code><a href=
"#func-day-from-date">10.5.16</a>)</div>
<div class="protoref"><a href=
"#func-day-from-dateTime"><code>fn:day-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-day-from-dateTime">10.5.9</a>)</div>
<div class="protoref"><a href=
"#func-days-from-duration"><code>fn:days-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-days-from-duration">10.5.3</a>)</div>
<div class="protoref"><a href=
"#func-dayTimeDuration-greater-than"><code>op:dayTimeDuration-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-dayTimeDuration-greater-than">10.4.4</a>)</div>
<div class="protoref"><a href=
"#func-dayTimeDuration-less-than"><code>op:dayTimeDuration-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-dayTimeDuration-less-than">10.4.3</a>)</div>
<div class="protoref"><a href=
"#func-deep-equal"><code>fn:deep-equal</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-deep-equal">15.3.1</a>)</div>
<div class="protoref"><a href=
"#func-deep-equal"><code>fn:deep-equal</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>item()*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-deep-equal">15.3.1</a>)</div>
<div class="protoref"><a href=
"#func-default-collation"><code>fn:default-collation</code></a>()<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-default-collation">16.7</a>)</div>
<div class="protoref"><a href=
"#func-distinct-values"><code>fn:distinct-values</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code><a href=
"#func-distinct-values">15.1.6</a>)</div>
<div class="protoref"><a href=
"#func-distinct-values"><code>fn:distinct-values</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code><a href=
"#func-distinct-values">15.1.6</a>)</div>
<div class="protoref"><a href=
"#func-divide-dayTimeDuration"><code>op:divide-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-divide-dayTimeDuration">10.6.9</a>)</div>
<div class="protoref"><a href=
"#func-divide-dayTimeDuration-by-dayTimeDuration"><code>op:divide-dayTimeDuration-by-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:decimal</code><a href=
"#func-divide-dayTimeDuration-by-dayTimeDuration">10.6.10</a>)</div>
<div class="protoref"><a href=
"#func-divide-yearMonthDuration"><code>op:divide-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code><a href=
"#func-divide-yearMonthDuration">10.6.4</a>)</div>
<div class="protoref"><a href=
"#func-divide-yearMonthDuration-by-yearMonthDuration"><code>op:divide-yearMonthDuration-by-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:decimal</code><a href=
"#func-divide-yearMonthDuration-by-yearMonthDuration">10.6.5</a>)</div>
<div class="protoref"><a href=
"#func-doc"><code>fn:doc</code></a>(<code>$uri</code><code>&#160;as&#160;</code><code>
xs:string?</code>)<code>&#160;as&#160;</code><code>document-node()?</code>
<a href="#func-doc">15.5.4</a>)</div>
<div class="protoref"><a href=
"#func-doc-available"><code>fn:doc-available</code></a>(<code>$uri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:boolean</code><a href="#func-doc-available">15.5.5</a>)</div>
<div class="protoref"><a href=
"#func-document-uri"><code>fn:document-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href="#func-document-uri">2.6</a>)</div>
<div class="protoref"><a href=
"#func-duration-equal"><code>op:duration-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:duration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:duration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-duration-equal">10.4.5</a>)</div>
<div class="protoref"><a href=
"#func-empty"><code>fn:empty</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code>
<a href="#func-empty">15.1.4</a>)</div>
<div class="protoref"><a href=
"#func-encode-for-uri"><code>fn:encode-for-uri</code></a>(<code>$uri-part</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-encode-for-uri">7.4.10</a>)</div>
<div class="protoref"><a href=
"#func-ends-with"><code>fn:ends-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-ends-with">7.5.3</a>)</div>
<div class="protoref"><a href=
"#func-ends-with"><code>fn:ends-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-ends-with">7.5.3</a>)</div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>()<code>&#160;as&#160;</code><code>
none</code><a href="#func-error">3</a>)</div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName</code>)<code>&#160;as&#160;</code><code>none</code>
<a href="#func-error">3</a>)</div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName?</code>,
<code>$description</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>none</code><a href=
"#func-error">3</a>)</div>
<div class="protoref"><a href=
"#func-error"><code>fn:error</code></a>(<code>$error</code><code>&#160;as&#160;</code><code>
xs:QName?</code>,
<code>$description</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$error-object</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>none</code><a href=
"#func-error">3</a>)</div>
<div class="protoref"><a href=
"#func-escape-html-uri"><code>fn:escape-html-uri</code></a>(<code>$uri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href=
"#func-escape-html-uri">7.4.12</a>)</div>
<div class="protoref"><a href=
"#func-exactly-one"><code>fn:exactly-one</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()</code><a href="#func-exactly-one">15.2.3</a>)</div>
<div class="protoref"><a href=
"#func-except"><code>op:except</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code><a href=
"#func-except">15.3.4</a>)</div>
<div class="protoref"><a href=
"#func-exists"><code>fn:exists</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code>
<a href="#func-exists">15.1.5</a>)</div>
<div class="protoref"><a href=
"#func-false"><code>fn:false</code></a>()<code>&#160;as&#160;</code><code>
xs:boolean</code><a href="#func-false">9.1.2</a>)</div>
<div class="protoref"><a href=
"#func-floor"><code>fn:floor</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code>
<a href="#func-floor">6.4.3</a>)</div>
<div class="protoref"><a href=
"#func-gDay-equal"><code>op:gDay-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gDay</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gDay</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-gDay-equal">10.4.19</a>)</div>
<div class="protoref"><a href=
"#func-gMonth-equal"><code>op:gMonth-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gMonth</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gMonth</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-gMonth-equal">10.4.18</a>)</div>
<div class="protoref"><a href=
"#func-gMonthDay-equal"><code>op:gMonthDay-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gMonthDay</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gMonthDay</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-gMonthDay-equal">10.4.17</a>)</div>
<div class="protoref"><a href=
"#func-gYear-equal"><code>op:gYear-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:gYear</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gYear</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-gYear-equal">10.4.16</a>)</div>
<div class="protoref"><a href=
"#func-gYearMonth-equal"><code>op:gYearMonth-equal</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:gYearMonth</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:gYearMonth</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-gYearMonth-equal">10.4.15</a>)</div>
<div class="protoref"><a href=
"#func-hexBinary-equal"><code>op:hexBinary-equal</code></a>(<code>$value1</code><code>
&#160;as&#160;</code><code>xs:hexBinary</code>,
<code>$value2</code><code>&#160;as&#160;</code><code>xs:hexBinary</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-hexBinary-equal">12.1.1</a>)</div>
<div class="protoref"><a href=
"#func-hours-from-dateTime"><code>fn:hours-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-hours-from-dateTime">10.5.10</a>)</div>
<div class="protoref"><a href=
"#func-hours-from-duration"><code>fn:hours-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-hours-from-duration">10.5.4</a>)</div>
<div class="protoref"><a href=
"#func-hours-from-time"><code>fn:hours-from-time</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code><a href=
"#func-hours-from-time">10.5.18</a>)</div>
<div class="protoref"><a href=
"#func-id"><code>fn:id</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>)<code>&#160;as&#160;</code><code>element()*</code>
<a href="#func-id">15.5.2</a>)</div>
<div class="protoref"><a href=
"#func-id"><code>fn:id</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>element()*</code><a href=
"#func-id">15.5.2</a>)</div>
<div class="protoref"><a href=
"#func-idref"><code>fn:idref</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>)<code>&#160;as&#160;</code><code>node()*</code>
<a href="#func-idref">15.5.3</a>)</div>
<div class="protoref"><a href=
"#func-idref"><code>fn:idref</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:string*</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>node()*</code><a href=
"#func-idref">15.5.3</a>)</div>
<div class="protoref"><a href=
"#func-implicit-timezone"><code>fn:implicit-timezone</code></a>()<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-implicit-timezone">16.6</a>)</div>
<div class="protoref"><a href=
"#func-in-scope-prefixes"><code>fn:in-scope-prefixes</code></a>(<code>
$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:string*</code><a href=
"#func-in-scope-prefixes">11.2.6</a>)</div>
<div class="protoref"><a href=
"#func-index-of"><code>fn:index-of</code></a>(<code>$seqParam</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$srchParam</code><code>&#160;as&#160;</code><code>xs:anyAtomicType</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code><a href=
"#func-index-of">15.1.3</a>)</div>
<div class="protoref"><a href=
"#func-index-of"><code>fn:index-of</code></a>(<code>$seqParam</code><code>
&#160;as&#160;</code><code>xs:anyAtomicType*</code>,
<code>$srchParam</code><code>&#160;as&#160;</code><code>xs:anyAtomicType</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code><a href=
"#func-index-of">15.1.3</a>)</div>
<div class="protoref"><a href=
"#func-insert-before"><code>fn:insert-before</code></a>(<code>$target</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$position</code><code>&#160;as&#160;</code><code>xs:integer</code>,
<code>$inserts</code><code>&#160;as&#160;</code><code>item()*</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-insert-before">15.1.7</a>)</div>
<div class="protoref"><a href=
"#func-intersect"><code>op:intersect</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code><a href=
"#func-intersect">15.3.3</a>)</div>
<div class="protoref"><a href=
"#func-iri-to-uri"><code>fn:iri-to-uri</code></a>(<code>$iri</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-iri-to-uri">7.4.11</a>)</div>
<div class="protoref"><a href=
"#func-is-same-node"><code>op:is-same-node</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-is-same-node">14.6</a>)</div>
<div class="protoref"><a href=
"#func-lang"><code>fn:lang</code></a>(<code>$testlang</code><code>&#160;as&#160;</code><code>
xs:string?</code>)<code>&#160;as&#160;</code><code>xs:boolean</code>
<a href="#func-lang">14.5</a>)</div>
<div class="protoref"><a href=
"#func-lang"><code>fn:lang</code></a>(<code>$testlang</code><code>&#160;as&#160;</code><code>
xs:string?</code>,
<code>$node</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-lang">14.5</a>)</div>
<div class="protoref"><a href=
"#func-last"><code>fn:last</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code><a href="#func-last">16.2</a>)</div>
<div class="protoref"><a href=
"#func-local-name"><code>fn:local-name</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-local-name">14.2</a>)</div>
<div class="protoref"><a href=
"#func-local-name"><code>fn:local-name</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-local-name">14.2</a>)</div>
<div class="protoref"><a href=
"#func-local-name-from-QName"><code>fn:local-name-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:NCName?</code><a href=
"#func-local-name-from-QName">11.2.3</a>)</div>
<div class="protoref"><a href=
"#func-lower-case"><code>fn:lower-case</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-lower-case">7.4.8</a>)</div>
<div class="protoref"><a href=
"#func-matches"><code>fn:matches</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-matches">7.6.2</a>)</div>
<div class="protoref"><a href=
"#func-matches"><code>fn:matches</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-matches">7.6.2</a>)</div>
<div class="protoref"><a href=
"#func-max"><code>fn:max</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>
<a href="#func-max">15.4.3</a>)</div>
<div class="protoref"><a href=
"#func-max"><code>fn:max</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code><a href=
"#func-max">15.4.3</a>)</div>
<div class="protoref"><a href=
"#func-min"><code>fn:min</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>
<a href="#func-min">15.4.4</a>)</div>
<div class="protoref"><a href=
"#func-min"><code>fn:min</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>string</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code><a href=
"#func-min">15.4.4</a>)</div>
<div class="protoref"><a href=
"#func-minutes-from-dateTime"><code>fn:minutes-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-minutes-from-dateTime">10.5.11</a>)</div>
<div class="protoref"><a href=
"#func-minutes-from-duration"><code>fn:minutes-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-minutes-from-duration">10.5.5</a>)</div>
<div class="protoref"><a href=
"#func-minutes-from-time"><code>fn:minutes-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code><a href=
"#func-minutes-from-time">10.5.19</a>)</div>
<div class="protoref"><a href=
"#func-month-from-date"><code>fn:month-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code><a href=
"#func-month-from-date">10.5.15</a>)</div>
<div class="protoref"><a href=
"#func-month-from-dateTime"><code>fn:month-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-month-from-dateTime">10.5.8</a>)</div>
<div class="protoref"><a href=
"#func-months-from-duration"><code>fn:months-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-months-from-duration">10.5.2</a>)</div>
<div class="protoref"><a href=
"#func-multiply-dayTimeDuration"><code>op:multiply-dayTimeDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-multiply-dayTimeDuration">10.6.8</a>)</div>
<div class="protoref"><a href=
"#func-multiply-yearMonthDuration"><code>op:multiply-yearMonthDuration</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code><a href=
"#func-multiply-yearMonthDuration">10.6.3</a>)</div>
<div class="protoref"><a href=
"#func-name"><code>fn:name</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-name">14.1</a>)</div>
<div class="protoref"><a href=
"#func-name"><code>fn:name</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>xs:string</code>
<a href="#func-name">14.1</a>)</div>
<div class="protoref"><a href=
"#func-namespace-uri"><code>fn:namespace-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI</code><a href="#func-namespace-uri">14.3</a>)</div>
<div class="protoref"><a href=
"#func-namespace-uri"><code>fn:namespace-uri</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI</code><a href="#func-namespace-uri">14.3</a>)</div>
<div class="protoref"><a href=
"#func-namespace-uri-for-prefix"><code>fn:namespace-uri-for-prefix</code></a>(<code>
$prefix</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:anyURI?</code><a href=
"#func-namespace-uri-for-prefix">11.2.5</a>)</div>
<div class="protoref"><a href=
"#func-namespace-uri-from-QName"><code>fn:namespace-uri-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href=
"#func-namespace-uri-from-QName">11.2.4</a>)</div>
<div class="protoref"><a href=
"#func-nilled"><code>fn:nilled</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>xs:boolean?</code>
<a href="#func-nilled">2.2</a>)</div>
<div class="protoref"><a href=
"#func-node-after"><code>op:node-after</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-node-after">14.8</a>)</div>
<div class="protoref"><a href=
"#func-node-before"><code>op:node-before</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-node-before">14.7</a>)</div>
<div class="protoref"><a href=
"#func-node-name"><code>fn:node-name</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>node()?</code>)<code>&#160;as&#160;</code><code>
xs:QName?</code><a href="#func-node-name">2.1</a>)</div>
<div class="protoref"><a href=
"#func-normalize-space"><code>fn:normalize-space</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-normalize-space">7.4.5</a>)</div>
<div class="protoref"><a href=
"#func-normalize-space"><code>fn:normalize-space</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-normalize-space">7.4.5</a>)</div>
<div class="protoref"><a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-normalize-unicode">7.4.6</a>)</div>
<div class="protoref"><a href=
"#func-normalize-unicode"><code>fn:normalize-unicode</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$normalizationForm</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-normalize-unicode">7.4.6</a>)</div>
<div class="protoref"><a href=
"#func-not"><code>fn:not</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>xs:boolean</code>
<a href="#func-not">9.3.1</a>)</div>
<div class="protoref"><a href=
"#func-NOTATION-equal"><code>op:NOTATION-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:NOTATION</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:NOTATION</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-NOTATION-equal">13.1.1</a>)</div>
<div class="protoref"><a href=
"#func-number"><code>fn:number</code></a>()<code>&#160;as&#160;</code><code>
xs:double</code><a href="#func-number">14.4</a>)</div>
<div class="protoref"><a href=
"#func-number"><code>fn:number</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType?</code>)<code>&#160;as&#160;</code><code>xs:double</code>
<a href="#func-number">14.4</a>)</div>
<div class="protoref"><a href=
"#func-numeric-add"><code>op:numeric-add</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code><a href=
"#func-numeric-add">6.2.1</a>)</div>
<div class="protoref"><a href=
"#func-numeric-divide"><code>op:numeric-divide</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code><a href=
"#func-numeric-divide">6.2.4</a>)</div>
<div class="protoref"><a href=
"#func-numeric-equal"><code>op:numeric-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-numeric-equal">6.3.1</a>)</div>
<div class="protoref"><a href=
"#func-numeric-greater-than"><code>op:numeric-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-numeric-greater-than">6.3.3</a>)</div>
<div class="protoref"><a href=
"#func-numeric-integer-divide"><code>op:numeric-integer-divide</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:integer</code><a href=
"#func-numeric-integer-divide">6.2.5</a>)</div>
<div class="protoref"><a href=
"#func-numeric-less-than"><code>op:numeric-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-numeric-less-than">6.3.2</a>)</div>
<div class="protoref"><a href=
"#func-numeric-mod"><code>op:numeric-mod</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code><a href=
"#func-numeric-mod">6.2.6</a>)</div>
<div class="protoref"><a href=
"#func-numeric-multiply"><code>op:numeric-multiply</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code><a href=
"#func-numeric-multiply">6.2.3</a>)</div>
<div class="protoref"><a href=
"#func-numeric-subtract"><code>op:numeric-subtract</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>numeric</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>numeric</code>)<code>
&#160;as&#160;</code><code>numeric</code><a href=
"#func-numeric-subtract">6.2.2</a>)</div>
<div class="protoref"><a href=
"#func-numeric-unary-minus"><code>op:numeric-unary-minus</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric</code>)<code>&#160;as&#160;</code><code>
numeric</code><a href=
"#func-numeric-unary-minus">6.2.8</a>)</div>
<div class="protoref"><a href=
"#func-numeric-unary-plus"><code>op:numeric-unary-plus</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric</code>)<code>&#160;as&#160;</code><code>
numeric</code><a href=
"#func-numeric-unary-plus">6.2.7</a>)</div>
<div class="protoref"><a href=
"#func-one-or-more"><code>fn:one-or-more</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()+</code><a href="#func-one-or-more">15.2.2</a>)</div>
<div class="protoref"><a href=
"#func-position"><code>fn:position</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code><a href="#func-position">16.1</a>)</div>
<div class="protoref"><a href=
"#func-prefix-from-QName"><code>fn:prefix-from-QName</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:QName?</code>)<code>&#160;as&#160;</code><code>
xs:NCName?</code><a href=
"#func-prefix-from-QName">11.2.2</a>)</div>
<div class="protoref"><a href=
"#func-QName"><code>fn:QName</code></a>(<code>$paramURI</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$paramQName</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:QName</code><a href=
"#func-QName">11.1.2</a>)</div>
<div class="protoref"><a href=
"#func-QName-equal"><code>op:QName-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:QName</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:QName</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-QName-equal">11.2.1</a>)</div>
<div class="protoref"><a href=
"#func-remove"><code>fn:remove</code></a>(<code>$target</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$position</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-remove">15.1.8</a>)</div>
<div class="protoref"><a href=
"#func-replace"><code>fn:replace</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$replacement</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-replace">7.6.3</a>)</div>
<div class="protoref"><a href=
"#func-replace"><code>fn:replace</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$replacement</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-replace">7.6.3</a>)</div>
<div class="protoref"><a href=
"#func-resolve-QName"><code>fn:resolve-QName</code></a>(<code>$qname</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$element</code><code>&#160;as&#160;</code><code>element()</code>)<code>
&#160;as&#160;</code><code>xs:QName?</code><a href=
"#func-resolve-QName">11.1.1</a>)</div>
<div class="protoref"><a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a>(<code>$relative</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href="#func-resolve-uri">8.1</a>)</div>
<div class="protoref"><a href=
"#func-resolve-uri"><code>fn:resolve-uri</code></a>(<code>$relative</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$base</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:anyURI?</code><a href=
"#func-resolve-uri">8.1</a>)</div>
<div class="protoref"><a href=
"#func-reverse"><code>fn:reverse</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()*</code>)<code>&#160;as&#160;</code><code>item()*</code>
<a href="#func-reverse">15.1.9</a>)</div>
<div class="protoref"><a href=
"#func-root"><code>fn:root</code></a>()<code>&#160;as&#160;</code><code>
node()</code><a href="#func-root">14.9</a>)</div>
<div class="protoref"><a href=
"#func-root"><code>fn:root</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
node()?</code>)<code>&#160;as&#160;</code><code>node()?</code>
<a href="#func-root">14.9</a>)</div>
<div class="protoref"><a href=
"#func-round"><code>fn:round</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
numeric?</code>)<code>&#160;as&#160;</code><code>numeric?</code>
<a href="#func-round">6.4.4</a>)</div>
<div class="protoref"><a href=
"#func-round-half-to-even"><code>fn:round-half-to-even</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric?</code>)<code>&#160;as&#160;</code><code>
numeric?</code><a href=
"#func-round-half-to-even">6.4.5</a>)</div>
<div class="protoref"><a href=
"#func-round-half-to-even"><code>fn:round-half-to-even</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>numeric?</code>,
<code>$precision</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>numeric?</code><a href=
"#func-round-half-to-even">6.4.5</a>)</div>
<div class="protoref"><a href=
"#func-seconds-from-dateTime"><code>fn:seconds-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:decimal?</code><a href=
"#func-seconds-from-dateTime">10.5.12</a>)</div>
<div class="protoref"><a href=
"#func-seconds-from-duration"><code>fn:seconds-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:decimal?</code><a href=
"#func-seconds-from-duration">10.5.6</a>)</div>
<div class="protoref"><a href=
"#func-seconds-from-time"><code>fn:seconds-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:decimal?</code><a href=
"#func-seconds-from-time">10.5.20</a>)</div>
<div class="protoref"><a href=
"#func-starts-with"><code>fn:starts-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-starts-with">7.5.2</a>)</div>
<div class="protoref"><a href=
"#func-starts-with"><code>fn:starts-with</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-starts-with">7.5.2</a>)</div>
<div class="protoref"><a href=
"#func-static-base-uri"><code>fn:static-base-uri</code></a>()<code>&#160;as&#160;</code><code>
xs:anyURI?</code><a href="#func-static-base-uri">16.8</a>)</div>
<div class="protoref"><a href=
"#func-string"><code>fn:string</code></a>()<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-string">2.3</a>)</div>
<div class="protoref"><a href=
"#func-string"><code>fn:string</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
item()?</code>)<code>&#160;as&#160;</code><code>xs:string</code>
<a href="#func-string">2.3</a>)</div>
<div class="protoref"><a href=
"#func-string-join"><code>fn:string-join</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string*</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-string-join">7.4.2</a>)</div>
<div class="protoref"><a href=
"#func-string-length"><code>fn:string-length</code></a>()<code>&#160;as&#160;</code><code>
xs:integer</code><a href="#func-string-length">7.4.4</a>)</div>
<div class="protoref"><a href=
"#func-string-length"><code>fn:string-length</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:integer</code><a href="#func-string-length">7.4.4</a>)</div>
<div class="protoref"><a href=
"#func-string-to-codepoints"><code>fn:string-to-codepoints</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code><a href=
"#func-string-to-codepoints">7.2.2</a>)</div>
<div class="protoref"><a href=
"#func-subsequence"><code>fn:subsequence</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-subsequence">15.1.10</a>)</div>
<div class="protoref"><a href=
"#func-subsequence"><code>fn:subsequence</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>,
<code>$length</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-subsequence">15.1.10</a>)</div>
<div class="protoref"><a href=
"#func-substring"><code>fn:substring</code></a>(<code>$sourceString</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring">7.4.3</a>)</div>
<div class="protoref"><a href=
"#func-substring"><code>fn:substring</code></a>(<code>$sourceString</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$startingLoc</code><code>&#160;as&#160;</code><code>xs:double</code>,
<code>$length</code><code>&#160;as&#160;</code><code>xs:double</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring">7.4.3</a>)</div>
<div class="protoref"><a href=
"#func-substring-after"><code>fn:substring-after</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring-after">7.5.5</a>)</div>
<div class="protoref"><a href=
"#func-substring-after"><code>fn:substring-after</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring-after">7.5.5</a>)</div>
<div class="protoref"><a href=
"#func-substring-before"><code>fn:substring-before</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring-before">7.5.4</a>)</div>
<div class="protoref"><a href=
"#func-substring-before"><code>fn:substring-before</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:string?</code>,
<code>$collation</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-substring-before">7.5.4</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dates"><code>op:subtract-dates</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:date</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code><a href=
"#func-subtract-dates">10.8.2</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dateTimes"><code>op:subtract-dateTimes</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dateTime</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code><a href=
"#func-subtract-dateTimes">10.8.1</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-date"><code>op:subtract-dayTimeDuration-from-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code><a href=
"#func-subtract-dayTimeDuration-from-date">10.8.11</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-dateTime"><code>op:subtract-dayTimeDuration-from-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code><a href=
"#func-subtract-dayTimeDuration-from-dateTime">10.8.7</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDuration-from-time"><code>op:subtract-dayTimeDuration-from-time</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:time</code><a href=
"#func-subtract-dayTimeDuration-from-time">10.8.13</a>)</div>
<div class="protoref"><a href=
"#func-subtract-dayTimeDurations"><code>op:subtract-dayTimeDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:dayTimeDuration</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-subtract-dayTimeDurations">10.6.7</a>)</div>
<div class="protoref"><a href=
"#func-subtract-times"><code>op:subtract-times</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration</code><a href=
"#func-subtract-times">10.8.3</a>)</div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDuration-from-date"><code>op:subtract-yearMonthDuration-from-date</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:date</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:date</code><a href=
"#func-subtract-yearMonthDuration-from-date">10.8.10</a>)</div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDuration-from-dateTime"><code>op:subtract-yearMonthDuration-from-dateTime</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:dateTime</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:dateTime</code><a href=
"#func-subtract-yearMonthDuration-from-dateTime">10.8.6</a>)</div>
<div class="protoref"><a href=
"#func-subtract-yearMonthDurations"><code>op:subtract-yearMonthDurations</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:yearMonthDuration</code><a href=
"#func-subtract-yearMonthDurations">10.6.2</a>)</div>
<div class="protoref"><a href=
"#func-sum"><code>fn:sum</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>)<code>&#160;as&#160;</code><code>xs:anyAtomicType</code>
<a href="#func-sum">15.4.5</a>)</div>
<div class="protoref"><a href=
"#func-sum"><code>fn:sum</code></a>(<code>$arg</code><code>&#160;as&#160;</code><code>
xs:anyAtomicType*</code>,
<code>$zero</code><code>&#160;as&#160;</code><code>xs:anyAtomicType?</code>)<code>
&#160;as&#160;</code><code>xs:anyAtomicType?</code><a href=
"#func-sum">15.4.5</a>)</div>
<div class="protoref"><a href=
"#func-time-equal"><code>op:time-equal</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-time-equal">10.4.12</a>)</div>
<div class="protoref"><a href=
"#func-time-greater-than"><code>op:time-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-time-greater-than">10.4.14</a>)</div>
<div class="protoref"><a href=
"#func-time-less-than"><code>op:time-less-than</code></a>(<code>$arg1</code><code>
&#160;as&#160;</code><code>xs:time</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:time</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-time-less-than">10.4.13</a>)</div>
<div class="protoref"><a href=
"#func-timezone-from-date"><code>fn:timezone-from-date</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:dayTimeDuration?</code><a href=
"#func-timezone-from-date">10.5.17</a>)</div>
<div class="protoref"><a href=
"#func-timezone-from-dateTime"><code>fn:timezone-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:dayTimeDuration?</code><a href=
"#func-timezone-from-dateTime">10.5.13</a>)</div>
<div class="protoref"><a href=
"#func-timezone-from-time"><code>fn:timezone-from-time</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:time?</code>)<code>&#160;as&#160;</code><code>
xs:dayTimeDuration?</code><a href=
"#func-timezone-from-time">10.5.21</a>)</div>
<div class="protoref"><a href=
"#func-to"><code>op:to</code></a>(<code>$firstval</code><code>&#160;as&#160;</code><code>
xs:integer</code>,
<code>$lastval</code><code>&#160;as&#160;</code><code>xs:integer</code>)<code>
&#160;as&#160;</code><code>xs:integer*</code><a href=
"#func-to">15.5.1</a>)</div>
<div class="protoref"><a href=
"#func-tokenize"><code>fn:tokenize</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string*</code><a href=
"#func-tokenize">7.6.4</a>)</div>
<div class="protoref"><a href=
"#func-tokenize"><code>fn:tokenize</code></a>(<code>$input</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$pattern</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$flags</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string*</code><a href=
"#func-tokenize">7.6.4</a>)</div>
<div class="protoref"><a href=
"#func-trace"><code>fn:trace</code></a>(<code>$value</code><code>&#160;as&#160;</code><code>
item()*</code>,
<code>$label</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>item()*</code><a href=
"#func-trace">4</a>)</div>
<div class="protoref"><a href=
"#func-translate"><code>fn:translate</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>,
<code>$mapString</code><code>&#160;as&#160;</code><code>xs:string</code>,
<code>$transString</code><code>&#160;as&#160;</code><code>xs:string</code>)<code>
&#160;as&#160;</code><code>xs:string</code><a href=
"#func-translate">7.4.9</a>)</div>
<div class="protoref"><a href=
"#func-true"><code>fn:true</code></a>()<code>&#160;as&#160;</code><code>
xs:boolean</code><a href="#func-true">9.1.1</a>)</div>
<div class="protoref"><a href=
"#func-union"><code>op:union</code></a>(<code>$parameter1</code><code>
&#160;as&#160;</code><code>node()*</code>,
<code>$parameter2</code><code>&#160;as&#160;</code><code>node()*</code>)<code>
&#160;as&#160;</code><code>node()*</code><a href=
"#func-union">15.3.2</a>)</div>
<div class="protoref"><a href=
"#func-unordered"><code>fn:unordered</code></a>(<code>$sourceSeq</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()*</code><a href="#func-unordered">15.1.11</a>)</div>
<div class="protoref"><a href=
"#func-upper-case"><code>fn:upper-case</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:string?</code>)<code>&#160;as&#160;</code><code>
xs:string</code><a href="#func-upper-case">7.4.7</a>)</div>
<div class="protoref"><a href=
"#func-year-from-date"><code>fn:year-from-date</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>xs:date?</code>)<code>&#160;as&#160;</code><code>
xs:integer?</code><a href=
"#func-year-from-date">10.5.14</a>)</div>
<div class="protoref"><a href=
"#func-year-from-dateTime"><code>fn:year-from-dateTime</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:dateTime?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-year-from-dateTime">10.5.7</a>)</div>
<div class="protoref"><a href=
"#func-yearMonthDuration-greater-than"><code>op:yearMonthDuration-greater-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-yearMonthDuration-greater-than">10.4.2</a>)</div>
<div class="protoref"><a href=
"#func-yearMonthDuration-less-than"><code>op:yearMonthDuration-less-than</code></a>(<code>
$arg1</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>,
<code>$arg2</code><code>&#160;as&#160;</code><code>xs:yearMonthDuration</code>)<code>
&#160;as&#160;</code><code>xs:boolean</code><a href=
"#func-yearMonthDuration-less-than">10.4.1</a>)</div>
<div class="protoref"><a href=
"#func-years-from-duration"><code>fn:years-from-duration</code></a>(<code>
$arg</code><code>&#160;as&#160;</code><code>xs:duration?</code>)<code>
&#160;as&#160;</code><code>xs:integer?</code><a href=
"#func-years-from-duration">10.5.1</a>)</div>
<div class="protoref"><a href=
"#func-zero-or-one"><code>fn:zero-or-one</code></a>(<code>$arg</code><code>
&#160;as&#160;</code><code>item()*</code>)<code>&#160;as&#160;</code><code>
item()?</code><a href="#func-zero-or-one">15.2.1</a>)</div>
</div>
</div>
</div>
</body>
</html>