<!--
<?xml-stylesheet type="text/xsl" href="E:\XMLdocs\XML Query Language (XQuery)\Functions and Operators\Current Functions and Operators Build Files\xquery-operators.xsl"?> --><spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" w3c-doctype="cr" status="ext-review">
    <header>
        <title>XQuery 1.0 and XPath 2.0 Functions and Operators</title>
        <version/>
        <w3c-designation>CR-xpath-functions</w3c-designation>
        <w3c-doctype>W3C Candidate Recommendation</w3c-doctype>
        <pubdate>
            <day>8</day>
            <month>June</month>
            <year>2006</year>
        </pubdate>
        <publoc>
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/CR-xpath-functions-20060608/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2006/CR-xpath-functions-20060608/</loc>
        </publoc>
  <altlocs>
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/CR-xpath-functions-20060608/xpath-functions.xml" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML</loc>
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/CR-xpath-functions-20060608/diff-from-20051103.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Recent revisions</loc>
  </altlocs>
        <latestloc>
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/xpath-functions/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xpath-functions/</loc>
        </latestloc>
        <prevlocs>
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xpath-functions-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2005/CR-xpath-functions-20051103/</loc>
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/WD-xpath-functions-20050404/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2005/WD-xpath-functions-20050404/</loc>
        </prevlocs>
        <authlist>
            <author>
                <name>Ashok Malhotra (XML Query and XSL WGs)</name>
                <affiliation>Oracle Corporation</affiliation>
                <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:ashok.malhotra@alum.mit.edu" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">ashok.malhotra@alum.mit.edu</email>
            </author>
            <author>
                <name>Jim Melton (XML Query WG)</name>
                <affiliation>Oracle Corporation</affiliation>
                <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:jim.melton@acm.org" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">jim.melton@acm.org</email>
            </author>
            <author>
                <name>Norman Walsh (XSL WG)</name>
                <affiliation>Sun Microsystems</affiliation>
                <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:Norman.Walsh@Sun.COM" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Norman.Walsh@Sun.COM</email>
            </author>
        </authlist>
        <abstract>
            <p>This document defines constructor functions, operators and functions on the datatypes defined in
                    <bibref ref="xmlschema-2"/> and the datatypes defined in <bibref ref="xpath-datamodel"/>. It also discusses
                functions and operators on nodes and node sequences as defined in the <bibref ref="xpath-datamodel"/>.  These functions and operators are defined for use in <bibref ref="xpath20"/>, <bibref ref="xquery"/> and
                    <bibref ref="xslt20"/> and other related XML standards.  The signatures and summaries of functions defined in this document are available at:
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2006/xpath-functions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2006/xpath-functions</loc>.</p>
        
</abstract>
<status id="status">
<!-- NEW -->
<p><emph>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 <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">W3C technical reports index</loc> at http://www.w3.org/TR/.</emph></p>

<p>On 3 November 2005, this specification
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xquery-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">was published</loc> as a
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate Recommendation</loc>,
and a Call for Implementations was announced. 
This revision is published in order to give visibility to the
technical decisions that have been made so far during this
phase of the process and to allow review by W3C Members and other interested parties. 
The maturity level of the specification remains unchanged,
and the work is on track to move forward to the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Proposed Recommendation</loc>
stage when the exit criteria for the current phase have been met.
Publication as a Candidate Recommendation does not imply endorsement by the W3C Membership. 
This is a draft document and may be updated, replaced or obsoleted by other documents at any time. 
It is inappropriate to cite this document as other than work in progress.
This specification will remain a Candidate Recommendation until at least 28 February 2006.
</p>

<p>This document was produced jointly by the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query Working Group</loc> and the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Style/XSL" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XSL Working Group</loc>, both of which are part of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Activity" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML
Activity</loc>.</p>

<p>This draft includes corrections and changes based on
<loc xmlns:xlink="http://www.w3.org/1999/xlink" 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=Candidate+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=" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public comments</loc> recorded in the W3C public Bugzilla repository (<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Bugs/Public/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/Bugs/Public/</loc>)
used for issue tracking on the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xpath-functions-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate Recommendation</loc>. We expect to continue to collect implementation experience during summer of 2006 and then request a transition to Proposed Recommendation. A list of substantive changes since the publication of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xpath-functions-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate
Recommendation</loc> of 03 November 2005 can be found in <specref ref="changelog"/>.</p>

<p>Comments on this document are invited and should be made in W3C's <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Bugs/Public/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public Bugzilla system</loc> (instructions can be found at <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/2005/04/qt-bugzilla" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>).
If access to that system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery mailing list, <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:public-qt-comments@w3.org" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public-qt-comments@w3.org</loc>. It will be very helpful if you include the string [F&amp;O] in the subject line of your comment, whether made in Bugzilla or in email. Each Bugzilla entry and email message should contain only one comment.  Archives of the comments and responses are available at <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://lists.w3.org/Archives/Public/public-qt-comments/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://lists.w3.org/Archives/Public/public-qt-comments/
</loc>.</p>

<p>The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query/test-suite/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query and XPath Test Suite</loc> is under development. 
Implementors are encouraged to run this test suite and report their results.
A <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query/test-suite/XQTSReport.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">preliminary XQuery Test Suite Result Summary</loc>
has been prepared that contains information submitted for several implementations.
</p>

<p>This document was produced by groups operating under the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">5 February 2004 W3C Patent Policy</loc>. W3C maintains a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2002/08/xmlquery-IPR-statements" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public list of any patent disclosures</loc> made in connection with the deliverables of the XML Query Working Group and also maintains a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Style/XSL/Disclosures" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public list of any patent disclosures</loc> 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 <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Essential
Claim(s)</loc> with respect to this specification should disclose the information in accordance with  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">section
6 of the W3C Patent Policy</loc>. </p>
<!-- END NEW -->

            <!-- ****************************************************************************************** -->
            <!-- THE FOLLOWING PARAGRAPH MUST BE RESTORED FOR PUBLICATION OF PRIVATE WORKING DRAFTS  Also the para later on about sending comments -->
            <!-- ****************************************************************************************** -->      
<!--
<p>This is a <emph>private</emph> Working Draft of this document for review by members of the XML Query Working Group and the XSLT Working Group. It is subject to review by those two Working Groups before any publication as a Public Working Draft of the W3C.</p> 
-->
            <!-- ************************************************************************************* -->
            <!-- THE FOLLOWING 2 PARAGRAPHS MUST BE RESTORED FOR PUBLICATION OF THE PUBLIC WORKING DRAFTS -->
            <!--
      ************************************************************************************* -->
<!--           
<p>This is a <loc
href="http://www.w3.org/Consortium/Process-20010719/tr.html#last-call">Last
Call Working Draft</loc>. Publication as a Working Draft does not
imply endorsement by the W3C Membership. This is a draft document and
may be updated, replaced or obsoleted by other documents at any time.
It is inappropriate to cite this document as other than work in
progress.</p>

<p>Comments on this document are due by 13 May 2005.
Comments should be entered into the
last-call issue tracking system for this specification (instructions
can be found at
<loc href="http://www.w3.org/XML/2005/04/qt-bugzilla">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>). 
If access to that system is not feasible, you may send your
comments to the W3C mailing list,
<loc href="mailto:public-qt-comments@w3.org">public-qt-comments@w3.org</loc>
(archived at <loc href="http://lists.w3.org/Archives/Public/public-qt-comments/">http://lists.w3.org/Archives/Public/public-qt-comments/)</loc>.
Please start the subject line with <quote>[F&amp;O]</quote> so
comments can be classified correctly.</p> -->

<!--
            <p>This is a Public Working Draft for review by W3C Members and other interested
                parties. Publication as a Working Draft does not imply endorsement by the W3C
                Membership. This is a draft document and may be updated, replaced or obsoleted by
                other documents at any time. It is inappropriate to cite this document as other than
                work in progress.</p> -->
<!--
            <p>XQuery 1.0 and XPath 2.0 Functions and Operators has been defined through the efforts
                of a joint task force of the <loc href="http://www.w3.org/XML/Query">XML Query
                    Working Group</loc> and the <loc href="http://www.w3.org/Style/XSL/"> XSL Working
                Group</loc> (both part of the <loc href="http://www.w3.org/XML/Activity.html"> XML
                Activity</loc>). It is designed to be read in conjunction with the following
                    documents:<bibref ref="xpath-datamodel"/>, <bibref ref="xpath20"/>,<bibref
                ref="xquery"/> and <bibref ref="xslt20"/>.</p>
            <p>This document describes constructor functions, operators and functions that are used
                in <bibref ref="xpath20"/>, <bibref ref="xquery"/> and <bibref ref="xslt20"/> and
                possibly other W3C specifications.  The signatures and summaries of functions defined in this document are available at:
<loc href="http://www.w3.org/&date.year;/xpath-functions">http://www.w3.org/&date.year;/xpath-functions</loc>.
</p> -->
            <!--
			<p>A number of changes have been made to this document as
			a result of "Last Call" comments on the previous version
			of the document.  Feedback is solicited on
      these changes. The more significant of these changes are listed
      below.</p> -->
            <!-- <p>
<p>The semantics of functions whose return type varies with their input type is now described in greater detail.  The return type of such functions is identified typographically to call attention to their special semantics.</p>
<p>
There also has been some amplification of the rules for constructing simple types and for casting (see section <specref ref="constructor-functions"/> and section <specref ref="casting"/>).  A constructor for <code>xs:QName</code> has been added with special semantics.  See <specref ref='casting-to-QName'/>.</p>
<p>Another area where there has been a significant change from earlier versions is the implementation of the decision to preserve the input timezone in <code>xs:dateTime</code>, <code>xs:date</code> and <code>xs:time</code> values.  This has impacted a large number of functions and has had a pervasive effect over 
<specref ref='durations-dates-times'/>.</p>
<p>The <code>fn:document()</code> function has been replaced by a much simpler function called <code>fn:doc()</code>.</p>
<p>The rules for overflow and underflow in numeric operations have been spelled out in greater detail.  See <specref ref='op.numeric'/></p>
<p>An error function, <code>fn:error()</code>, and a trace function,
	  <code>fn:trace()</code>, have been added.</p> -->
            <!--
<ulist>
<item><p>An <quote>absolute</quote> function, <code>fn:abs()</code>,
has been added.  A <quote>reverse</quote> function, <code>fn:reverse()</code>,
has been added to Appendix <specref ref='examples'/>.</p></item>
<item><p>The semantics of the fn:id() and fn:idref() functions have been clarified.  These functions operate only on trees rooted in document nodes.</p></item>
<item><p>Casting from <code>xs:hexBinary</code> to <code>xs:base64Binary</code>and vice versa, is now allowed.  Casting from <code>xs:hexBinary</code> and <code>xs:base64Binary</code> to <code>xs:boolean</code> is now prohibited.</p></item>
<item><p>The names of two functions have been changed: <code>fn:get-namespace-from-QName</code> was changed to <code>get-namespace-uri-from-QName</code> and <code>get-namespace-uri-for-prefix</code> was changed to <code>get-inscope-namespace-prefixes</code>.</p></item>
</ulist>
-->
<!--
<p>This draft includes many corrections and changes based on member-only
and public comments on the <loc
href="http://www.w3.org/TR/2005/WD-xpath-functions-20050404/">Last Call Working
Draft</loc>
(http://www.w3.org/TR/2005/WD-xpath-functions-20050404/). These
decisions
<loc 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=Last+Call+drafts&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=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_status=RESOLVED&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=">are recorded</loc>
in the
<loc href="http://www.w3.org/Bugs/Public/">Bugzilla database</loc> (http://www.w3.org/Bugs/Public/).
A list of changes introduced by this draft can be found
in <specref ref="changelog"/>.
</p>

<p>This draft is being provided to permit public review of the changes
that have been made as a result of the Last Call comments. Publication
as a Working Draft does not imply endorsement by the W3C Membership.
This is a draft document and may be updated, replaced or obsoleted by
other documents at any time. It is inappropriate to cite this document
as other than work in progress.</p>

<p>Comments on the
changes should be made against the pertinent Last Call comment
(instructions can be found at
<loc href="http://www.w3.org/XML/2005/04/qt-bugzilla">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>). If access to that system is
not feasible, you may send your comments to the W3C mailing list,
<loc href="mailto:public-qt-comments@w3.org">public-qt-comments@w3.org</loc>
(archived at
<loc href="http://lists.w3.org/Archives/Public/public-qt-comments/">http://lists.w3.org/Archives/Public/public-qt-comments/</loc>). Please start
the subject line with “[F&amp;O]” so comments can be classified correctly.</p>

<p>The XML Query and XSL Working Groups expect to progress this document to
<loc href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR">Candidate
Recommendation</loc> status in
the very near future.</p>

<p>The patent policy for this document is the <loc
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</loc>. Patent disclosures relevant to this
specification may be found on the <loc
href="http://www.w3.org/2002/08/xmlquery-IPR-statements">XML Query
Working Group's patent disclosure page</loc> and the <loc
href="http://www.w3.org/Style/XSL/Disclosures">XSL Working Group's
patent disclosure page</loc>. An individual who has actual knowledge
of a patent which the individual believes contains Essential Claim(s)
with respect to this specification should disclose the information in
accordance with <loc
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</loc>.</p> -->
        </status>
        <langusage>
            <language id="EN">English</language>
        </langusage>
        <revisiondesc>
           <p/>
        </revisiondesc>
    </header>
    <body>
        <div1 id="intro">
            <head>Introduction</head>
            <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 <bibref ref="xpath20"/>, <bibref ref="xquery"/> and <bibref ref="xslt20"/>. </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
                    <bibref ref="xquery"/>.</p>
            <p>
                <bibref ref="xmlschema-2"/> 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 <xspecref spec="DM" ref="types"/> of the <bibref ref="xpath-datamodel"/>.
                These functions and operations are defined for use in <bibref ref="xpath20"/>,
                    <bibref ref="xquery"/> and <bibref ref="xslt20"/> and related XML standards. This
                document also discusses functions and operators on nodes and node sequences as
                defined in the <bibref ref="xpath-datamodel"/> for use in <bibref ref="xpath20"/>, <bibref ref="xquery"/> and <bibref ref="xslt20"/> 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' <bibref ref="xquery"/>, 'XT' <bibref ref="xslt20"/>, 'XP' <bibref ref="xpath20"/>, 'DM' <bibref ref="xpath-datamodel"/> and 'FS'
                    <bibref ref="xquery-semantics"/>.</p>
            <div2 id="conformance">
                <head>Conformance</head>
<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 
<bibref ref="xpath20"/>, <bibref ref="xslt20"/> and <bibref ref="xquery"/>)
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>
<ulist>
<item>
<p>It is <termref def="implementation-defined"/> which version of Unicode is supported, but it is recommended that the most recent version of Unicode be used.  </p>
</item>
<item><p>Support for XML 1.0 and XML 1.1 by the datatypes used in Functions and Operators.</p></item>
</ulist>
<note><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></note>
</div2>
            <div2 id="namespace-prefixes">
                <head>Namespaces and Prefixes</head>
                <p>The functions and operators discussed in this document are contained in one of
                    three namespaces (see <bibref ref="REC-xml-names"/>) and referenced using an
                    <code>xs:QName</code>. The datatypes and constructor functions for the built-in datatypes defined
                    in <bibref ref="xmlschema-2"/> and in <xspecref spec="DM" ref="types"/>
                   of <bibref ref="xpath-datamodel"/> and discussed in <specref ref="constructor-functions"/>  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>The datatypes defined in <bibref ref='xpath-datamodel'/> <xspecref spec="DM" ref="types"/> 
                    and <specref ref="duration-subtypes"/> in this document are contained in a
                    separate namespace and are named using the prefix <code>xdt</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>
                <ulist>
                    <item>
                        <p>
                            <code>http://www.w3.org/2001/XMLSchema</code> for constructors --
                            associated with <code>xs</code>.
                        </p>
                    </item>
                    <!--					<item>
						<p>
							<code>http://www.w3.org/&date.year;/xpath-operators</code> for operators</p>
					</item> -->
                    <item>
                        <p>

                            <code>http://www.w3.org/2006/xpath-functions</code>
                            for functions -- associated with <code>fn</code>. </p>
                    </item>
                 <!--   <item>
                        <p>

                            <code>http://www.w3.org/&date.year;/xpath-datatypes</code>
                            for the datatypes associated with <code>xdt</code>. </p>
                    </item> -->
                    <item>
                        <p>
                            <code>http://www.w3.org/2005/xqt-errors</code> -- associated with
                            <code>err</code>. </p>
                    </item>
                </ulist>
                <note>
                    <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>
                </note>
                <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 <bibref ref="xpath20"/>, <bibref ref="xquery"/> and <bibref ref="xslt20"/>. 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>
                <example role="signature">
                    <proto role="example" name="numeric-multiply" return-type="numeric" isOp="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                        <arg name="arg1" type="numeric"/>
                        <arg name="arg2" type="numeric"/>
                    </proto>
                </example>
            </div2>
            <div2 id="func-overloading">
                <head>Function Overloading</head>
                <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 <bibref ref="xpath"/>
                    functions such as <code>fn:string()</code>, which accepts a single parameter of
                    a variety of types. In addition, it should be noted that the functions defined
                    in <specref ref="numeric-functions"/> 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
                        <specref ref="func-signatures"/>. 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>
            </div2>
            <div2 id="func-signatures">
                <head>Function Signatures and Descriptions</head>
                <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>
                <example role="signature">
                    <proto role="example" name="function-name" return-type="return-type" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="parameter-name" type="parameter-type"/>
                        <arg name="..." type=""/>
                    </proto>
                </example>
                <p>In this notation, <term>function-name</term>, 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 <emph>
                        <code>return-type</code>
                    </emph>, 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 <xspecref spec="XP" ref="id-sequencetype-syntax"/>.</p>
                <p>In some cases the word <quote>
                        <code>numeric</code>
                    </quote> 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 <example role="signature">
                        <proto role="example" name="numeric-function" return-type="..." returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric"/>
                        </proto>
                    </example> represents the following four function signatures:<example role="signature">
                        <proto role="example" name="numeric-function" return-type="..." returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:integer"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto role="example" name="numeric-function" return-type="..." returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:decimal"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto role="example" name="numeric-function" return-type="..." returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:float"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto role="example" name="numeric-function" return-type="..." returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:double"/>
                        </proto>
                    </example>
                    <!--
In most cases, numeric functions operate on 
parameters of the same type and return the same type. The exceptions
are <code>op:numeric-divide</code>, which returns an
<code>xs:decimal</code> if called with two <code>xs:integer</code>
operands and <code>op:numeric-integer-divide</code> which always
returns an <code>xs:integer</code>. -->
                </p>
                <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 <emph>
                        <term>bold italics</term>
                    </emph> 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 <xspecref spec="FS" ref="function_rules"/>.</p>
                <p>The function name is a <code>QName</code> as defined in <bibref ref="xmlschema-2"/>
                    and must adhere to its syntactic conventions. Following <bibref ref="xpath"/>,
                    function names are composed of English words separated by hyphens,"-". If a
                    function name contains a <bibref ref="xmlschema-2"/> datatype name, it may have
                    intercapitalized spelling and is used in the function name as such. For example, <code>fn:timezone-from-dateTime</code>.</p>
                <p>Rules for passing parameters to operators are described in the relevant sections
                    of <bibref ref="xquery"/> and <bibref ref="xpath20"/>. For example, the rules for
                    passing parameters to arithmetic operators are described in <xspecref spec="XP" ref="id-arithmetic"/>. 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 <emph>subtype substitution</emph> (See <xspecref spec="XP" ref="id-sequencetype-matching"/>). 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 <xspecref spec="XP" ref="promotion"/>). 
                  <olist>
                        <item>
                            <p>
                                <emph>Subtype Substitution</emph>: 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>
                        </item>
                        <item>
                            <p>
                                <emph>Numeric Type Promotion</emph>: <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>
                        </item>
                        <item>
                            <p>
                                <emph>anyURI Type Promotion</emph>: A value of
                                type <code>xs:anyURI</code> can be promoted to the
                                type <code>xs:string</code>. </p>
                        </item>
                    </olist>
                </p>
                <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>
                <example role="signature">
                    <proto role="example" name="function-name" return-type="return-type" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="parameter-name" type="parameter-type" emptyOk="yes"/>
                    </proto>
                </example>
                <p>Note that this function signature is different from a signature in which the
                    parameter is omitted. See, for example, the two signatures
                    for <code>fn:string()</code>. In the first signature, the parameter is omitted
                    and the argument defaults to the context item, referred to as <quote>.</quote>.
                    In the second signature, the argument must be present but may be the empty
                    sequence, referred to as <quote>().</quote>
                </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>
                <example role="signature">
                    <proto role="example" name="median" return-type="xs:double" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="xs:double*" emptyOk="no"/>
                    </proto>
                </example>
            </div2>
            <div2 id="namespace-terminology">
                <head>Namespace Terminology</head>
                <p>This document uses the phrase "namespace URI" to identify the concept identified
                    in <bibref ref="REC-xml-names"/> as "namespace name", and the phrase "local name"
                    to identify the concept identified in <bibref ref="REC-xml-names"/> as "local part".</p>
                <p>It also uses the term <quote>expanded-QName</quote> defined below.</p>
                <glist>
                    <gitem>
                        <label>
                            <termdef id="expanded-Qname" term="Expanded-QName">
                                <term>Expanded-QName</term>
                            </termdef>
                        </label>
                        <def>
                            <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 <bibref ref="xmlschema-2"/> 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>
                        </def>
                    </gitem>
                </glist>
            </div2>
            <div2 id="datatypes">
                <head>Type Hierarchy</head>
                <p>The diagram below shows the types for which functions are defined in this
                    document. These include the built-in types defined by <bibref ref="xmlschema-2"/>
                    (shown on the right) as well as types defined in <bibref ref="xpath-datamodel"/>
                    (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>
                <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="XPathTypeHierarchy.gif" alt="Type hierarchy   graphic" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                <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
                        <bibref ref="xpath-datamodel"/>
                </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 border="0" summary="Type summary" role="hierarchy">
                   <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">xs:anyType</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">user-defined complex types</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:untyped</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:anySimpleType</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">user-defined list and union types</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:IDREFS</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:NMTOKENS</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:ENTITIES</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:anyAtomicType</td>
                        </tr>
                    </tbody>
                </table>
                <p>The table below shows the datatypes derived from <code>xs:anyAtomicType</code>.
                    This includes all the <bibref ref="xmlschema-2"/> built-in datatypes as well as the
                    two totally ordered subtypes of duration defined in <xspecref spec="DM" ref="types"/>. </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 border="0" summary="Type summary" role="hierarchy">
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">xs:untypedAtomic</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:dateTime</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:date</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:time</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:duration</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:yearMonthDuration</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:dayTimeDuration</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:float</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:double</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:decimal</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:integer</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:nonPositiveInteger</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:negativeInteger</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:long</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:int</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:short</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:byte</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:nonNegativeInteger</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:unsignedLong</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:unsignedInt</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:unsignedShort</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:unsignedByte</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:positiveInteger</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:gYearMonth</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:gYear</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:gMonthDay</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:gDay</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:gMonth</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:string</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:normalizedString</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:token</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:language</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:NMTOKEN</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:Name</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:NCName</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:ID</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:IDREF</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:ENTITY</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:boolean</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:base64Binary</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:hexBinary</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:anyURI</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:QName</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:NOTATION</td>
                        </tr>
                    </tbody>
                </table>
                <p>The table below shows the type hierarchy for the types introduced in <bibref ref="xpath-datamodel"/>. 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 border="0" summary="Type summary" role="hierarchy">
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">item</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:anyAtomicType</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">node</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">attribute</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">user-defined attribute types</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">comment</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">document</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">user-defined document types</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">element</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">user-defined element types</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">processing-instruction</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">text</td>
                        </tr>
                    </tbody>
                </table>
            </div2>
            
            <div2 id="terminology">
                <head>Terminology</head>
                <p>The terminology used to describe the functions and operators on <bibref ref="xmlschema-2"/> is defined in the body of this specification. The terms defined
                    in the following list are used in building those definitions:</p>
                <glist>
                    <gitem>
                        <label>
                            <termdef id="compatibility" term="for compatibility">
                                <term>for compatibility</term>
                            </termdef>
                        </label>
                        <def>
                            <p>A feature of this specification included to ensure that
                                implementations that use this feature remain compatible with <bibref ref="xpath"/>
                            </p>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="may" term="may">
                                <term>may</term>
                            </termdef>
                        </label>
                        <def>
                            <p>Conforming documents and processors are permitted to, but need not,
                                behave as described. </p>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="must" term="must">
                                <term>must</term>
                            </termdef>
                        </label>
                        <def>
                            <p>Conforming documents and processors are required to behave as
                                described; otherwise, they are either non-conformant or else in error.</p>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="implementation-defined" term="implementation-defined">
                                <term>implementation-defined</term>
                            </termdef>
                        </label>
                        <def>
                            <p>Possibly differing between implementations, but specified and
                                documented by the implementor for each particular implementation.</p>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="implementation-dependent" term="implementation dependent">
                                <term>implementation-dependent</term>
                            </termdef>
                        </label>
                        <def>
                            <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>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="execution-scope" term="execution scope">
                                <term>execution scope</term>
                            </termdef>
                        </label>
                        <def>
                            <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>
                        </def>
                    </gitem>
                    <gitem>
                        <label>
                            <termdef id="stable" term="stable">
                                <term>stable</term>
                            </termdef>
                        </label>
                        <def>
                            <p> Most of the functions in the core library have the property that
                                calling the same function twice within an <termref def="execution-scope"/> with the same arguments returns the same
                                result: these functions are said to be <term>stable</term>. This
                                category includes a number of functions such as
                                <code>fn:doc()</code>, <code>fn:collection()</code>,
                                <code>fn:current-dateTime()</code>, <code>fn:current-date</code> and
                                <code>fn:current-time()</code> 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>
<note>
<p>in the case of <code>fn:collection()</code> and <code>fn:doc()</code>, the
requirement for stability may be relaxed: see the function definitions for details.</p>
</note>
                            <p> Some other functions, for example <code>fn:position()</code> and
                                <code>fn:last()</code>, depend on the dynamic context and may,
                                therefore, produce different results each time they are called.
                                These functions are said to be <term>contextual</term>.</p>
                        </def>
                    </gitem>
 					<gitem>
                        <label>
                            <termdef id="uri" term="URI and URI reference">
                                <term>URI and URI reference</term>
                            </termdef>
                        </label>
                        <def>
                        <p>
                        Within this specification, the term "URI" refers to Universal Resource Identifiers as
defined in <bibref ref="rfc3986"/> and extended in <bibref ref="rfc3987"/> 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 <bibref ref="xmlschema-2"/>. Note that this means, in practice, that where this specification requires a "URI Reference", an IRI as defined in <bibref ref="rfc3987"/> 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 <bibref ref="rfc3987"/>; for example it does not require non-ASCII characters to be escaped.
						</p></def>
                    </gitem>
                </glist>
            </div2>
        </div1>
        <div1 id="accessors">
            <head>Accessors</head>
            <p>Accessors and their semantics are described in <bibref ref="xpath-datamodel"/>. Some of
                these accessors are exposed to the user through the functions described below.</p>
            <table border="1" width="80%" summary="Function summary">
                <col width="25%" span="1"/>
                <col width="25%" span="1"/>
                <col width="25%" span="1"/>
                <col width="25%" span="1"/>
                <thead>
                    <tr>
                        <th rowspan="1" colspan="1">Function</th>
                        <th rowspan="1" colspan="1">Accessor</th>
                        <th rowspan="1" colspan="1">Accepts</th>
                        <th rowspan="1" colspan="1">Returns</th>
                    </tr>
                </thead>
                <tbody>
                    <!--		<tr>
						<td>
							<code>fn:node-kind</code>
						</td>
						<td>
							<code>node-kind</code>
						</td>
						<td>any kind of node</td>
						<td><code>xs:string</code></td>
					</tr> -->
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:node-name</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>node-name</code>
                        </td>
                        <td rowspan="1" colspan="1">an optional node</td>
                        <td rowspan="1" colspan="1">zero or one <code>xs:QName</code>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:nilled</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>nilled</code>
                        </td>
                        <td rowspan="1" colspan="1">a node</td>
                        <td rowspan="1" colspan="1">an optional <code>xs:boolean</code>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:string</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>string-value</code>
                        </td>
                        <td rowspan="1" colspan="1">an optional item or no argument</td>
                        <td rowspan="1" colspan="1">
                            <code>xs:string</code>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:data</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>typed-value</code>
                        </td>
                        <td rowspan="1" colspan="1">zero or more items</td>
                        <!-- Don Chamberlin email, 2002-07-27 -->
                        <td rowspan="1" colspan="1">a sequence of atomic values</td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:base-uri</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>base-uri</code>
                        </td>
                        <td rowspan="1" colspan="1">an optional node or no argument</td>
                        <td rowspan="1" colspan="1">zero or one <code>xs:anyURI</code>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:document-uri</code>
                        </td>
                        <td rowspan="1" colspan="1">
                            <code>document-uri</code>
                        </td>
                        <td rowspan="1" colspan="1">an optional node</td>
                        <td rowspan="1" colspan="1">zero or one <code>xs:anyURI</code>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div2 id="func-node-name">
                <head>fn:node-name</head>
                <example role="signature">
                    <proto name="node-name" return-type="xs:QName" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="node()" emptyOk="yes"/>
                    </proto>
                </example>
                <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>
            </div2>
            <div2 id="func-nilled">
                <head>fn:nilled</head>
                <example role="signature">
                    <proto name="nilled" return-type="xs:boolean" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="node()" emptyOk="yes"/>
                    </proto>
                </example>
                <p>Summary: Returns an <code>xs:boolean</code> indicating whether the argument node
                    is <quote>nilled</quote>. If the argument is not an element node, returns the
                    empty sequence. If the argument is the empty sequence, returns the empty sequence.</p>
            </div2>
            <div2 id="func-string">
                <head>fn:string</head>
                <example role="signature">
                    <proto name="string" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                    <proto name="string" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <!-- Don Chamberlin email, 2002-07-27 changed item* to item -->
                        <!-- JM editorial, 2002-08-23 changed item to item? -->
                        <arg name="arg" type="item()" emptyOk="yes"/>
                    </proto>
                </example>
                <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>The following errors may be raised:  if the context item is undefined <xerrorref spec="XP" class="DY" code="0002" type="type"/>; if the context item is not a node 
<xerrorref spec="XP" class="TY" code="0004" type="type"/>.</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
                        <xspecref spec="DM" ref="dm-string-value"/>.</p>
                <p>If <code>$arg</code> is an atomic value, then the function returns the same
                    string as is returned by the expression <quote>
                        <code>$arg</code> cast as <code>xs:string</code>
                    </quote> (see <specref ref="casting"/>).</p>
                      
             </div2>
            <div2 id="func-data">
                <head>fn:data</head>
                <example role="signature">
                    <proto name="data" return-type="xs:anyAtomicType*" returnEmptyOk="no" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="item()*"/>
                    </proto>
                </example>
                <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>
                <ulist>
                    <item>
                        <p>If the item is an atomic value, it is returned.</p>
                    </item>
                    <item>
                        <p> If the item is a node:</p>
                        <ulist>
                            <item>
                                <p>If the node does not have a typed value an error is
                                        raised  <errorref class="TY" code="0012" type="dynamic"/>. </p>
                            </item>
                            <item>
                                <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 <xspecref spec="DM" ref="dm-typed-value"/>.</p>
                            </item>
                        </ulist>
                    </item>
                </ulist>
            </div2>
            <div2 id="func-base-uri">
                <head>fn:base-uri</head>
                <example role="signature">
                    <proto name="base-uri" return-type="xs:anyURI" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                </example>
                <example role="signature">
                    <proto name="base-uri" return-type="xs:anyURI" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="node()" emptyOk="yes"/>
                    </proto>
                </example>
                <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 <xspecref spec="DM" ref="dm-base-uri"/>. 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 <xerrorref spec="XP" class="DY" code="0002" type="type"/>; if the context item is not a node 
<xerrorref spec="XP" class="TY" code="0004" type="type"/>.</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 <code>fn:static-base-uri</code>.</p>
            </div2>
            <div2 id="func-document-uri">
                <head>fn:document-uri</head>
                <example role="signature">
                    <proto name="document-uri" return-type="xs:anyURI" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="node()" emptyOk="yes"/>
                    </proto>
                </example>
                <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
                        <xspecref spec="DM" ref="DocumentNodeAccessors"/>.</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 or
  if its document-uri property is a relative URI. Otherwise, returns
  an absolute URI expressed as an <code>xs:string</code>.</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>If <code>fn:document-uri($arg)</code> does not return the empty sequence, then
                    the following expression always holds:</p>
                <eg xml:space="preserve"> fn:doc(fn:document-uri($arg)) is $arg</eg>
            </div2>
            <!--		<div2 id="func-unique-ID">
				<head>fn:unique-ID</head>
				<example role="signature">
					<proto name="unique-ID" return-type="ID" returnEmptyOk="yes">
						<arg name="arg" type="node"/>
					</proto>
				</example>
				<p>This function accepts an element node and returns the identifier (ID) which may have been assigned by the user. It corresponds to the normalized value property of the attribute information item in the attributes property that has a type ID, if one exists.  If no ID attribute exists the empty sequence is returned.</p>
			</div2> -->
        </div1>
        <div1 id="func-error">
            <head>The Error Function</head>
            <p>In this document, as well as in <bibref ref="xquery"/>, <bibref ref="xpath20"/>, and
                    <bibref ref="xquery-semantics"/>, the phrase <quote>an error is raised</quote>
                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: <quote>an error is raised [<emph>error code</emph>]</quote>. 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 <xspecref spec="XP" ref="id-handling-dynamic"/> and <xspecref spec="FS" ref="sec_fnerror"/>.</p>
            <p>The <code>fn:error</code> function is a general function that may be invoked as above
                but may also be invoked from <bibref ref="xquery"/> or <bibref ref="xpath20"/>
                applications with, for example, an <code>xs:QName</code> argument. </p>
            <example role="signature">
                <proto name="error" return-type="none" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
            </example>
            <example role="signature">
                <proto name="error" return-type="none" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                    <arg name="error" type="xs:QName" emptyOk="no"/>
                </proto>
            </example>
            <example role="signature">
                <proto name="error" return-type="none" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                    <arg name="error" type="xs:QName" emptyOk="yes"/>
                    <arg name="description" type="xs:string" emptyOk="no"/>
                </proto>
            </example>
            <example role="signature">
                <proto name="error" return-type="none" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                    <arg name="error" type="xs:QName" emptyOk="yes"/>
                    <arg name="description" type="xs:string" emptyOk="no"/>
                    <arg name="error-object" type="item()*" emptyOk="no"/>
                </proto>
            </example>
            <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 <termref def="implementation-dependent"/>.</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 <termref def="implementation-dependent"/>. </p>
<note><p>
The value of the <code>$description</code> parameter may need to be localized.
</p></note>
            <p>Note that <quote>none</quote> is a special type defined in <bibref ref="xquery-semantics"/> 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>
            <eg xml:space="preserve"> fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')) </eg>
            <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>
            <eg xml:space="preserve"> fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000')</eg>
            <div2 id="func-error-examples">
                <head>Examples</head>
                <ulist>
                    <item>
                        <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>
                    </item>
                    <item>
                        <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>
                    </item>
                </ulist>
            </div2>
        </div1>
        <div1 id="func-trace">
            <head>The Trace Function</head>
            <p>This function is intended to be used in debugging queries by providing a trace of
                their execution.</p>
            <example role="signature">
                <proto name="trace" return-type="item()*" returnVaries="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                    <arg name="value" type="item()*" emptyOk="no"/>
                    <arg name="label" type="xs:string" emptyOk="no"/>
                </proto>
            </example>
            <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 <termref def="implementation-defined"/>. The format of the trace
                output is <termref def="implementation-dependent"/>. The ordering of output from
                invocations of the <code>fn:trace()</code> function is <termref def="implementation-dependent"/>.</p>
            <div2 id="func-trace-examples">
                <head>Examples</head>
                <ulist>
                    <item>
                        <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>
                    </item>
                </ulist>
            </div2>
        </div1>
        <div1 id="constructor-functions">
            <head>Constructor Functions</head>
            <div2 id="constructor-functions-for-xsd-types">
                <head>Constructor Functions for XML Schema Built-in Types</head>
                <p>Every built-in atomic type that is defined in <bibref ref="xmlschema-2"/>, except <code>xs:anyAtomicType</code> and <code>xs:NOTATION</code>, has an
                    associated constructor function. <code>xs:untypedAtomic</code>, defined
                    in <xspecref spec="DM" ref="types"/> and the two derived types
                    <code>xs:yearMonthDuration</code> and <code>xs:dayTimeDuration</code> defined
                    in <xspecref spec="DM" ref="types"/> 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 <bibref ref="xmlschema-2"/>.  If the static context (See <xspecref spec="XP" ref="static_context"/>) contains a type derived from
<code>xs:NOTATION</code> then a constructor function is defined for it.
See <specref ref="constructor-functions-for-user-defined-types"/>.
</p>
<p> 
The form of the constructor function for a type
                    <emph>prefix:TYPE</emph> is:</p>
                <example role="signature">
                    <proto name="prefix:TYPE" return-type="prefix:TYPE" role="example" returnEmptyOk="yes" isSpecial="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isOp="no">
                        <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                    </proto>
                </example>
                <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 <bibref ref="xmlschema-2"/> is:</p>
                <example role="signature">
                    <proto name="unsignedInt" return-type="xs:unsignedInt" isSchema="yes" returnEmptyOk="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                    </proto>
                </example>
                <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
                        <xspecref spec="XP" ref="id-atomization"/> 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 <errorref class="RG" code="0001"/>.</p>
                    <p>The semantics of the constructor function <quote>
                        <code>xs:TYPE(arg)</code>
                    </quote> are identical to the semantics of <quote>
                        <code>arg</code> cast as <code>xs:TYPE?</code>
                    </quote>. See <specref ref="casting"/>.</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 
<specref ref="constructor-qname-notation"/>.
</p>
                <p>The following constructor functions for the built-in types are supported:</p>
                <ulist>
                    <item>
                        <proto name="string" return-type="xs:string" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="boolean" return-type="xs:boolean" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="decimal" return-type="xs:decimal" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="float" return-type="xs:float" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                        <p>Implementations <termref def="may"/> return negative zero for <code>xs:float("-0.0E0")</code>.  <bibref ref="xmlschema-2"/> does not distinguish between the values positive zero and negative zero.
                        </p>
                    </item>
                    <item>
                        <proto name="double" return-type="xs:double" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                        <p>Implementations <termref def="may"/> return negative zero for <code>xs:double("-0.0E0").</code> <bibref ref="xmlschema-2"/> does not distinguish between the values positive zero and negative zero.
                        </p>
                    </item>
                    <item>
                        <proto name="duration" return-type="xs:duration" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="dateTime" return-type="xs:dateTime" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="time" return-type="xs:time" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="date" return-type="xs:date" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="gYearMonth" return-type="xs:gYearMonth" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="gYear" return-type="xs:gYear" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="gMonthDay" return-type="xs:gMonthDay" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="gDay" return-type="xs:gDay" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="gMonth" return-type="xs:gMonth" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="hexBinary" return-type="xs:hexBinary" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="base64Binary" return-type="xs:base64Binary" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="anyURI" return-type="xs:anyURI" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="QName" return-type="xs:QName" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="no"/>
                        </proto>
                        <p>
                            See <specref ref="constructor-qname-notation"/> for special rules.</p>
                    </item>
               <!--     <item>
                        <proto name="NOTATION" return-type="xs:NOTATION" returnEmptyOk="no"
                            isSchema="yes" role="example">
                            <arg name="arg" type="xs:string" emptyOk="no"/>
                        </proto>
                        <p>
                            <code>$arg</code> must be a <code>xs:string</code> literal.</p>
                    </item> -->
                </ulist>
                <ulist>
                    <item>
                        <proto name="normalizedString" return-type="xs:normalizedString" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="token" return-type="xs:token" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="language" return-type="xs:language" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="NMTOKEN" return-type="xs:NMTOKEN" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <!-- <item><proto name="NMTOKENS" return-type="xs:NMTOKENS" returnEmptyOk='yes' isSchema="yes" role='example'>
					<arg name="arg" type="xs:anyAtomicType" emptyOk='yes'/></proto></item> -->
                    <item>
                        <proto name="Name" return-type="xs:Name" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="NCName" return-type="xs:NCName" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="ID" return-type="xs:ID" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="IDREF" return-type="xs:IDREF" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <!-- <item><proto name="IDREFS" return-type="xs:IDREFS" returnEmptyOk='yes' isSchema="yes" role='example'>
					<arg name="arg" type="xs:anyAtomicType" emptyOk='yes'/></proto></item> -->
                    <item>
                        <proto name="ENTITY" return-type="xs:ENTITY" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
 <p>See <specref ref="casting-to-ENTITY"/> for rules related to constructing values of type <code>xs:ENTITY</code> and types derived from it.</p>
                    </item>
                    <!-- <item><proto name="ENTITIES" return-type="xs:ENTITIES" returnEmptyOk='yes' isSchema="yes" role='example'>
					<arg name="arg" type="xs:anyAtomicType" emptyOk='yes'/></proto></item> -->
                    <item>
                        <proto name="integer" return-type="xs:integer" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="nonPositiveInteger" return-type="xs:nonPositiveInteger" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="negativeInteger" return-type="xs:negativeInteger" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="long" return-type="xs:long" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="int" return-type="xs:int" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="short" return-type="xs:short" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="byte" return-type="xs:byte" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="nonNegativeInteger" return-type="xs:nonNegativeInteger" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="unsignedLong" return-type="xs:unsignedLong" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="unsignedInt" return-type="xs:unsignedInt" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="unsignedShort" return-type="xs:unsignedShort" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="unsignedByte" return-type="xs:unsignedByte" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="positiveInteger" return-type="xs:positiveInteger" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                </ulist>
                <ulist>
                    <item>
                        <proto name="yearMonthDuration" return-type="xs:yearMonthDuration" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="dayTimeDuration" return-type="xs:dayTimeDuration" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                    <item>
                        <proto name="untypedAtomic" return-type="xs:untypedAtomic" returnEmptyOk="yes" isSchema="yes" role="example" returnSeq="no" returnVaries="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                        </proto>
                    </item>
                </ulist>
            </div2>
            <div2 id="func-dateTime">
                <head>A Special Constructor Function for xs:dateTime</head>
                <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>
                <example role="signature">
                    <proto name="dateTime" return-type="xs:dateTime" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg1" type="xs:date" emptyOk="no"/>
                        <arg name="arg2" type="xs:time" emptyOk="no"/>
                    </proto>
                </example>
                <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 timezone of the result is computed as follows:</p>
                <ulist>
                    <item>
                        <p>If neither argument has a timezone, the result has no timezone.</p>
                    </item>
                    <item>
                        <p>If exactly one of the arguments has a timezone, or if both arguments have
                            the same timezone, the result has this timezone.</p>
                    </item>
                    <item>
                        <p>If the two arguments have different timezones, an error is
                                raised:<errorref class="RG" code="0008"/>
                        </p>
                    </item>
                </ulist>
 				<div3 id="func-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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></item>
<item><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>
                            </item>
                        </ulist>
               </div3>
            </div2>
           <div2 id="constructor-qname-notation">
                <head>Constructor Functions for xs:QName and xs:NOTATION</head>
<p>Special rules apply to constructor functions for the types <code>xs:QName</code> and <code>xs:NOTATION</code>, for two reasons:</p>
<ulist>
<item><p>
The lexical representation of these types uses namespace prefixes, whose
meaning is context-dependent.</p></item>
<item><p>
Values cannot belong directly to the type <code>xs:NOTATION</code>, only to its subtypes.
</p></item>
</ulist>
<p>
These constraints result in the following restrictions:</p>
<ulist>
<item><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 <specref ref="casting-from-primitive-to-primitive"/>) 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></item>
<item><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></item>
</ulist>
<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 <xspecref spec="XP" ref="static_context"/>. A static error is raised <errorref class="NS" code="0004"/>
if the prefix is not bound in the static context. As described in
<xspecref spec="DM" ref="terminology"/>, the supplied prefix is retained as part of the
expanded-QName value.
</p>
           </div2>
            <div2 id="constructor-functions-for-user-defined-types">
                <head>Constructor Functions for User-Defined Types</head>
                <p> For every atomic type in the static context (See <xspecref spec="XP" ref="static_context"/>) 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 <specref ref="constructor-functions-for-xsd-types"/>. </p>
<p>
                            Special rules apply to constructor functions for types derived from <code>xs:QName</code> and <code>xs:NOTATION</code>. See <specref ref="constructor-qname-notation"/>.</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>
                <example role="signature">
                    <proto name="my:hatSize" return-type="my:hatSize" isSpecial="yes" returnEmptyOk="yes" role="example" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isOp="no">
                        <arg name="arg" type="xs:anyAtomicType" emptyOk="yes"/>
                    </proto>
                </example>
                <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>
                <eg xml:space="preserve">17 cast as apple</eg>
                <p> The following shows the use of the constructor function:</p>
                <eg xml:space="preserve">declare default function namespace ""; apple(17)</eg>
            </div2>
        </div1>
        <div1 id="numeric-functions">
            <head>Functions and Operators on Numerics</head>
            <p>This section discusses arithmetic operators on the numeric datatypes defined in
                    <bibref ref="xmlschema-2"/>. It uses an approach that permits lightweight
                implementation whenever possible. </p>
            <div2 id="numeric-types">
                <head>Numeric Types</head>
                <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 border="0" width="288" summary="Numeric types" role="hierarchy">
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">xs:decimal</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:integer</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:float</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">xs:double</td>
                        </tr>
                    </tbody>
                </table>
                <p>They also apply to types derived by restriction from the above types. </p>
                <note>
                    <p>
This specification uses  <bibref ref="ieee754"/> arithmetic for <code>xs:float</code> and <code>xs:double</code> values.
This differs from <bibref ref="xmlschema-2"/> which defines
<code>NaN</code> as being equal to itself and defines only a single zero in the value space while <bibref ref="ieee754"/> 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 <bibref ref="xmlschema-2"/>  value.) The text accompanying several functions discusses behaviour for both positive and negative zero inputs and outputs in the interest of alignment with <bibref ref="ieee754"/>.
</p>
                </note>
            </div2>
            <div2 id="op.numeric">
                <head>Operators on Numeric Values</head>
                <p>The following functions define the semantics of operators defined in <bibref ref="xquery"/> and <bibref ref="xpath20"/> on these numeric types. </p>
                <table border="1" summary="Operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Operators</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-add</code>
                            </td>
                            <td rowspan="1" colspan="1">Addition</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-subtract</code>
                            </td>
                            <td rowspan="1" colspan="1">Subtraction</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-multiply</code>
                            </td>
                            <td rowspan="1" colspan="1">Multiplication</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-divide</code>
                            </td>
                            <td rowspan="1" colspan="1">Division</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-integer-divide</code>
                            </td>
                            <td rowspan="1" colspan="1">Integer division</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-mod</code>
                            </td>
                            <td rowspan="1" colspan="1">Modulus</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-unary-plus</code>
                            </td>
                            <td rowspan="1" colspan="1">Unary plus</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-unary-minus</code>
                            </td>
                            <td rowspan="1" colspan="1">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 <quote><code>numeric</code></quote> 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 <code>op:numeric-divide</code>, which returns
                    an <code>xs:decimal</code> if called with two <code>xs:integer</code> operands
                    and <code>op:numeric-integer-divide</code> which always returns an <code>xs:integer</code>.</p>
                <p>If the two operands are not of the same type, <emph>subtype substitution</emph>
                    and <emph>numeric type promotion</emph> are used to obtain two operands of the
                    same type. <xspecref spec="XP" ref="promotion"/> and <xspecref spec="XP" ref="mapping"/> 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 border="1" summary="Function/operator summary">
                    <col width="50%" span="1"/>
                    <col width="50%" span="1"/>
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Operator</th>
                            <th rowspan="1" colspan="1">Returns</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:integer, xs:integer)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:integer</code> (except for <code>op:numeric-divide(integer,
                                integer)</code>, which returns <code>xs:decimal</code>)</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:decimal, xs:decimal)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:decimal</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:float, xs:float)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:float</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:double, xs:double)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:double</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:integer)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:integer</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:decimal)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:decimal</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:float)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <code>xs:float</code>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:operation(xs:double)</code>
                            </td>
                            <td rowspan="1" colspan="1">
                                <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>
                <eg xml:space="preserve">op:operation(xs:int, xs:double) =&gt; op:operation(xs:double, xs:double)</eg>
                <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>
                <eg xml:space="preserve">op:operation(fenceHeight, xs:integer) =&gt; op:operation(xs:integer, xs:integer)</eg>
                <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 <termref def="must"/> behave as follows:</p>
                <ulist>
                    <item>
                        <p>For <code>xs:float</code> and <code>xs:double</code> operations, overflow
                            behavior <termref def="must"/> be conformant with <bibref ref="ieee754"/>. This specification allows the following options:</p>
                        <ulist>
                            <item>
                                <p>Raising an error <errorref class="AR" code="0002"/> via an
                                    overflow trap.</p>
                            </item>
                            <item>
                                <p>Returning <code>INF</code> or <code>-INF</code>.</p>
                            </item>
                            <item>
                                <p>Returning the largest (positive or negative) non-infinite number.</p>
                            </item>
                        </ulist>
                    </item>
                    <item>
                        <p>For <code>xs:float</code> and <code>xs:double</code> operations,
                            underflow behavior <termref def="must"/> be conformant with <bibref ref="ieee754"/>. This specification allows the following options:</p>
                        <ulist>
                            <item>
                                <p>Raising an error <errorref class="AR" code="0002"/> via an
                                    underflow trap.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </item>
                    <item>
                        <p>For <code>xs:decimal</code> operations, overflow behavior <termref def="must"/> raise an error <errorref class="AR" code="0002"/>. On
                            underflow, <code>0.0</code> must be returned.</p>
                    </item>
                    <item>
                        <p>For <code>xs:integer</code> operations, implementations that support
                            limited-precision integer operations <termref def="must"/> select from
                            the following options:</p>
                        <ulist>
                            <item>
                                <p> They <termref def="may"/> choose to always raise an
                                        error <errorref class="AR" code="0002"/>.</p>
                            </item>
                            <item>
                                <p> They <termref def="may"/> provide an <termref def="implementation-defined"/> mechanism that allows users to
                                    choose between raising an error and returning a result that is
                                    modulo the largest representable integer value. See <bibref ref="ISO10967"/>.</p>
                            </item>
                        </ulist>
                    </item>
                </ulist>
                <p>The functions <code>op:numeric-add</code>, <code>op:numeric-subtract</code>,
                    <code>op:numeric-multiply</code>, <code>op:numeric-divide</code>,
                    <code>op:numeric-integer-divide</code> and <code>op:numeric-mod</code> 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 <code>op:numeric-unary-plus</code> and
                    <code>op:numeric-unary-minus</code> 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 <termref def="implementation-defined"/>. 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 <termref def="implementation-defined"/> manner.</p>
                <div3 id="func-numeric-add">
                    <head>op:numeric-add</head>
                    <example role="signature">
                        <proto name="numeric-add" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <p>Summary: Backs up the "+" operator and returns the arithmetic sum of its
                        operands: (<code>$arg1 + $arg2</code>).</p>
<note>                   
                        <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>
</note>                   
                </div3>
                <div3 id="func-numeric-subtract">
                    <head>op:numeric-subtract</head>
                    <example role="signature">
                        <proto name="numeric-subtract" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <p>Summary: Backs up the "-" operator and returns the arithmetic difference of
                        its operands: (<code>$arg1 - $arg2</code>).</p>
<note>                   
                        <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>
</note>                   
                </div3>
                <div3 id="func-numeric-multiply">
                    <head>op:numeric-multiply</head>
                    <example role="signature">
                        <proto name="numeric-multiply" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <p>Summary: Backs up the "*" operator and returns the arithmetic product of its
                        operands: (<code>$arg1 * $arg2</code>).</p>
<note>
                        <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>
</note>
                </div3>
                <div3 id="func-numeric-divide">
                    <head>op:numeric-divide</head>
                    <example role="signature">
                        <proto name="numeric-divide" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <p>Summary: Backs up the "div" operator and returns the arithmetic quotient of
                        its operands: (<code>$arg1 div $arg2</code>).</p>
                    <!-- Integer arithmetic proposal -->
                    <!--						<p>For compatibility with <bibref ref="xpath"/>, if the types of both <code>$arg1</code> and <code>$arg2</code> are <code>xs:integer</code>, then the return type is <code>xs:double</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>
<notes>
                    <p>For <code>xs:decimal</code> and <code>xs:integer</code> operands, if the
                        divisor is (positive or negative) zero, an error is raised <errorref class="AR" code="0001"/>.
                        For <code>xs:float</code> and <code>xs:double</code> operands, floating point
                        division is performed as specified in <bibref ref="ieee754"/>.</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></notes>
                   
                </div3>
                <div3 id="func-numeric-integer-divide">
                    <head>op:numeric-integer-divide</head>
                    <example role="signature">
                        <proto name="numeric-integer-divide" return-type="xs:integer" isOp="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <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 <quote>
                            <code>$a idiv $b</code>
                        </quote> are equivalent to <quote>
                            <code>($a div $b) cast as xs:integer</code>
                        </quote> except for error situations.</p>
                    <p>If the divisor is (positive or negative) zero, then an error is raised <errorref class="AR" code="0001"/>.  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 <errorref class="AR" code="0002"/>.</p>
                    <note>
                        <p>The semantics of this function are different from integer division as
                            defined in programming languages such as Java and C++.</p>
                    </note>
                    <div4 id="func-numeric-integer-divide-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(10,3)</code> returns <code>3</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(3,-2)</code> returns <code>-1</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(-3,2)</code> returns <code>-1</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(-3,-2)</code> returns <code>1</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(9.0,3)</code> returns <code>3</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(-3.5,3)</code> returns <code>-1</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(3.0,4)</code> returns <code>0</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(3.1E1,6)</code> returns <code>5</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-integer-divide(3.1E1,7)</code> returns <code>4</code>
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-numeric-mod">
                    <head>op:numeric-mod</head>
                    <example role="signature">
                        <proto name="numeric-mod" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric"/>
                            <arg name="arg2" type="numeric"/>
                        </proto>
                    </example>
                    <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 <errorref class="AR" code="0001"/>.</p>
                    <p> For <code>xs:float</code> and <code>xs:double</code> operands the following
                        rules apply:</p>
                    <ulist>
                        <item>
                            <p>If either operand is <code>NaN</code>, the result is <code>NaN</code>.</p>
                        </item>
                        <item>
                            <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>
                        </item>
                        <!--								<item>
									<p>The sign of the result is the same as the sign of the dividend.</p>
								</item> -->
                        <item>
                            <p>If the dividend is finite and the divisor is an infinity, the result
                                equals the dividend.</p>
                        </item>
                        <item>
                            <p>If the dividend is positive or negative zero and the divisor is
                                finite, the result is the same as the dividend.</p>
                        </item>
                        <item>
                            <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>.

                                <!--float or double remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n-(d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d.  -->
                                Division is truncating division, analogous to integer division,
                                    not <bibref ref="ieee754"/> rounding division i.e. additional
                                digits are truncated, not rounded to the required precision.</p>
                        </item>
                    </ulist>
                    <div4 id="func-numeric-mod-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>op:numeric-mod(10,3)</code> returns <code>1</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-mod(6,-2)</code> returns <code>0</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-mod(4.5,1.2)</code> returns <code>0.9</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>op:numeric-mod(1.23E2, 0.6E1)</code> returns <code>3.0E0</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-numeric-unary-plus">
                    <head>op:numeric-unary-plus</head>
                    <example role="signature">
                        <proto name="numeric-unary-plus" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg" type="numeric"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-numeric-unary-minus">
                    <head>op:numeric-unary-minus</head>
                    <example role="signature">
                        <proto name="numeric-unary-minus" return-type="numeric" returnVaries="yes" isOp="yes" returnEmptyOk="no" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg" type="numeric"/>
                        </proto>
                    </example>
                    <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>
                </div3>
            </div2>
            <div2 id="comp.numeric">
                <head>Comparison Operators on Numeric Values</head>
                <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 <specref ref="op.numeric"/>. Each comparison operator returns a boolean
                    value. If either, or both, operands are <code>NaN</code>, <code>false</code> is
                    returned. </p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Operator</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:numeric-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison</td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-numeric-equal">
                    <head>op:numeric-equal</head>
                    <example role="signature">
                        <proto name="numeric-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric" emptyOk="no"/>
                            <arg name="arg2" type="numeric" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-numeric-less-than">
                    <head>op:numeric-less-than</head>
                    <example role="signature">
                        <proto name="numeric-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric" emptyOk="no"/>
                            <arg name="arg2" type="numeric" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-numeric-greater-than">
                    <head>op:numeric-greater-than</head>
                    <example role="signature">
                        <proto name="numeric-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="numeric" emptyOk="no"/>
                            <arg name="arg2" type="numeric" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
            </div2>
            <div2 id="numeric-value-functions">
                <head>Functions on Numeric Values</head>
                <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>
                <ulist>
                    <item>
                        <p>If the argument is the empty sequence, the empty sequence is returned.</p>
                    </item>
                    <item>
                        <p>For <code>xs:float</code> and <code>xs:double</code> arguments, if the
                            argument is "NaN", "NaN" is returned.</p>
                    </item>
                    <item>
                        <p>Except for <code>fn:abs()</code>, 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>
                    </item>
                </ulist>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:abs</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the absolute value of the argument.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:ceiling</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the smallest number with no fractional part that is greater
                                than or equal to the argument.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:floor</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the largest number with no fractional part that is less than
                                or equal to the argument.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:round</code>
                            </td>
                            <td rowspan="1" colspan="1">Rounds to the nearest number with no fractional part.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:round-half-to-even</code>
                            </td>
                            <td rowspan="1" colspan="1">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>
                <div3 id="func-abs">
                    <head>fn:abs</head>
                    <example role="signature">
                        <proto name="abs" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <xspecref spec="FS" ref="sec_fn_abs_ceil_floor_round"/>
                    </p>
                    <div4 id="func-abs-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:abs(10.5)</code> returns <code>10.5</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:abs(-10.5)</code> returns <code>10.5</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-ceiling">
                    <head>fn:ceiling</head>
                    <example role="signature">
                        <proto name="ceiling" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <xspecref spec="FS" ref="sec_fn_abs_ceil_floor_round"/>
                    </p>
                   <div4 id="func-ceiling-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:ceiling(10.5)</code> returns <code>11</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ceiling(-10.5)</code> returns <code>-10</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-floor">
                    <head>fn:floor</head>
                    <example role="signature">
                        <proto name="floor" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <xspecref spec="FS" ref="sec_fn_abs_ceil_floor_round"/>
                    </p>
                    <div4 id="func-floor-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:floor(10.5)</code> returns <code>10</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:floor(-10.5)</code> returns <code>-11</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-round">
                    <head>fn:round</head>
                    <example role="signature">
                        <proto name="round" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <bibref ref="xmlschema-2"/> 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 <code>fn:floor(x+0.5)</code>.</p>
                    <p>For detailed type semantics, see <xspecref spec="FS" ref="sec_fn_abs_ceil_floor_round"/>
                    </p>
                    <div4 id="func-round-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:round(2.5)</code> returns <code>3.</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round(2.4999)</code> returns <code>2</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round(-2.5)</code> returns <code>-2</code> (not the
                                    possible alternative, <code>-3</code>). </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-round-half-to-even">
                    <head>fn:round-half-to-even</head>
                    <example role="signature">
                        <proto name="round-half-to-even" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto name="round-half-to-even" return-type="numeric" returnEmptyOk="yes" returnVaries="yes" returnSeq="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="numeric" emptyOk="yes"/>
                            <arg name="precision" type="xs:integer" emptyOk="no"/>
                        </proto>
                    </example>
                    <p>Summary: The value returned is the nearest (that is, numerically closest)
                        numeric 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...), returns the one
                        whose least significant digit is even. 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> 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 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.</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 <xspecref spec="FS" ref="sec_fn_abs_ceil_floor_round"/>
                    </p>
                    <!--
<p>For detailed type semantics, see section 6.2.6 of <bibref
		  ref='xquery-semantics'/>.</p> -->
                    <div4 id="func-round-half-to-even-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(0.5)</code> returns <code>0</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(1.5)</code> returns <code>2</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(2.5)</code> returns <code>2</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(3.567812E+3, 2)</code> returns <code>3567.81E0</code>.
                                    <!-- If this were to be serialized, its canonical form <code>"3.56781E3"</code> would be returned. -->
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(4.7564E-3, 2)</code> returns
                                    <code>0.0E0</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:round-half-to-even(35612.25, -2)</code> returns
                                    <code>35600</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
        </div1>
        <div1 id="string-functions">
            <head>Functions on Strings</head>
            <p>This section discusses functions and operators on the <bibref ref="xmlschema-2"/>
                <code>xs:string</code> datatype and the datatypes derived from it.</p>
            <div2 id="string-types">
                <head>String Types</head>
                <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 border="0" summary="Type summary" role="hierarchy">
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">xs:string</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:normalizedString</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:token</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:language</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:NMTOKEN</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:Name</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:NCName</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:ID</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">xs:IDREF</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1"/>
                            <td rowspan="1" colspan="1">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 <termref def="implementation-defined"/> which version of <bibref ref="Unicode4"/> 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 <bibref ref="charmod"/>.</p>
                <notes>
                    <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 <bibref ref="charmod"/>. The use of the word "character" in this document is in the sense of production [2] of <bibref ref="REC-xml"/>.  <bibref ref="Unicode4"/>, defines code points that range from #x0000 to #x10FFFF inclusive and may include code points
                        that have not yet been assigned to characters.</p>
                    <!--  Code points range from x0000 to x10FFFF
inclusive, except for the range xD800 to xDFFF inclusive, which is the
range reserved for surrogates.</p> -->
                    <p>In functions that involve character counting such
                        as <code>fn:substring</code>, <code>fn:string-length</code> and
                        <code>fn:translate</code>, 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>
                </notes>
               
            </div2>
            <div2 id="func-assemble-disassemble-string">
                <head>Functions to Assemble and Disassemble Strings</head>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:codepoints-to-string</code>
                            </td>
                            <td rowspan="1" colspan="1">Creates an <code>xs:string</code> from a sequence of Unicode code points. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:string-to-codepoints</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the sequence of Unicode code points that constitute an
                                <code>xs:string</code>. </td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-codepoints-to-string">
                    <head>fn:codepoints-to-string</head>
                    <example role="signature">
                        <proto name="codepoints-to-string" return-type="xs:string" returnEmptyOk="no" isOp="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg" type="xs:integer*" emptyOk="no"/>
                        </proto>
                    </example>
                    <p>Summary: Creates an <code>xs:string</code> from a sequence of <bibref ref="Unicode4"/> 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 <errorref class="CH" code="0001"/>.</p>
                    <div4 id="func-codepoints-to-string-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:codepoints-to-string((2309, 2358, 2378, 2325))</code>
                                    returns "अशॊक"</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-string-to-codepoints">
                    <head>fn:string-to-codepoints</head>
                    <example role="signature">
                        <proto name="string-to-codepoints" return-type="xs:integer*" returnEmptyOk="no" isOp="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns the sequence of <bibref ref="Unicode4"/>           
                    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>
                    <div4 id="func-string-to-codepoints-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:string-to-codepoints("Thérèse")</code>
                                    returns the sequence (84, 104, 233, 114, 232, 115, 101)</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="string-compare">
                <head>Equality and Comparison of Strings</head>
                <div3 id="collations">
                    <head>Collations</head>
                    <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 <bibref ref="charmod"/> 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 <bibref ref="Unicode-Collations"/> 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/2006/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 <bibref ref="charmod-normalization"/> 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 <bibref ref="LDML"/>.
</p>
                    <p>Functions such as <code>fn:compare</code> and <code>fn:max</code> 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 <quote>
                            <code>http://www.example.com/collations/French</code>
                        </quote> 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 <quote>
                            <code>http://www.example.com/collations/French1</code>
                        </quote> and <quote>
                            <code>http://www.example.com/collations/French2</code>
                        </quote>. 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 <xspecref spec="XP" ref="static_context"/>. 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/2006/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>
                    <olist>
                        <item>
                            <p>If the function specifies an explicit collation, CollationA (e.g., if
                                the optional collation argument is specified in an invocation of the
                                <code>fn:compare()</code> function), then:</p>
                            <ulist>
                                <item>
                                    <p>If CollationA is supported by the implementation, then
                                        CollationA is used. </p>
                                </item>
                                <item>
                                    <p>Otherwise, an error is raised <errorref class="CH" code="0002"/>. </p>
                                </item>
                            </ulist>
                        </item>
                        <!--
			<item><p>If no collation is explicitly specified for the
			function and the function is <code>fn:contains</code>,
			<code>fn:starts-with</code>, <code>fn:ends-with</code>,
			<code>fn:substring-before</code> or
			<code>fn:substring-after</code> the  Unicode code point collation (<code>http://www.w3.org/&date.year;/xpath-functions/collation/codepoint</code>) is used.</p></item> -->
                        <item>
                            <p>If no collation is explicitly specified for the function
                                <!-- and the function is not one of the above functions --> and the
                                default collation in the XQuery/XPath static context is CollationB, then:</p>
                            <ulist>
                                <item>
                                    <p>If CollationB is supported by the implementation, then
                                        CollationB is used. </p>
                                </item>
                                <item>
                                    <p>Otherwise, an error is raised <errorref class="CH" code="0002"/>. </p>
                                </item>
                            </ulist>
                        </item>
                    </olist>
                    <note>
                        <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
                            <!-- , in part because collations should be determined by the user of -->
                            <!-- the data, not (normally) the data itself, and --> 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>
                    </note>
                    <!--				<note><p>Some data management environments allow collations to be associated with the definition of string items (that is, with the metadata that describes items whose type is string).  While such association may be appropriate for use in environments in which data is held in a repository tightly bound to its descriptive metadata, it is not appropriate in the XML environment in which different documents being processed by a single query may be described by differing schemas.</p></note> -->
                    <table border="1" summary="Function/operator summary">
                        <thead>
                            <tr>
                                <th rowspan="1" colspan="1">Function</th>
                                <th rowspan="1" colspan="1">Meaning</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td rowspan="1" colspan="1">
                                    <code>fn:compare</code>
                                </td>
                                <td rowspan="1" colspan="1"> 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 rowspan="1" colspan="1">
                                    <code>fn:codepoint-equal</code>
                                </td>
                                <td rowspan="1" colspan="1">Returns <code>true</code> if the two arguments are equal using
                                    the Unicode code point collation. </td>
                                <td rowspan="1" colspan="1"/>
                            </tr>
                        </tbody>
                    </table>
                </div3>
                <div3 id="func-compare">
                    <head>fn:compare</head>
                    <example role="signature">
                        <proto name="compare" return-type="xs:integer" returnEmptyOk="yes" isOp="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="comparand1" type="xs:string" emptyOk="yes"/>
                            <arg name="comparand2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="compare" return-type="xs:integer" returnEmptyOk="yes" isOp="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="comparand1" type="xs:string" emptyOk="yes"/>
                            <arg name="comparand2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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 <specref ref="collations"/>. </p>
                    <!--
					<p>If the value of <code>$comparand2</code> begins
					with a string that is equal to the value of
					<code>$comparand1</code> (according to the
					collation that is used) and has additional code
					points following that beginning string, then the
					result is -1.  If the value of
					<code>$comparand1</code> begins with a string that
					is equal to the value of <code>$comparand2</code>
					(according to the collation that is used) and has
					additional code points following that beginning string, then the result is 1.</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>
                    <div4 id="func-compare-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:compare('abc', 'abc')</code> returns 0. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:compare('Strasse', 'Straße')</code> returns 0
                                    if and only if the default collation includes provisions that
                                    equate <quote>ss</quote> and the (German) character
                                    <quote>ß</quote> (<quote>sharp-s</quote>). (Otherwise,
                                    the returned value depends on the semantics of the default collation.)</p>
                            </item>
                            <item>
                                <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
                                    <quote>deutsch</quote> includes provisions that equate
                                    <quote>ss</quote> and the (German) character
                                    <quote>ß</quote> (<quote>sharp-s</quote>). (Otherwise,
                                    the returned value depends on the semantics of that collation.)</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:compare('Strassen', 'Straße')</code> returns 1
                                    if the default collation includes provisions that treat
                                    differences between <quote>ss</quote> and the (German) character
                                    <quote>ß</quote> (<quote>sharp-s</quote>) with less
                                    strength than the differences between the base characters, such
                                    as the final <quote>n</quote>.
                                    <!-- (Since the value of <code>$comparand1</code> has an additional
									character, an <quote>n</quote>,
									following the string that is equal
									to <quote>Stra&#xDF;e</quote>, it
									is greater than the value of
									<code>$comparand2</code>.) -->
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-codepoint-equal">
                    <head>fn:codepoint-equal</head>
                    <example role="signature">
                        <proto name="codepoint-equal" return-type="xs:boolean" returnEmptyOk="yes" isOp="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="comparand1" type="xs:string" emptyOk="yes"/>
                            <arg name="comparand2" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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/2006/xpath-functions/collation/codepoint</code>).</p>
                    <p>If either argument is the empty sequence, the result is the empty sequence. </p>
<note>
<p>This function allows <code>xs:anyURI</code> values to be compared without having to specify the Unicode code point collation.</p></note>
                </div3>
            </div2>
            <div2 id="string-value-functions">
                <head>Functions on String Values</head>
                <p>The following functions are defined on values of type <code>xs:string</code> and
                    types derived from it.</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:concat</code>
                            </td>
                            <td rowspan="1" colspan="1">Concatenates two or more <code>xs:anyAtomicType</code> arguments
                                cast to <code>xs:string</code>. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:string-join</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:substring</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the <code>xs:string</code> located at a specified place
                                within an argument <code>xs:string</code>. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:string-length</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the length of the argument. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:normalize-space</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the whitespace-normalized value of the argument.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:normalize-unicode</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the normalized value of the first argument in the
                                normalization form specified by the second argument.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:upper-case</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the upper-cased value of the argument. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:lower-case</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the lower-cased value of the argument. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:translate</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:encode-for-uri</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:iri-to-uri</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:escape-html-uri</code>
                            </td>
                            <td rowspan="1" colspan="1">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>
                <notes>
                    <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 <code>fn:concat</code> and <code>fn:string-join</code> are not guaranteed to be normalized.  But see note in <code>fn:concat</code>.
                </p>
                </notes>
                <div3 id="func-concat">
                    <head>fn:concat</head>
                    <example role="signature">
                        <proto name="concat" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:anyAtomicType" emptyOk="yes"/>
                            <arg name="arg2" type="xs:anyAtomicType" emptyOk="yes"/>
                            <arg name="..." type="" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <bibref ref="xpath"/>. </p>
<note>
<p>As mentioned in the note above, the result of <code>fn:concat</code> may not be normalized.  If a normalized result is required, <code>fn:normalize-unicode</code> can be applied to the <code>xs:string</code> returned by <code>fn:concat</code>.  The following XQuery:</p>
<eg xml:space="preserve">
let $v1 := "I plan to go to Mu"
let $v2 := "?nchen in September"
return concat($v1, $v2)</eg>

<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>
<eg xml:space="preserve">
let $v1 := "I plan to go to Mu"
let $v2 := "?nchen in September"
return normalize-unicode(concat($v1, $v2))</eg>

<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>
</note>
                    <div4 id="func-concat-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:concat('un', 'grateful')</code> returns <quote>
                                        <code>ungrateful</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:concat('Thy ', (), 'old ', "groans", "", ' ring', '
                                        yet', ' in', ' my', ' ancient',' ears.')</code> returns <quote>
                                        <code>Thy old groans ring yet in my ancient ears.</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:concat('Ciao!',())</code> returns <quote>
                                        <code>Ciao!</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:concat('Ingratitude, ', 'thou ', 'marble-hearted', '
                                    fiend!')</code> returns <quote>
                                        <code>Ingratitude, thou marble-hearted fiend!</code>
                                    </quote>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-string-join">
                    <head>fn:string-join</head>
                    <example role="signature">
                        <proto name="string-join" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string*" emptyOk="no"/>
                            <arg name="arg2" type="xs:string" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-string-join-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:string-join(('Now', 'is', 'the', 'time', '...'), '
                                    ')</code> returns <quote>
                                        <code>Now is the time ...</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:string-join(('Blow, ', 'blow, ', 'thou ', 'winter ',
                                        'wind!'), '')</code> returns <quote>
                                        <code>Blow, blow, thou winter wind!</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:string-join((), 'separator')</code> returns <quote/>. </p>
                            </item>
                            <item>
                                <p>Assume a document:</p>
                                <eg xml:space="preserve">&lt;doc&gt;
  &lt;chap&gt;
    &lt;section&gt;
    &lt;/section&gt;
  &lt;/chap&gt;
&lt;/doc&gt;</eg>
                                <p>with the <code>&lt;section&gt;</code> as the context node,
                                    the <bibref ref="xpath20"/> expression: </p>
                                <p>
                                    <code>fn:string-join(for $n in ancestor-or-self::* return
                                        name($n), '/')</code>
                                </p>
                                <p> returns <quote>
                                        <code>doc/chap/section</code>
                                    </quote>
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-substring">
                    <head>fn:substring</head>
                    <example role="signature">
                        <proto name="substring" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="sourceString" type="xs:string" emptyOk="yes"/>
                            <arg name="startingLoc" type="xs:double" emptyOk="no"/>
                        </proto>
                        <proto name="substring" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="sourceString" type="xs:string" emptyOk="yes"/>
                            <arg name="startingLoc" type="xs:double" emptyOk="no"/>
                            <arg name="length" type="xs:double" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                        <code>fn:round($startingLoc) &lt;= $p &lt; fn:round($startingLoc) + fn:round($length)</code>
                    </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>
                        <code>fn:round($startingLoc) &lt;= $p &lt; fn:round(INF)</code>
                    </p>
                    <p>In the above computations, the rules for <code>op:numeric-less-than()</code>
                        and <code>op:numeric-greater-than()</code> apply.</p>
                    <p>If the value of <code>$sourceString</code> is the empty sequence, the
                        zero-length string is returned. </p>
                    <!--					
					<p>If <code>$startingLoc</code>
is zero or negative, the substring includes characters from the beginning of the <code>$sourceString</code>.</p>
					<p>If <code>$length</code> is not specified, the substring includes characters to the end of <code>$sourceString</code>. </p>
					<p>If <code>$length</code> is
	  greater than the number of characters in the value of
	  <code>$sourceString</code> following
	  <code>$startingLoc</code>, the substring includes characters
	  to the end of <code>$sourceString</code>. </p> -->
                    <note>
                        <p>The first character of a string is located at position 1, not position 0.</p>
                    </note>
                    <div4 id="func-substring-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring("12345", 1, 0 div 0E0)</code> returns <code>""</code>.</p>
                                <p>As above.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring((), 1, 3)</code> returns <code>""</code>.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-string-length">
                    <head>fn:string-length</head>
                    <example role="signature">
                        <proto name="string-length" return-type="xs:integer" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                    </example>
                    <example role="signature">
                        <proto name="string-length" return-type="xs:integer" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <code>fn:string()</code>) 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: <xerrorref spec="XP" class="DY" code="0002" type="type"/>.</p>
                    <div4 id="func-string-length-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:string-length("Harp not on that string, madam; that is
                                    past.")</code> returns <code>45</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:string-length(())</code> returns <code>0</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-normalize-space">
                    <head>fn:normalize-space</head>
                    <example role="signature">
                        <proto name="normalize-space" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                    </example>
                    <example role="signature">
                        <proto name="normalize-space" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <bibref ref="REC-xml"/>.</p>

                    <note>
                    <p>The definition of the metasymbol S (Production 3), is unchanged
                    in <bibref ref="xml11"/>. </p>
                    </note>
<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 <code>fn:string()</code>) 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: <xerrorref spec="XP" class="DY" code="0002" type="type"/>.
                    </p>
                    <div4 id="func-normalize-space-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:normalize-space(" The  wealthy curled darlings
                                        of   our  nation. ")</code>
                                    returns <quote>
                                        <code>The wealthy curled darlings of our nation.</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:normalize-space(())</code> returns <quote/>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-normalize-unicode">
                    <head>fn:normalize-unicode</head>
                    <example role="signature">
                        <proto name="normalize-unicode" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="normalize-unicode" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                            <arg name="normalizationForm" type="xs:string"/>
                        </proto>
                    </example>
                    <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 <bibref ref="charmod-normalization"/> 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>
                    <ulist>
                        <item>
                            <p>If the effective value of <code>$normalizationForm</code> is
                                <quote>NFC</quote>, then the value returned by the function is the
                                value of <code>$arg</code> in Unicode Normalization Form C (NFC).</p>
                        </item>
                        <item>
                            <p>If the effective value of <code>$normalizationForm</code> is
                                <quote>NFD</quote>, then the value returned by the function is the
                                value of <code>$arg</code> in Unicode Normalization Form D (NFD).</p>
                        </item>
                        <item>
                            <p>If the effective value of <code>$normalizationForm</code> is
                                <quote>NFKC</quote>, then the value returned by the function is the
                                value of <code>$arg</code> in Unicode Normalization Form KC (NFKC).</p>
                        </item>
                        <item>
                            <p>If the effective value of <code>$normalizationForm</code> is
                                <quote>NFKD</quote>, then the value returned by the function is the
                                value of <code>$arg</code> in Unicode Normalization Form KD (NFKD).</p>
                        </item>
                        <item>
                            <p>If the effective value of <code>$normalizationForm</code> is
                                <quote>FULLY-NORMALIZED</quote>, then the value returned by the
                                function is the value of <code>$arg</code> in the fully normalized form.
                            </p>
                        </item>
                        <item>
                            <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>
                        </item>
                        <!--						<item>
							<p>Implementations may choose to support other normalization forms in addition to the normalization forms discussed above.</p>
						</item> -->
                    </ulist>
                    <p>Conforming implementations <termref def="must"/> support normalization form
                        "NFC" and <termref def="may"/> support normalization forms "NFD", "NFKC",
                        "NFKD", "FULLY-NORMALIZED". They <termref def="may"/> also support other
                        normalization forms with <termref def="implementation-defined"/> 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
                            <errorref class="CH" code="0003"/>.</p>
                </div3>
                <div3 id="func-upper-case">
                    <head>fn:upper-case</head>
                    <example role="signature">
                        <proto name="upper-case" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    
<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 <bibref ref="Unicode4"/>. 
For versions of Unicode beginning with 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>
                    <note>
                        <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 <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>
                    </note>
                    <div4 id="func-upper-case-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:upper-case("abCd0")</code> returns
                                    <code>"ABCD0"</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-lower-case">
                    <head>fn:lower-case</head>
                    <example role="signature">
                        <proto name="lower-case" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
<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 <bibref ref="Unicode4"/>. 
For versions of Unicode beginning with 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>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 <bibref ref="Unicode4"/>. 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 is case mappings in the absence of
    tailoring for particular languages and environments.  Every character that does not
                        have an lower-case correspondent 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>
                    <note>
                        <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 <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>
                    </note>
                    <div4 id="func-lower-case-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:lower-case("ABc!D")</code> returns
                                    <code>"abc!d"</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-translate">
                    <head>fn:translate</head>
                    <example role="signature">
                        <proto name="translate" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:string" emptyOk="yes"/>
                            <arg name="mapString" type="xs:string" emptyOk="no"/>
                            <arg name="transString" type="xs:string" emptyOk="no"/>
                        </proto>
                    </example>
                    <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
                        <emph>N</emph> in the value of <code>$mapString</code> has been replaced by
                        the character that occurs at position <emph>N</emph> 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 <emph>M</emph> in the value of <code>$mapString</code>, where the
                        value of <code>$transString</code> is less than <emph>M</emph> 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>
                    <div4 id="func-translate-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:translate("bar","abc","ABC")</code> returns <code>"BAr"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:translate("--aaa--","abc-","ABC")</code> returns <code>"AAA"</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:translate("abcdabc", "abc", "AB")</code> returns
                                    <code>"ABdAB"</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <!--			<div3 id="func-string-pad">
					<head>fn:string-pad</head>
					<example role="signature">
						<proto name="string-pad" return-type="xs:string" returnEmptyOk="yes">
							<arg name="padString" type="xs:string" emptyOk="yes"/>
							<arg name="padCount" type="xs:integer" emptyOk="no"/>
						</proto>
					</example>
					<p> If the value of <code>$padString</code> is the empty sequence, returns the empty sequence.</p>
					<p>Otherwise, returns an <code>xs:string</code> consisting of <code>$padCount</code> copies of <code>$padString</code> concatenated together without any separators. Returns the zero-length string if <code>$padCount</code> is zero (0).</p>
					<p>If the value of <code>$padCount</code> is less than zero (0), an error is raised <errorref class="RG" code="0002"/>.</p>
					<div4 id="func-string-pad-examples">
						<head>Examples</head>
						<ulist>
							<item>
								<p>
									<code>fn:string-pad("XMLQuery", 2)</code> returns <code>"XMLQueryXMLQuery"</code>.</p>
							</item>
							<item>
								<p>
									<code>fn:string-pad(" ", 4)</code> returns a string containing four spaces.</p>
							</item>
							<item>
								<p>
									<code>fn:string-pad(" ", 0)</code> returns the zero-length string.</p>
							</item>
							<item>
								<p>
									<code>fn:string-pad(" ", -3)</code> results in an error being raised <errorref class="RG" code="0002"/>.</p>
							</item>
						</ulist>
					</div4>
				</div3> -->
                <div3 id="func-encode-for-uri">
                    <head>fn:encode-for-uri</head>
                    <example role="signature">
                        <proto name="encode-for-uri" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="uri-part" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
<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 <bibref ref="rfc3986"/> 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 <bibref ref="rfc3986"/>.</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 <bibref ref="rfc3986"/>, 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 <bibref ref="rfc3986"/> 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>
                  <div4 id="func-encode-for-uri-examples">
                        <head>Examples</head>
 						<ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
<code>concat("http://www.example.com/", encode-for-uri("100% organic"))</code>
      returns <code>"http://www.example.com/100%25%20organic"</code>.
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
  <div3 id="func-iri-to-uri">
                    <head>fn:iri-to-uri</head>
                    <example role="signature">
                        <proto name="iri-to-uri" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="uri-part" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
<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 <bibref ref="rfc3987"/>  It is idempotent but not invertible.</p>
<p>If <code>$uri-part</code> contains a character that is invalid in an IRI, such as a space character, the invalid character is 
replaced by its percent-encoded form as described in <bibref ref="rfc3986"/> before the conversion is performed.</p>

<p>
If <code>$uri-part</code> is the empty sequence, returns the zero-length string.</p>
<p>
Since <bibref ref="rfc3986"/> 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>

<notes>
<p>
This function does not check whether <code>$uri-part</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>
  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></notes>
                <div4 id="func-iri-to-uri-examples">
                        <head>Examples</head>
                        <ulist>
 							<item>
                                <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>
                            </item>
                           <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
 <div3 id="func-escape-html-uri">
                    <head>fn:escape-html-uri</head>
                    <example role="signature">
                        <proto name="escape-html-uri" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="uri" type="xs:string" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                            
                  
<note>
                        <p>The behavior of this function corresponds to the recommended handling 
of non-ASCII characters in URI attribute values as described in <bibref ref="HTML40"/> Appendix B.2.1.

</p>
                    </note>
                   
                    <div4 id="func-escape-html-uri-examples">
                        <head>Examples</head>
                        <ulist>
 							<item>
                                <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>
                            </item>
                           <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="substring.functions">
                <head>Functions Based on Substring Matching</head>
                <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 <code>fn:compare()</code>, this is
                    all that is required. For other functions, such as <code>fn:contains()</code>,
                    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 <bibref ref="Unicode-Collations"/>.) 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 <code>fn:contains("Jäger", "eg")</code> will return
                    <code>true</code>. Alternatively, a collation might treat "ae" as a single
                    collation unit, in which case the expression <code>fn:contains("Jaeger",
                    "eg")</code> 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 <bibref ref="Unicode-Collations"/> 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 <termref def="implementation-defined"/> property of the collation.</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:contains</code>
                            </td>
                            <td rowspan="1" colspan="1">Indicates whether one <code>xs:string</code> contains another
                                <code>xs:string</code>. A collation may be specified. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:starts-with</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:ends-with</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:substring-before</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:substring-after</code>
                            </td>
                            <td rowspan="1" colspan="1">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>
                <div3 id="func-contains">
                    <head>fn:contains</head>
                    <example role="signature">
                        <proto name="contains" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="contains" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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>
                    <note>
                        <p>"Minimal match" is defined in <bibref ref="Unicode-Collations"/>. </p>
                    </note>
                    <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 <specref ref="collations"/>. If the specified collation does
                        not support collation units an error <termref def="may"/> be raised
                            <errorref class="CH" code="0004"/>.</p>
                    <div4 id="func-contains-examples">
                        <head>Examples</head>
                        <p>CollationA used in these examples is a collation in which both "-" and
                            "*" are ignorable collation units.</p>
                        <note>
                            <p>"Ignorable collation unit" is equivalent to "ignorable collation
                                element" in <bibref ref="Unicode-Collations"/>.</p>
                        </note>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:contains ( "tattoo", "t")</code> returns <code>true</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:contains ( "tattoo", "ttt")</code> returns <code>false</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:contains ( "", ())</code> returns <code>true</code>.  The first rule is applied, followed by the second rule.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:contains ( "abcdefghi", "-d-e-f-", "CollationA")</code>
                                    returns <code>true</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:contains ( "a*b*c*d*e*f*g*h*i*", "d-ef-",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:contains ( "abcd***e---f*--*ghi", "def",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-starts-with">
                    <head>fn:starts-with</head>
                    <example role="signature">
                        <proto name="starts-with" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="starts-with" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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>
                    <note>
                        <p>"Minimal match" is defined in <bibref ref="Unicode-Collations"/>. </p>
                    </note>
                    <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 <specref ref="collations"/>. If the specified collation does
                        not support collation units an error <termref def="may"/> be raised
                            <errorref class="CH" code="0004"/>.</p>
                    <div4 id="func-starts-with-examples">
                        <head>Examples</head>
                        <p>CollationA used in these examples is a collation in which both "-" and
                            "*" are ignorable collation units.</p>
                        <note>
                            <p>"Ignorable collation unit" is equivalent to "ignorable collation
                                element" in <bibref ref="Unicode-Collations"/>.</p>
                        </note>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:starts-with("tattoo", "tat")</code> returns
                                    <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:starts-with ( "tattoo", "att")</code> returns
                                    <code>false</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:starts-with ((), ())</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:starts-with ( "abcdefghi", "-a-b-c-",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:starts-with ( "a*b*c*d*e*f*g*h*i*", "a-bc-",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:starts-with ( "abcd***e---f*--*ghi", "abcdef",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-ends-with">
                    <head>fn:ends-with</head>
                    <example role="signature">
                        <proto name="ends-with" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="ends-with" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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>
                    <note>
                        <p>"Minimal match" is defined in <bibref ref="Unicode-Collations"/>. </p>
                    </note>
                    <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 <specref ref="collations"/>. If the specified collation does
                        not support collation units an error <termref def="may"/> be raised
                            <errorref class="CH" code="0004"/>.</p>
                    <div4 id="func-ends-with-examples">
                        <head>Examples</head>
                        <p>CollationA used in these examples is a collation in which both "-" and
                            "*" are ignorable collation units.</p>
                        <note>
                            <p>"Ignorable collation unit" is equivalent to "ignorable collation
                                element" in <bibref ref="Unicode-Collations"/>.</p>
                        </note>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:ends-with ( "tattoo", "tattoo")</code> returns
                                    <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ends-with ( "tattoo", "atto")</code> returns
                                    <code>false</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ends-with ((), ())</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ends-with ( "abcdefghi", "-g-h-i-",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ends-with ( "abcd***e---f*--*ghi", "defghi",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:ends-with ( "abcd***e---f*--*ghi", "defghi",
                                    "CollationA")</code> returns <code>true</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-substring-before">
                    <head>fn:substring-before</head>
                    <example role="signature">
                        <proto name="substring-before" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="substring-before" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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>
                    <note>
                        <p>"Minimal match" is defined in <bibref ref="Unicode-Collations"/>. </p>
                    </note>
                    <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 <specref ref="collations"/> If the specified collation does
                        not support collation units an error <termref def="may"/> be raised
                            <errorref class="CH" code="0004"/>.</p>
                    <div4 id="func-substring-before-example">
                        <head>Examples</head>
                        <p>CollationA used in these examples is a collation in which both "-" and
                            "*" are ignorable collation units.</p>
                        <note>
                            <p>"Ignorable collation unit" is equivalent to "ignorable collation
                                element" in <bibref ref="Unicode-Collations"/>.</p>
                        </note>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:substring-before ( "tattoo", "attoo")</code> returns <quote><code>t</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-before ( "tattoo", "tatto")</code> returns <quote><code/></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-before ((), ())</code> returns <quote><code/></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-before ( "abcdefghi", "--d-e-",
                                    "CollationA")</code> returns <quote><code>abc</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-before ( "abc--d-e-fghi", "--d-e-",
                                    "CollationA")</code> returns <quote><code>abc--</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-before ( "a*b*c*d*e*f*g*h*i*", "***cde",
                                    "CollationA")</code> returns <quote><code>a*b*</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code> fn:substring-before ( "Eureka!", "--***-*---",
                                    "CollationA")</code> returns <quote/>. The second argument
                                    contains only ignorable collation units and is equivalent to the
                                    zero-length string.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-substring-after">
                    <head>fn:substring-after</head>
                    <example role="signature">
                        <proto name="substring-after" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                        </proto>
                        <proto name="substring-after" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg1" type="xs:string" emptyOk="yes"/>
                            <arg name="arg2" type="xs:string" emptyOk="yes"/>
                            <arg name="collation" type="xs:string"/>
                        </proto>
                    </example>
                    <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>
                    <note>
                        <p>"Minimal match" is defined in <bibref ref="Unicode-Collations"/>. </p>
                    </note>
                    <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 <specref ref="collations"/> If the specified collation does
                        not support collation units an error <termref def="may"/> be raised
                            <errorref class="CH" code="0004"/>.</p>
                    <div4 id="func-substring-after-examples">
                        <head>Examples</head>
                        <p>CollationA used in these examples is a collation in which both "-" and
                            "*" are ignorable collation units.</p>
                        <note>
                            <p>"Ignorable collation unit" is equivalent to "ignorable collation
                                element" in <bibref ref="Unicode-Collations"/>.</p>
                        </note>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:substring-after("tattoo", "tat")</code> returns <quote><code>too</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-after ( "tattoo", "tattoo")</code> returns <quote><code/></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-after ((), ())</code> returns <quote><code/></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code> fn:substring-after ( "abcdefghi", "--d-e-",
                                    "CollationA")</code> returns <quote><code>fghi</code></quote>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-after ( "abc--d-e-fghi", "--d-e-",
                                    "CollationA")</code> returns <quote><code>-fghi</code>
                                    </quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-after ( "a*b*c*d*e*f*g*h*i*", "***cde***",
                                    "CollationA")</code> returns <quote><code>*f*g*h*i*</code></quote>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:substring-after ( "Eureka!", "--***-*---",
                                    "CollationA")</code> returns <quote><code>Eureka!</code></quote>. The second argument contains only ignorable collation
                                    units and is equivalent to the zero-length string.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="string.match">
                <head>String Functions that Use Pattern Matching</head>
                <p>The three functions described in this section make use of a regular expression
                    syntax for pattern matching. This is described below.</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:matches</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:replace</code>
                            </td>
                            <td rowspan="1" colspan="1">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 rowspan="1" colspan="1">
                                <code>fn:tokenize</code>
                            </td>
                            <td rowspan="1" colspan="1">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>
                <div3 id="regex-syntax">
                    <head>Regular Expression Syntax</head>
                    <p>The regular expression syntax used by these functions is defined in terms of
                        the regular expression syntax specified in XML Schema (see <bibref ref="xmlschema-2"/>), 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>
<note><p>
It is recommended that implementers consult <bibref ref="Unicode-Regex"/> for information on using regular expression processing on Unicode characters.</p></note>
                  
                        <p>The regular expression syntax and semantics are identical to those
                            defined in <bibref ref="xmlschema-2"/> with the following additions:</p>
                        <ulist>
                            <item>
                                <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 <bibref ref="xmlschema-2"/>:</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>
<note><p>The definition of Char (production [10]) in <bibref ref="xmlschema-2"/> has a known error in which it omits the left brace ("{") and right brace ("}").  That error is corrected here.</p></note>

                                <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>
                            </item>
                                                <item>
                                <p>
                                    <emph>Reluctant quantifiers</emph> are supported. They are
                                    indicated by a <quote>
                                        <code>?</code>
                                    </quote> following a quantifier. Specifically:</p>
                                <ulist>
                                    <item>
                                        <p>
                                            <code>X??</code> matches X, once or not at all</p>
                                    </item>
                                    <item>
                                        <p>
                                            <code>X*?</code> matches X, zero or more times</p>
                                    </item>
                                    <item>
                                        <p>
                                            <code>X+?</code> matches X, one or more times</p>
                                    </item>
                                    <item>
                                        <p>
                                            <code>X{n}?</code> matches X, exactly n times</p>
                                    </item>
                                    <item>
                                        <p>
                                            <code>X{n,}?</code> matches X, at least n times</p>
                                    </item>
                                    <item>
                                        <p>
                                            <code>X{n,m}?</code> matches X, at least n times, but
                                            not more than m times</p>
                                    </item>
                                </ulist>
                                <p>The effect of these quantifiers is that the regular expression
                                    matches the <emph>shortest</emph> possible substring consistent
                                    with the match as a whole succeeding. Without the <quote>
                                        <code>?</code>
                                    </quote>, the regular expression matches the
                                    <emph>longest</emph> possible substring.</p>
                                <p>To achieve this, the production in <bibref ref="xmlschema-2"/>:</p>
                                <p>
                                    <code>[4] quantifier ::= [?*+] | ( '{' quantity '}' )</code>
                                </p>
                                <p>is changed to:</p>
                                <p>
                                    <code>[4] quantifier ::= ( [?*+] | ( '{' quantity '}' ) ) '?'?</code>
                                </p>
                                <note>
                                    <p>Reluctant quantifiers have no effect on the results of the
                                        boolean <code>fn:matches</code> function, since this
                                        function is only interested in discovering whether a match
                                        exists, and not where it exists.</p>
                                </note>
                            </item>
                            <item>
                                <p>Sub-expressions (groups) within the regular expression are
                                    recognized. The regular expression syntax defined by <bibref ref="xmlschema-2"/> allows a regular expression to contain
                                    parenthesized sub-expressions, but attaches no special
                                    significance to them. The <code>fn:replace()</code> 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 <emph>last</emph> substring that it
                                    matched will be captured.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                       <div4 id="flags">
                        <head>Flags</head>
                        <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 <errorref class="RX" code="0001"/>.</p>
                        <p>The following options are defined:</p>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
 <item>
                                <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 *case-variant* 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><code>fn:lower-case(C1) eq fn:lower-case(C2)</code></p> 
                                    <p>  or </p>
                                    <p><code>fn:upper-case(C1) eq fn:upper-case(C2)</code></p>
                                    <p>
                                     Note that the case-variants of a character under this definition 
                                     are always single characters.</p>
                                    <olist><item><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></item>
                                    <item><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 
                                    <code>fn:lower-case("#x212A")</code> 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></item>
                                    <item><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></item>
                                    <item><p>
                                    All other constructs are unaffected by the "<code>i</code>" flag. 
                                    For example, 
                                    "\p{Lu}" continues to match upper-case letters only.</p></item>
                                    </olist>
                            </item>
  <item>
                                <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> <code>fn:matches("helloworld", "hello world", "x")</code> returns <code>true</code></p> 
                                    <p> <code>fn:matches("helloworld", "hello[ ]world", "x")</code> returns <code>false</code></p> 
                                    <p> <code>fn:matches("hello world", "hello\ sworld", "x")</code> returns <code>true</code></p> 
                                    <p> <code>fn:matches("hello world", "hello world", "x")</code> returns <code>false</code></p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-matches">
                    <head>fn:matches</head>
                    <example role="signature">
                        <proto name="matches" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                        </proto>
                        <proto name="matches" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                            <arg name="flags" type="xs:string" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <specref ref="flags"/>.</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>
                    <note>
                        <p>This is different from the behavior of patterns in <bibref ref="xmlschema-2"/>, where regular expressions are <emph>implicitly</emph> anchored.</p>
                    </note>
                    <p>An error is raised <errorref class="RX" code="0002"/> if the value of
                        <code>$pattern</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>. </p>
                    <p>An error is raised <errorref class="RX" code="0001"/> if the value of
                        <code>$flags</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>. </p>
                    <div4 id="func-matches-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:matches("abracadabra", "bra")</code> returns true</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches("abracadabra", "^a.*a$")</code> returns true</p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches("abracadabra", "^bra")</code> returns false</p>
                            </item>
                        </ulist>
                        <p>Given the source document:</p>
                        <eg xml:space="preserve">&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;</eg>
                        <p>the following function calls produce the following results, with the
                            <code>poem</code> element as the context node:</p>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:matches(., "Kaum.*krähen")</code> returns <code>false</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches(., "Kaum.*krähen", "s")</code> returns <code>true</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches(., "^Kaum.*gesehen,$", "m")</code> returns <code>true</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches(., "^Kaum.*gesehen,$")</code> returns <code>false</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:matches(., "kiki", "i")</code> returns <code>true</code>
                                </p>
                            </item>
                        </ulist>
                        <note>
                            <p>Regular expression matching is defined on the basis of Unicode code
                                points; it takes no account of collations.</p>
                        </note>
                    </div4>
                </div3>
                <!-- Mike Kay's regular expression proposal 2002-06-14 -->
                <div3 id="func-replace">
                    <head>fn:replace</head>
                    <example role="signature">
                        <proto name="replace" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                            <arg name="replacement" type="xs:string" emptyOk="no"/>
                        </proto>
                        <proto name="replace" return-type="xs:string" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                            <arg name="replacement" type="xs:string" emptyOk="no"/>
                            <arg name="flags" type="xs:string" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <specref ref="flags"/>.</p>
                    <p>The <code>$flags</code> argument is interpreted in the same manner as for the
                        <code>fn:matches()</code> 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>
<p>
<olist>
<item><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></item>
<item><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></item>
<item><p>
If <code>S</code>&lt;<code>N</code>&lt;=<code>9</code>, then the variable is replaced by the zero-length string.
</p></item>
<item><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></item>
</olist></p>
<p>
For example, if the replacement string is <quote><code>$23</code></quote> and there are 5 substrings, the result contains the value of the substring that matches the second sub-expression, followed by the digit <quote><code>3</code></quote>.</p>
<p>A literal <quote><code>$</code></quote> symbol must be written as <quote><code>\$</code></quote>.</p> 
<p>A literal <quote><code>\</code></quote> symbol must be written as <quote><code>\\</code></quote>.</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>
                    <eg xml:space="preserve"> fn:replace("abcd", "(ab)|(a)", "[1=$1][2=$2]") returns "[1=ab][2=]cd"</eg>
                    <p>An error is raised <errorref class="RX" code="0002"/> if the value of
                        <code>$pattern</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>. </p>
                    <p>An error is raised <errorref class="RX" code="0001"/> if the value of
                        <code>$flags</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>. </p>
                    <p>An error is raised <errorref class="RX" code="0003"/> if the pattern matches
                        a zero-length string, that is, if the expression <code>fn:matches("",
                            $pattern, $flags)</code> returns <code>true</code>. It is not an error,
                        however, if a captured substring is zero-length.</p>
                    <p>An error is raised <errorref class="RX" code="0004"/> 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 <errorref class="RX" code="0004"/> 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>
                    <div4 id="func-replace-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>replace("abracadabra", "bra", "*")</code> returns <code>"a*cada*"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("abracadabra", "a.*a", "*")</code> returns <code>"*"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("abracadabra", "a.*?a", "*")</code> returns <code>"*c*bra"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("abracadabra", "a", "")</code> returns <code>"brcdbr"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("abracadabra", "a(.)", "a$1$1")</code> returns <code>"abbraccaddabbra"</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("abracadabra", ".*?", "$1")</code> raises an
                                    error, because the pattern matches the zero-length string </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("AAAA", "A+", "b")</code> returns <quote>
                                        <code>b</code>
                                    </quote>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("AAAA", "A+?", "b")</code> returns <quote>
                                        <code>bbbb</code>
                                    </quote>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>replace("darted", "^(.*?)d(.*)$", "$1c$2")</code> returns <quote>
                                        <code>carted</code>
                                    </quote>. The first <quote>
                                        <code>d</code>
                                    </quote> is replaced.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <!-- Mike Kay's regular expression proposal 2002-06-14 -->
                <div3 id="func-tokenize">
                    <head>fn:tokenize</head>
                    <example role="signature">
                        <proto name="tokenize" return-type="xs:string*" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                        </proto>
                        <proto name="tokenize" return-type="xs:string*" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="input" type="xs:string" emptyOk="yes"/>
                            <arg name="pattern" type="xs:string" emptyOk="no"/>
                            <arg name="flags" type="xs:string" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <specref ref="flags"/>.</p>
                    <p> The <code>$flags</code> argument is interpreted in the same way as for the
                        <code>fn:matches()</code> 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 <code>fn:matches("", $pattern, $flags)</code> returns <code>true</code>,
                        then an error is raised: <errorref class="RX" code="0003"/>. </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>
                    <eg xml:space="preserve"> fn:tokenize("abracadabra", "(ab)|(a)") returns ("", "r", "c", "d", "r", "")</eg>
                    <p> An error is raised <errorref class="RX" code="0002"/> if the value of
                        <code>$pattern</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>.</p>
                    <p> An error is raised <errorref class="RX" code="0001"/> if the value of
                        <code>$flags</code> is invalid according to the rules described in section
                            <specref ref="regex-syntax"/>.</p>
                    <div4 id="func-tokenize-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:tokenize("The cat sat on the mat", "\s+")</code>
                                    returns <code>("The", "cat", "sat", "on", "the", "mat")</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:tokenize("1, 15, 24, 50", ",\s*")</code> returns
                                        <code>("1", "15", "24", "50")</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:tokenize("1,15,,24,50,", ",")</code> returns
                                        <code>("1", "15", "", "24", "50", "")</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:tokenize("abba", ".?")</code> raises the error
                                        <errorref class="RX" code="0003"/>.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
        </div1>
        <div1 id="anyURI-functions">
            <head>Functions on anyURI</head>
            <p>This section specifies functions that take anyURI as arguments.</p>
            <table border="1" summary="Function/operator summary">
                <thead>
                    <tr>
                        <th rowspan="1" colspan="1">Function</th>
                        <th rowspan="1" colspan="1">Meaning</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td rowspan="1" colspan="1">
                            <code>fn:resolve-uri</code>
                        </td>
                        <td rowspan="1" colspan="1">Returns an <code>xs:anyURI</code> representing an absolute
                            <code>xs:anyURI</code> given a base URI and a relative URI. </td>
                    </tr>
                    <!--	<tr>
							<td>
								<code>op:anyURI-equal</code>
							</td>
							<td>Returns <code>true</code> if the two arguments are equal. </td>
							<td/>
						</tr> -->
                </tbody>
            </table>
            <div2 id="func-resolve-uri">
                <head>fn:resolve-uri</head>
                <example role="signature">
                    <proto name="resolve-uri" return-type="xs:anyURI" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="relative" type="xs:string" emptyOk="yes"/>
                    </proto>
                </example>
                <example role="signature">
                    <proto name="resolve-uri" return-type="xs:anyURI" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="relative" type="xs:string" emptyOk="yes"/>
                        <arg name="base" type="xs:string"/>
                    </proto>
                </example>
<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 <errorref class="NS" code="0005"/>. </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 <bibref ref="rfc2396"/> or <bibref ref="rfc3986"/>, and the
                    resulting absolute URI reference is returned. An error may be raised <errorref class="RG" code="0009"/> 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 <errorref class="RG" code="0002"/>.</p>
                <p>If <code>$relative</code> is the empty sequence, the empty sequence is returned.</p>
                <note>
<!--
                    <p>If <code>$relative</code> is the zero-length string, returns the value of the
                        base-uri property from the static context in the first form (if the base-uri
                        property is not initialized in the static context an error is raised
                            <errorref class="NS" code="0005"/>) and <code>$base</code> in the second form.</p> -->
                
               
                    <p>Resolving a URI does not dereference it. This is merely a syntactic operation
                        on two character strings.</p>
                </note>
            </div2>

<!-- THIS FUNCTION REMOVED.  URI's can now be compared using fn:compare 							
<div2 id="func-anyURI-equal">
					<head>op:anyURI-equal</head>
					<example role="signature">
						<proto name="anyURI-equal" return-type="xs:boolean" isOp="yes">
							<arg name="arg1" type="xs:anyURI"/>
							<arg name="arg2" type="xs:anyURI"/>
						</proto>
					</example>
					<p>Summary: Returns <code>true</code> if <code>$arg1</code> and <code>$arg2</code> compare equal based on the default collation in the static context.  Otherwise, returns <code>false</code>. This function backs up the "eq" and "ne" operators on anyURI. </p>
<p>For more details on comparing URIs see <bibref ref='RFC3986'/>.</p>
					<div3 id="func-anyURI-equals-examples">>
						<head>Examples</head>
						<ulist>
							<item>
								<p>
									<code>op:anyURI-equal(xs:anyURI("http://www.example.com/spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles"), xs:anyURI("http://www.example.com/spinaltap.micro.umn.edu"))</code> returns <code>false</code>
								</p>
							</item>
						</ulist>
					</div3>
			</div2> -->
        </div1>
        <div1 id="boolean-functions">
            <head>Functions and Operators on Boolean Values</head>
            <p>This section defines functions and operators on the <bibref ref="xmlschema-2"/> boolean datatype.</p>
            <div2 id="boolean-constructors">
                <head>Additional Boolean Constructor Functions</head>
                <p>The following additional constructor functions are defined on the boolean type. </p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:true</code>
                            </td>
                            <td rowspan="1" colspan="1">Constructs the xs:boolean value 'true'.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:false</code>
                            </td>
                            <td rowspan="1" colspan="1">Constructs the xs:boolean value 'false'.</td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-true">
                    <head>fn:true</head>
                    <example role="signature">
                        <proto name="true" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                    </example>
                    <p>Summary: Returns the <code>xs:boolean</code> value <code>true</code>.
                        Equivalent to <code>xs:boolean("1")</code>.</p>
                    <div4 id="func-true-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:true()</code> returns <code>true</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-false">
                    <head>fn:false</head>
                    <example role="signature">
                        <proto name="false" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no"/>
                    </example>
                    <p>Summary: Returns the <code>xs:boolean</code> value <code>false</code>.
                        Equivalent to <code>xs:boolean("0")</code>.</p>
                    <div4 id="func-false-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:false()</code> returns <code>false</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="op.boolean">
                <head>Operators on Boolean Values</head>
                <p>The following functions define the semantics of operators on boolean values in
                        <bibref ref="xquery"/> and <bibref ref="xpath20"/>:</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Operator</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:boolean-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality of <code>xs:boolean</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:boolean-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">A less-than operator on <code>xs:boolean</code> values:
                                <code>false</code> is less than <code>true</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:boolean-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">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 <code>op:boolean-less-than</code>
                    and <code>op:boolean-greater-than</code> are provided for application purposes
                    and for compatibility with <bibref ref="xpath"/>. The <bibref ref="xmlschema-2"/>
                    datatype <code>xs:boolean</code> is not ordered.</p>
                <div3 id="func-boolean-equal">
                    <head>op:boolean-equal</head>
                    <example role="signature">
                        <proto name="boolean-equal" return-type="xs:boolean" isOp="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="value1" type="xs:boolean" emptyOk="no"/>
                            <arg name="value2" type="xs:boolean" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-boolean-less-than">
                    <head>op:boolean-less-than</head>
                    <example role="signature">
                        <proto name="boolean-less-than" return-type="xs:boolean" isOp="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:boolean" emptyOk="no"/>
                            <arg name="arg2" type="xs:boolean" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-boolean-greater-than">
                    <head>op:boolean-greater-than</head>
                    <example role="signature">
                        <proto name="boolean-greater-than" return-type="xs:boolean" isOp="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:boolean" emptyOk="no"/>
                            <arg name="arg2" type="xs:boolean" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
            </div2>
            <div2 id="boolean-value-functions">
                <head>Functions on Boolean Values</head>
                <p>The following functions are defined on boolean values:</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:not</code>
                            </td>
                            <td rowspan="1" colspan="1">Inverts the <code>xs:boolean</code> value of the argument.</td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-not">
                    <head>fn:not</head>
                    <example role="signature">
                        <proto name="not" return-type="xs:boolean" returnEmptyOk="no" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="item()*" emptyOk="no"/>
                        </proto>
                    </example>
                    <p>Summary: <code>$arg</code> is first reduced to an effective boolean value by
                        applying the <code>fn:boolean()</code> 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>
                    <div4 id="func-not-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:not(fn:true())</code> returns <code>false</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:not("false")</code> returns <code>false</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
        </div1>
        <div1 id="durations-dates-times">
            <head>Functions and Operators on Durations, Dates and Times</head>
            <p>This section discusses operations on the <bibref ref="xmlschema-2"/> date and time types.
                It also discusses operations on two subtypes of <code>xs:duration</code> that are
                defined in <xspecref spec="DM" ref="types"/>. See <specref ref="duration-subtypes"/>.</p>
<p>
See <bibref ref="Working-With-Timezones"/> for a disquisition on working with date and time values with and without timezones.
</p>
  <!--          <p>The functions described in this section follow the principle of locale-independent
                storage for these datatypes that originated with <bibref ref="xmlschema-2"/>. Thus, a
                single calendar (Gregorian) and a single timezone (UTC) is chosen to represent
                normalized date and time values. Since the value tuple (See <xspecref spec="DM"
                ref="dates-and-times"/>) also contains the timezone specified in the lexical
                representation, applications and other processing systems are free to present this
                information in locale-specific representations.</p> -->
           
            <div2 id="duration-date-time-types">
                <head>Duration, Date and Time Types</head>
                <p>The operators described in this section are defined on the following date and
                    time types: </p>
                <ulist>
                    <item>
                        <p>xs:dateTime</p>
                    </item>
                    <item>
                        <p>xs:date</p>
                    </item>
                    <item>
                        <p>xs:time</p>
                    </item>
                    <item>
                        <p>xs:gYearMonth</p>
                    </item>
                    <item>
                        <p>xs:gYear</p>
                    </item>
                    <item>
                        <p>xs:gMonthDay</p>
                    </item>
                    <item>
                        <p>xs:gMonth</p>
                    </item>
                    <item>
                        <p>xs:gDay</p>
                    </item>
                </ulist>
                <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>
                    <ulist>
                    <item>
                        <p>xs:duration</p>
                    </item>
                    </ulist>
<p>and on the <specref ref="duration-subtypes"/>:</p>
                <ulist>
                    <item>
                        <p>xs:yearMonthDuration</p>
                    </item>
                    <item>
                        <p>xs:dayTimeDuration</p>
                    </item>
                </ulist>
<p>Note that only equality is defined on					
                    <code>xs:duration</code> values.</p>
                <div3 id="date-time-duration-conformance">
                    <head>Limits and Precision</head>
                    <p>For a number of the above datatypes <bibref ref="xmlschema-2"/> extends the basic
                            <bibref ref="ISO8601"/> 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 <emph>minimally conforming</emph> processors
                        <termref def="must"/>  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, <emph>conforming</emph> processors
                        <termref def="may"/>  set larger <termref def="implementation-defined"/> limits
                        on the maximum number of digits they support in these two situations.  Processors <termref def="may"/> also choose to support the year 0000 and 
                        years with negative values.  The results of operations on dates that cross the year 
                        0000 are <termref def="implementation-defined"/>.</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 <specref ref="dateTime-arithmetic"/>. In
                        these situations, the processor <termref def="must"/> return P0M or PT0S in
                        case of duration underflow and 00:00:00 in case of time underflow.
                            It <termref def="must"/> raise an error <errorref class="DT" code="0001"/> in case of overflow.</p>
                    <p>The value spaces of the two totally ordered subtypes of
                        <code>xs:duration</code> described in <specref ref="duration-subtypes"/> 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
                            <specref ref="duration-arithmetic"/>. In these situations the processor
                            <termref def="must"/> return zero in case of numeric underflow and P0M
                        or PT0S in case of duration underflow. It <termref def="must"/> raise an
                        error <errorref class="DT" code="0002"/> in case of overflow.</p>
                </div3>
            </div2>
 <div2 id="date-time-values">
                <head>Date/time datatype values</head>
<p>As defined in <xspecref spec="DM" ref="dates-and-times"/>, <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 <emph>local</emph> value in that the value is in the given timezone.  Before comparing or subtracting <code>xs:dateTime</code> values, this local value <termref def="must"/>  be translated or <emph>normalized</emph> 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.  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>
                <div3 id="date-time-lexical-mapping">
                    <head>Examples</head>
                    <ulist>
                        <item>
                            <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>
                        </item>
                        <item>
                            <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>
                        </item>
                        <item>
                            <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>
                        </item>
 						<item>
                            <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>
                        </item>
						<item>
                            <p>An <code>xs:time</code> with lexical
                                representation <code>24:00:00</code> is represented by <code>{(), (), (), 0, 0, 0, ()}</code>.</p>
                        </item>
                    </ulist>
                </div3>
            </div2>
            <div2 id="duration-subtypes">
                <head>Two Totally Ordered Subtypes of Duration</head>
                <p>Two totally ordered subtypes of <code>xs:duration</code> are defined in <xspecref spec="DM" ref="types"/>
                    specification using the mechanisms described in <bibref ref="xmlschema-2"/> for
                    defining user-defined types. Additional details about these types is given below.</p>
              
                <div3 id="dt-yearMonthDuration">
                    <head>xs:yearMonthDuration</head>
                    <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 <bibref ref="ISO8601"/>, respectively.</p>
                   <div4 id="lexical-yearMonthDuration">
                        <head>Lexical representation</head>
                        <p>The lexical representation for <code>xs:yearMonthDuration</code> is the
                                <bibref ref="ISO8601"/> 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 <termref def="may"/> be omitted.
                            However, at least one number and its designator <termref def="must"/> 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>
                    </div4>
                    <div4 id="calculating-value-yearMonthDuration">
                        <head>Calculating the value from the lexical representation</head>
                        <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>
                    </div4>
                    <div4 id="canonical-yearMonthDuration">
                        <head>Canonical representation</head>
                        <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 <termref def="must"/> be
                            omitted. However, if the value is zero (0) months, the canonical form is "P0M".</p>
                    </div4>
                    <div4 id="order-yearMonthDuration">
                        <head>Order relation on xs:yearMonthDuration</head>
                        <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>
                    </div4>
                </div3>
                <div3 id="dt-dayTimeDuration">
                    <head>xs:dayTimeDuration</head>
                    <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
                            <bibref ref="ISO8601"/>, respectively.</p> 
                    <div4 id="lexical-dayTimeDuration">
                        <head>Lexical representation</head>
                        <p>The lexical representation for <code>xs:dayTimeDuration</code> is the
                                <bibref ref="ISO8601"/> 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 <bibref ref="ISO8601"/> 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>
                        <ulist>
                            <item>
                                <p>If the number of days, hours, minutes, or seconds in any
                                    expression equals zero (0), the number and its corresponding
                                    designator <termref def="may"/> be omitted. However, at least
                                    one number and its designator <termref def="must"/> be present.</p>
                            </item>
                            <item>
                                <p>The seconds part <termref def="may"/> have a decimal fraction.</p>
                            </item>
                            <item>
                                <p>The designator 'T' <termref def="must"/> be absent if and only if
                                    all of the time items are absent. The designator 'P' <termref def="must"/> always be present.</p>
                            </item>
                        </ulist>
                        <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>
                    </div4>
                    <div4 id="calculating-value-dayTimeDuration">
                        <head>Calculating the value of a xs:dayTimeDuration from the lexical representation</head>
                        <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>
                    </div4>
                    <div4 id="canonical-dayTimeDuration">
                        <head>Canonical representation</head>
                        <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 <bibref ref="xmlschema-2"/>, 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 <quote>PT0S</quote>.</p>
                    </div4>
                    <div4 id="order-dayTimeDuration">
                        <head>Order relation on xs:dayTimeDuration</head>
                        <p>Let the function that calculates the value of a
                            <code>xs:dayTimeDuration</code> in the manner described above be called
                            <emph>V(d)</emph>. Then for two <code>xs:dayTimeDuration</code> values
                            <emph>x</emph> and <emph>y, x &gt; y</emph> if and only if <emph>V(x)
                                &gt; V(y)</emph>. The order relation on
                            <code>xs:dayTimeDuration</code> is a total order. </p>
                    </div4>
                </div3>
            </div2>
            <div2 id="comp.duration.datetime">
                <head>Comparison Operators on Duration, Date and Time Values</head>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Operator</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
              
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:yearMonthDuration-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison on <code>xs:yearMonthDuration</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:yearMonthDuration-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison on <code>xs:yearMonthDuration</code> values</td>
                        </tr>
                        
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:dayTimeDuration-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison on <code>xs:dayTimeDuration</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:dayTimeDuration-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison on <code>xs:dayTimeDuration</code> values</td>
                        </tr>
						<tr>
                            <td rowspan="1" colspan="1">
                                <code>op:duration-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:duration</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:dateTime-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:dateTime</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:dateTime-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison on <code>xs:dateTime</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:dateTime-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison on <code>xs:dateTime</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:date-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:date</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:date-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison on <code>xs:date</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:date-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison on <code>xs:date</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:time-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:time</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:time-less-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Less-than comparison on <code>xs:time</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:time-greater-than</code>
                            </td>
                            <td rowspan="1" colspan="1">Greater-than comparison on <code>xs:time</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:gYearMonth-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:gYearMonth</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:gYear-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:gYear</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:gMonthDay-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:gMonthDay</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:gMonth-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:gMonth</code> values</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:gDay-equal</code>
                            </td>
                            <td rowspan="1" colspan="1">Equality comparison on <code>xs:gDay</code> values</td>
                        </tr>
                    </tbody>
                </table>
                <p>The following comparison operators are defined on the <bibref ref="xmlschema-2"/>
                    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 <bibref ref="xmlschema-2"/>, 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
                        <specref ref="duration-subtypes"/> which do have a total order.</p>
                <p><bibref ref="xmlschema-2"/> 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 <xspecref spec="XP" ref="id-xp-evaluation-context-components"/>, is assumed to be present as part of
                    the value. This creates a total order for all date and time values.</p>
<!--                <p>Note that for <code>xs:dateTime</code>, <code>xs:date</code> and
                    <code>xs:time</code>, as discussed in <specref ref="date-time-values"/> the
                    value is defined as a tuple. Comparison operators on these three datatypes
                    operate on the first, or normalized value, part of the tuple and disregard the
                    second, or timezone, part of the tuple. If the timezone part is (), the implicit
                    timezone is used to adjust the normalized value as necessary.</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>

<note><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></note>

<!--              <div3 id="func-yearMonthDuration-equal">
                    <head>op:yearMonthDuration-equal</head>
                    <example role="signature">
                        <proto name="yearMonthDuration-equal" return-type="xs:boolean"
                            returnEmptyOk="no" isOp="yes">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <p>Summary: Returns <code>true</code> if and only if <code>$arg1</code> is equal
                        to <code>$arg2</code>. Returns <code>false</code> otherwise.</p>
                    <p>This function backs up the "eq", "ne", "le" and "ge" operators on
                        <code>xs:yearMonthDuration</code> values.</p>
                </div3> -->
                <div3 id="func-yearMonthDuration-less-than">
                    <head>op:yearMonthDuration-less-than</head>
                    <example role="signature">
                        <proto name="yearMonthDuration-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-yearMonthDuration-greater-than">
                    <head>op:yearMonthDuration-greater-than</head>
                    <example role="signature">
                        <proto name="yearMonthDuration-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
 <!--               <div3 id="func-dayTimeDuration-equal">
                    <head>op:dayTimeDuration-equal</head>
                    <example role="signature">
                        <proto name="dayTimeDuration-equal" return-type="xs:boolean"
                            returnEmptyOk="no" isOp="yes">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>. Returns
                        <code>false</code> otherwise.</p>
                    <p>This function backs up the "eq", "ne", "le" and "ge" operators on
                        <code>xs:dayTimeDuration</code> values.</p>
                </div3> -->
                <div3 id="func-dayTimeDuration-less-than">
                    <head>op:dayTimeDuration-less-than</head>
                    <example role="signature">
                        <proto name="dayTimeDuration-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-dayTimeDuration-greater-than">
                    <head>op:dayTimeDuration-greater-than</head>
                    <example role="signature">
                        <proto name="dayTimeDuration-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                </div3>
                <div3 id="func-duration-equal">
                    <head>op:duration-equal</head>
                    <example role="signature">
                        <proto name="duration-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:duration" emptyOk="no"/>
                            <arg name="arg2" type="xs:duration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
<eg xml:space="preserve">
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')
</eg>
<p>that is, the function returns <code>true</code> if the months and seconds values of the two durations are equal.</p>
                    <div4 id="func-duration-equal-examples">
                        <head>Examples</head>
						<ulist>
	
							<item><p>
<code>op:duration-equal(xs:duration("P1Y"), xs:duration("P12M"))</code> returns <code>true</code>.
							</p></item>
							<item><p>
<code>op:duration-equal(xs:duration("PT24H"), xs:duration("P1D"))</code> returns <code>true</code>.
							</p></item>
							<item><p>
<code>op:duration-equal(xs:duration("P1Y"), xs:duration("P365D"))</code> returns <code>false</code>. 
						
							</p></item>
<item><p>
<code>op:duration-equal(xs:yearMonthDuration("P0Y"), xs:dayTimeDuration("PT0D"))</code> returns <code>true</code>.
							</p></item>
	<item><p>
<code>op:duration-equal(xs:yearMonthDuration("P1Y"), xs:dayTimeDuration("PT365D"))</code> returns <code>false</code>.
							</p></item>
<item><p>
<code>op:duration-equal(xs:yearMonthDuration("P2Y"), xs:yearMonthDuration("P24M"))</code> returns <code>true</code>.
							</p></item>
	<item><p>
<code>op:duration-equal(xs:dayTimeDuration("PT10D"), xs:dayTimeDuration("PT240H"))</code> returns <code>true</code>.
							</p></item>
<item><p>
<code>op:duration-equal(xs:duration("P2Y0M0DT0H0M0S"), xs:yearMonthDuration("P24M"))</code> returns <code>true</code>.
							</p></item>
	<item><p>
<code>op:duration-equal(xs:duration("P0Y0M10D"), xs:dayTimeDuration("PT240H"))</code> returns <code>true</code>.
							</p></item>
						</ulist>
                    </div4>
                </div3>
                <div3 id="func-dateTime-equal">
                    <head>op:dateTime-equal</head>
                    <example role="signature">
                        <proto name="dateTime-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dateTime" emptyOk="no"/>
                            <arg name="arg2" type="xs:dateTime" emptyOk="no"/>
                        </proto>
                    </example>
                    <p>Summary: 
<!-- Returns <code>true</code> if and only if the normalized value of
                        <code>$arg1</code> is equal to the normalized value of <code>$arg2</code>.
                        Returns <code>false</code> otherwise. -->
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 <bibref ref="xmlschema-2"/> <quote>Order relation on dateTime</quote> 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>
                    <div4 id="func-dateTime-equal-examples">
                        <head>Examples</head>
                        <p>Assume that the dynamic context provides an implicit timezone value of <code>-05:00</code>.</p>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
							<item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-dateTime-less-than">
                    <head>op:dateTime-less-than</head>
                    <example role="signature">
                        <proto name="dateTime-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dateTime" emptyOk="no"/>
                            <arg name="arg2" type="xs:dateTime" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <bibref ref="xmlschema-2"/> <quote>Order relation on dateTime</quote> for <code>xs:dateTime</code> values with timezones.
<!--
Returns <code>true</code> if and only if the normalized value of
                        <code>$arg1</code> is less than the normalized value of <code>$arg2</code>. -->
                        Returns <code>false</code> otherwise.</p>
                    <p>This function backs up the "lt" and "le" operators on
                        <code>xs:dateTime</code> values.</p>
                </div3>
                <div3 id="func-dateTime-greater-than">
                    <head>op:dateTime-greater-than</head>
                    <example role="signature">
                        <proto name="dateTime-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dateTime" emptyOk="no"/>
                            <arg name="arg2" type="xs:dateTime" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <bibref ref="xmlschema-2"/> <quote>Order relation on dateTime</quote> 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>
                </div3>
                <div3 id="func-date-equal">
                    <head>op:date-equal</head>
                    <example role="signature">
                        <proto name="date-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:date" emptyOk="no"/>
                            <arg name="arg2" type="xs:date" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-equal</code>.
</p>
<p>This function backs up the "eq", "ne", "le" and "ge" operators on <code>xs:date</code> values.</p>
      
 <div4 id="func-date-equal-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
</div3>
                <div3 id="func-date-less-than">
                    <head>op:date-less-than</head>
                    <example role="signature">
                        <proto name="date-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:date" emptyOk="no"/>
                            <arg name="arg2" type="xs:date" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-less-than</code>.</p>
                    <p>This function backs up the "lt" and "le" operators on <code>xs:date</code> values.</p>
				<div4 id="func-date-less-than-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>op:date-less-than(xs:date("2004-12-25Z"),
                                    xs:date("2004-12-25-05:00"))</code> returns <code>true</code>.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-date-greater-than">
                    <head>op:date-greater-than</head>
                    <example role="signature">
                        <proto name="date-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:date" emptyOk="no"/>
                            <arg name="arg2" type="xs:date" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-greater-than</code>.</p>
                    <p>This function backs up the "gt" and "ge" operators on <code>xs:date</code> values.</p>
					 <div4 id="date-greater-than-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>op:date-greater-than(xs:date("2004-12-25Z"),
                                    xs:date("2004-12-25+07:00"))</code> returns <code>true</code>.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-time-equal">
                    <head>op:time-equal</head>
                    <example role="signature">
                        <proto name="time-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:time" emptyOk="no"/>
                            <arg name="arg2" type="xs:time" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-equal</code>.</p>
                    <p>This function backs up the "eq", "ne", "le" and "ge" operators on <code>xs:time</code> values.</p>
   					<div4 id="func-time-equals-examples">
                        <head>Examples</head>
                        <p>Assume that the date components from the reference <code>xs:dateTime</code> correspond to <code>1972-12-31</code>.</p>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
 							<item>
                                <p>
                                    <code>op:time-equal(xs:time("24:00:00+01:00"), xs:time("00:00:00+01:00"))</code> returns <code>true</code>.</p>
                            </item>
                          </ulist>
                    </div4>
                </div3>
                <div3 id="func-time-less-than">
                    <head>op:time-less-than</head>
                    <example role="signature">
                        <proto name="time-less-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:time" emptyOk="no"/>
                            <arg name="arg2" type="xs:time" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-less-than</code>.</p>
                    <p>This function backs up the "lt" and "le" operators on <code>xs:time</code> values.</p>
                    <div4 id="func-time-less-than-examples">
                        <head>Examples</head>
                        <p>Assume that the dynamic context provides an implicit timezone value of <code>-05:00</code>.</p>
                        <ulist>
                            <item>
                                <p>
                                    <code>op:time-less-than(xs:time("12:00:00"),
                                    xs:time("23:00:00+06:00"))</code> returns <code>false</code>.</p>
                            </item>
                            <item>
                                <p>
                                    <code>op:time-less-than(xs:time("11:00:00"),
                                    xs:time("17:00:00Z"))</code> returns <code>true</code>.</p>
                            </item>
 <item>
                                <p>
                                    <code>op:time-less-than(xs:time("23:59:59"), xs:time("24:00:00"))</code> returns <code>false</code>.</p>
                            </item>
                          </ulist>
                    </div4>
                </div3>
                <div3 id="func-time-greater-than">
                    <head>op:time-greater-than</head>
                    <example role="signature">
                        <proto name="time-greater-than" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:time" emptyOk="no"/>
                            <arg name="arg2" type="xs:time" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-greater-than</code>.</p>
                    <p>This function backs up the "gt" and "ge" operators on <code>xs:time</code> values.</p>
   					<div4 id="func-time-greater-than-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-gYearMonth-equal">
                    <head>op:gYearMonth-equal</head>
                    <example role="signature">
                        <proto name="gYearMonth-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:gYearMonth" emptyOk="no"/>
                            <arg name="arg2" type="xs:gYearMonth" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-equal</code>.</p>
                    <p>This function backs up the "eq" and "ne" operators on
                        <code>xs:gYearMonth</code> values.</p>
                     <div4 id="func-gYearMonth-equal-examples">
                        <head>Examples</head>
                        <p>Assume that the dynamic context provides an implicit timezone value of <code>-05:00</code>.</p>
                        <ulist>
                            <item>
                                <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>
                            </item>
  							<item>
                                <p>
                                    <code>op:gYearMonth-equal(xs:gYearMonth("1976-03"),
                                    xs:gYearMonth("1976-03Z"))</code> returns <code>false</code>.</p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-gYear-equal">
                    <head>op:gYear-equal</head>
                    <example role="signature">
                        <proto name="gYear-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:gYear" emptyOk="no"/>
                            <arg name="arg2" type="xs:gYear" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-equal</code>.</p>
                    <p>This function backs up the "eq" and "ne" operators on <code>xs:gYear</code> values.</p>
 					<div4 id="func-gYear-equal-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <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>
                            </item>
  							<item>
                                <p>
                                    <code>op:gYear-equal(xs:gYear("1976-05:00"),
                                    xs:gYear("1976"))</code> returns <code>true</code>.</p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-gMonthDay-equal">
                    <head>op:gMonthDay-equal</head>
                    <example role="signature">
                        <proto name="gMonthDay-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:gMonthDay" emptyOk="no"/>
                            <arg name="arg2" type="xs:gMonthDay" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:dateTime-equal</code>.</p>
                                        <p>This function backs up the "eq" and "ne" operators on
                        <code>xs:gMonthDay</code> values.</p>
 					<div4 id="func-gMonthDay-equal-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <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>
                            </item>
  							<item>
                                <p>
                                    <code>op:gMonthDay-equal(xs:gMonthDay("--12-25"),
                                    xs:gMonthDay("--12-26Z"))</code> returns <code>false</code>.</p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-gMonth-equal">
                    <head>op:gMonth-equal</head>
                    <example role="signature">
                        <proto name="gMonth-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:gMonth" emptyOk="no"/>
                            <arg name="arg2" type="xs:gMonth" emptyOk="no"/>
                        </proto>
                    </example>
                   
                    <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 <code>op:dateTime-equal</code>.</p>
                    
                    <p>This function backs up the "eq" and "ne" operators on <code>xs:gMonth</code> values.</p>
					<div4 id="func-gMonth-equal-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <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>
                            </item>
  							<item>
                                <p>
                                    <code>op:gMonth-equal(xs:gMonth("--12"),
                                    xs:gMonth("--12Z"))</code> returns <code>false</code>.</p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
                <div3 id="func-gDay-equal">
                    <head>op:gDay-equal</head>
                    <example role="signature">
                        <proto name="gDay-equal" return-type="xs:boolean" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:gDay" emptyOk="no"/>
                            <arg name="arg2" type="xs:gDay" emptyOk="no"/>
                        </proto>
                    </example>
<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 <code>op:dateTime-equal</code>.</p>
                    <p>This function backs up the "eq" and "ne" operators on <code>xs:gDay</code> values.</p>
					<div4 id="func-gDay-equal-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <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>
                            </item>
  							<item>
                                <p>
                                    <code>op:gDay-equal(xs:gDay("---12"),
                                    xs:gDay("---12Z"))</code> returns <code>false</code>.</p>
                            </item>
                         </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="component-exraction-functions">
                <head>Component Extraction Functions on Durations, Dates and Times</head>
                <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.</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:years-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the year component of an <code>xs:duration</code>
                                value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:months-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the months component of an
                                <code>xs:duration</code> value.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:days-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the days component of an <code>xs:duration</code>
                                value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:hours-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the hours component of an <code>xs:duration</code>
                                value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:minutes-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the minutes component of an <code>xs:duration</code>
                                value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:seconds-from-duration</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the seconds component of an <code>xs:duration</code>
                                value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:year-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the year from an <code>xs:dateTime</code> value.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:month-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the month from an <code>xs:dateTime</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:day-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the day from an <code>xs:dateTime</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:hours-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the hours from an <code>xs:dateTime</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:minutes-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the minutes from an <code>xs:dateTime</code> value.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:seconds-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the seconds from an <code>xs:dateTime</code> value.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:timezone-from-dateTime</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the timezone from an <code>xs:dateTime</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:year-from-date</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the year from an <code>xs:date</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:month-from-date</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the month from an <code>xs:date</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:day-from-date</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the day from an <code>xs:date</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:timezone-from-date</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the timezone from an <code>xs:date</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:hours-from-time</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the hours from an <code>xs:time</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:minutes-from-time</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the minutes from an <code>xs:time</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:seconds-from-time</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the seconds from an <code>xs:time</code> value. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:timezone-from-time</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the timezone from an <code>xs:time</code> value. </td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-years-from-duration">
                    <head>fn:years-from-duration</head>
                    <example role="signature">
                        <proto name="years-from-duration" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dDuration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:integer</code> representing the years component
                        in the canonical lexical representation of the value of <code>$arg</code>.
                        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>
                    <div4 id="func-years-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:years-from-duration(xs:yearMonthDuration("P20Y15M"))</code>
                                    returns <code>21</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:years-from-duration(xs:yearMonthDuration("-P15M"))</code>
                                    returns <code>-1</code>.</p>
                            </item>
 							<item>
                                <p>

                                    <code>fn:years-from-duration(xs:dayTimeDuration("-P2DT15H"))</code>
                                    returns <code>0</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-months-from-duration">
                    <head>fn:months-from-duration</head>
                    <example role="signature">
                        <proto name="months-from-duration" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:duration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:integer</code> representing the months component
                        in the canonical lexical representation of the value of <code>$arg</code>.
                        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>
                    <div4 id="func-months-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:months-from-duration(xs:yearMonthDuration("P20Y15M"))</code>
                                    returns <code>3</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:months-from-duration(xs:yearMonthDuration("-P20Y18M"))</code>
                                    returns <code>-6</code>.</p>
                            </item>
	<item>
                                <p>

                                    <code>fn:months-from-duration(xs:dayTimeDuration("-P2DT15H0M0S"))</code>
                                    returns <code>0</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-days-from-duration">
                    <head>fn:days-from-duration</head>
                    <example role="signature">
                        <proto name="days-from-duration" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:duration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:integer</code> representing the days component
                        in the canonical lexical representation of the value of <code>$arg</code>.
                        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>
                    <div4 id="func-days-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:days-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
                                    returns <code>3</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:days-from-duration(xs:dayTimeDuration("P3DT55H"))</code>
                                    returns <code>5</code>.</p>
                            </item>
 							<item>
                                <p>

                                    <code>fn:days-from-duration(xs:yearMonthDuration("P3Y5M"))</code>
                                    returns <code>0</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-hours-from-duration">
                    <head>fn:hours-from-duration</head>
                    <example role="signature">
                        <proto name="hours-from-duration" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:duration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:integer</code> representing the hours component
                        in the canonical lexical representation of the value of <code>$arg</code>.
                        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>
                    <div4 id="func-hours-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:hours-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
                                    returns <code>10</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:hours-from-duration(xs:dayTimeDuration("P3DT12H32M12S"))</code>
                                    returns <code>12</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:hours-from-duration(xs:dayTimeDuration("PT123H"))</code>
                                    returns <code>3</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:hours-from-duration(xs:dayTimeDuration("-P3DT10H"))</code>
                                    returns <code>-10</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-minutes-from-duration">
                    <head>fn:minutes-from-duration</head>
                    <example role="signature">
                        <proto name="minutes-from-duration" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:duration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:integer</code> representing the minutes
                        component in the canonical lexical representation of the value of
                        <code>$arg</code>. 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>
                    <div4 id="func-minutes-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:minutes-from-duration(xs:dayTimeDuration("P3DT10H"))</code>
                                    returns <code>0</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:minutes-from-duration(xs:dayTimeDuration("-P5DT12H30M"))</code>
                                    returns <code>-30</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-seconds-from-duration">
                    <head>fn:seconds-from-duration</head>
                    <example role="signature">
                        <proto name="seconds-from-duration" return-type="xs:decimal" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:duration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <p>Summary: Returns an <code>xs:decimal</code> representing the seconds
                        component in the canonical lexical representation of the value of
                        <code>$arg</code>. 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>
                    <div4 id="func-seconds-from-duration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:seconds-from-duration(xs:dayTimeDuration("P3DT10H12.5S"))</code>
                                    returns <code>12.5</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:seconds-from-duration(xs:dayTimeDuration("-P256S"))</code>
                                    returns <code>-16.0</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-year-from-dateTime">
                    <head>fn:year-from-dateTime</head>
                    <example role="signature">
                        <proto name="year-from-dateTime" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-year-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
                                    returns <code>1999</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:year-from-dateTime(xs:dateTime("1999-05-31T21:30:00-05:00"))</code>
                                    returns <code>1999</code>.</p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:year-from-dateTime(xs:dateTime("1999-12-31T19:20:00"))</code>
                                    returns <code>1999</code>.</p>
                            </item>
 							<item>
                                <p>

                                    <code>fn:year-from-dateTime(xs:dateTime("1999-12-31T24:00:00"))</code>
                                    returns <code>2000</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-month-from-dateTime">
                    <head>fn:month-from-dateTime</head>
                    <example role="signature">
                        <proto name="month-from-dateTime" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-month-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
                                    returns <code>5</code>. </p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:month-from-dateTime(xs:dateTime("1999-12-31T19:20:00-05:00"))</code>
                                    returns <code>12</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-day-from-dateTime">
                    <head>fn:day-from-dateTime</head>
                    <example role="signature">
                        <proto name="day-from-dateTime" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-day-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:day-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
                                    returns <code>31</code>. </p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:day-from-dateTime(xs:dateTime("1999-12-31T20:00:00-05:00"))</code>
                                    returns <code>31</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-hours-from-dateTime">
                    <head>fn:hours-from-dateTime</head>
                    <example role="signature">
                        <proto name="hours-from-dateTime" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-hours-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:hours-from-dateTime(xs:dateTime("1999-05-31T08:20:00-05:00"))</code>
                                    returns <code>8</code>. </p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T21:20:00-05:00"))</code>
                                    returns <code>21</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T12:00:00"))</code>
                                    returns <code>12</code>.
                                </p>
                            </item>
							<item>
                                <p>
                                    <code>fn:hours-from-dateTime(xs:dateTime("1999-12-31T24:00:00"))</code>
                                    returns <code>0</code>.
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-minutes-from-dateTime">
                    <head>fn:minutes-from-dateTime</head>
                    <example role="signature">
                        <proto name="minutes-from-dateTime" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-minutes-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
                                    returns <code>20</code> . </p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:30:00+05:30"))</code>
                                    returns <code>30</code> . </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-seconds-from-dateTime">
                    <head>fn:seconds-from-dateTime</head>
                    <example role="signature">
                        <proto name="seconds-from-dateTime" return-type="xs:decimal" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-seconds-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>fn:seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))</code>
                                    returns <code>0</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-timezone-from-dateTime">
                    <head>fn:timezone-from-dateTime</head>
                    <example role="signature">
                        <proto name="timezone-from-dateTime" return-type="xs:dayTimeDuration" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-timezone-from-dateTime-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>

                                    <code>fn:timezone-from-dateTime(xs:dateTime("2004-08-27T00:00:00"))</code>
                                    returns <code>()</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-year-from-date">
                    <head>fn:year-from-date</head>
                    <example role="signature">
                        <proto name="year-from-date" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-year-from-date-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:year-from-date(xs:date("1999-05-31"))</code> returns
                                    <code>1999</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:year-from-date(xs:date("2000-01-01+05:00"))</code>
                                    returns <code>2000</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-month-from-date">
                    <head>fn:month-from-date</head>
                    <example role="signature">
                        <proto name="month-from-date" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-month-from-date-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:month-from-date(xs:date("1999-05-31-05:00"))</code>
                                    returns <code>5</code> . </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:month-from-date(xs:date("2000-01-01+05:00"))</code>
                                    returns <code>1</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-day-from-date">
                    <head>fn:day-from-date</head>
                    <example role="signature">
                        <proto name="day-from-date" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-day-from-date-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:day-from-date(xs:date("1999-05-31-05:00"))</code>
                                    returns <code>31</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:day-from-date(xs:date("2000-01-01+05:00"))</code>
                                    returns <code>1</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-timezone-from-date">
                    <head>fn:timezone-from-date</head>
                    <example role="signature">
                        <proto name="timezone-from-date" return-type="xs:dayTimeDuration" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-timezone-from-date-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:timezone-from-date(xs:date("2000-06-12Z"))</code>
                                    returns the <code>xs:dayTimeDuration</code> with value <code>PT0S</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-hours-from-time">
                    <head>fn:hours-from-time</head>
                    <example role="signature">
                        <proto name="hours-from-time" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-hours-from-time-examples">
                        <head>Examples</head>
                        <p>Assume that the dynamic context provides an implicit timezone value of <code>-05:00</code>.</p>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:hours-from-time(xs:time("11:23:00"))</code> returns
                                    <code>11</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:hours-from-time(xs:time("21:23:00"))</code> returns
                                    <code>21</code>. </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:hours-from-time(xs:time("01:23:00+05:00"))</code>
                                    returns <code>1</code>. </p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:hours-from-time(xs:time("24:00:00"))</code>
                                    returns <code>0</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-minutes-from-time">
                    <head>fn:minutes-from-time</head>
                    <example role="signature">
                        <proto name="minutes-from-time" return-type="xs:integer" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-minutes-from-time-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:minutes-from-time(xs:time("13:00:00Z"))</code> returns
                                    <code>0</code> . </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-seconds-from-time">
                    <head>fn:seconds-from-time</head>
                    <example role="signature">
                        <proto name="seconds-from-time" return-type="xs:decimal" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-seconds-from-time-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:seconds-from-time(xs:time("13:20:10.5"))</code> returns
                                    <code>10.5</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-timezone-from-time">
                    <head>fn:timezone-from-time</head>
                    <example role="signature">
                        <proto name="timezone-from-time" return-type="xs:dayTimeDuration" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-timezone-from-time-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:timezone-from-time(xs:time("13:20:00"))</code> returns <code>()</code>.</p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="duration-arithmetic">
                <head>Arithmetic Operators on Durations</head>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:add-yearMonthDurations</code>
                            </td>
                            <td rowspan="1" colspan="1">Adds two <code>xs:yearMonthDuration</code>s. Returns an <code>xs:yearMonthDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:subtract-yearMonthDurations</code>
                            </td>
                            <td rowspan="1" colspan="1">Subtracts one <code>xs:yearMonthDuration</code> from another.
                                Returns an <code>xs:yearMonthDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:multiply-yearMonthDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Multiplies a <code>xs:yearMonthDuration</code> by an
                                <code>xs:double</code>. Returns an <code>xs:yearMonthDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:divide-yearMonthDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Divides an <code>xs:yearMonthDuration</code> by an
                                <code>xs:double</code>. Returns an <code>xs:yearMonthDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:divide-yearMonthDuration-by-yearMonthDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Divides an <code>xs:yearMonthDuration</code> by an
                                <code>xs:yearMonthDuration</code>. Returns an <code>xs:decimal</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:add-dayTimeDurations</code>
                            </td>
                            <td rowspan="1" colspan="1">Adds two <code>xs:dayTimeDurations</code>. Returns an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:subtract-dayTimeDurations</code>
                            </td>
                            <td rowspan="1" colspan="1">Subtracts one <code>xs:dayTimeDuration</code> from another. Returns
                                an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:multiply-dayTimeDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Multiplies an <code>xs:dayTimeDuration</code> by a
                                <code>xs:double</code>. Returns an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:divide-dayTimeDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Divides an <code>xs:dayTimeDuration</code> by an
                                <code>xs:double</code>. Returns an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:divide-dayTimeDuration-by-dayTimeDuration</code>
                            </td>
                            <td rowspan="1" colspan="1">Divides an <code>xs:dayTimeDuration</code> by an
                                <code>xs:dayTimeDuration</code>. Returns an <code>xs:decimal</code>.</td>
                        </tr>
                    </tbody>
                </table>
                <div3 id="func-add-yearMonthDurations">
                    <head>op:add-yearMonthDurations</head>
                    <example role="signature">
                        <proto name="add-yearMonthDurations" return-type="xs:yearMonthDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-add-yearMonthDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-subtract-yearMonthDurations">
                    <head>op:subtract-yearMonthDurations</head>
                    <example role="signature">
                        <proto name="subtract-yearMonthDurations" return-type="xs:yearMonthDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-subtract-yearMonthDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-multiply-yearMonthDuration">
                    <head>op:multiply-yearMonthDuration</head>
                    <example role="signature">
                        <proto name="multiply-yearMonthDuration" return-type="xs:yearMonthDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:double" emptyOk="no"/>
                        </proto>
                    </example>
                    <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
                        <emph>v</emph>, 0 &lt;= <emph>v</emph> &lt; 0.5 rounds to 0; 0.5
                        &lt;= <emph>v</emph> &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 <specref ref="date-time-duration-conformance"/>. If <code>$arg2</code> is
                        <code>NaN</code> an error is raised <errorref class="CA" code="0005"/>
                    </p>
                    <p>Backs up the "*" operator on <code>xs:yearMonthDuration</code> values.</p>
                    <div4 id="func-multiply-yearMonthDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-divide-yearMonthDuration">
                    <head>op:divide-yearMonthDuration</head>
                    <example role="signature">
                        <proto name="divide-yearMonthDuration" return-type="xs:yearMonthDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:double" emptyOk="no"/>
                        </proto>
                    </example>
                    <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
                        <emph>v</emph>, 0 &lt;= <emph>v</emph> &lt; 0.5 rounds to 0; 0.5
                        &lt;= <emph>v</emph> &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 <specref ref="date-time-duration-conformance"/>. If <code>$arg2</code> is
                        <code>NaN</code> an error is raised <errorref class="CA" code="0005"/>
                    </p>
                    <p>Backs up the "div" operator on <code>xs:yearMonthDuration</code> and numeric values.</p>
                    <div4 id="func-divide-yearMonthDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-divide-yearMonthDuration-by-yearMonthDuration">
                    <head>op:divide-yearMonthDuration-by-yearMonthDuration</head>
                    <example role="signature">
                        <proto name="divide-yearMonthDuration-by-yearMonthDuration" return-type="xs:decimal" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:yearMonthDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:yearMonthDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:numeric-divide</code> with
                        <code>xs:integer</code> operands.</p>
                    <p>Backs up the "div" operator on <code>xs:yearMonthDuration</code> values.</p>
                    <div4 id="func-divide-yearMonthDuration-by-yearMonthDuration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>op:divide-yearMonthDuration-by-yearMonthDuration(xs:yearMonthDuration("P3Y4M"),
                                    xs:yearMonthDuration("-P1Y4M"))</code> returns
                                    <code>-2.5</code>. </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-add-dayTimeDurations">
                    <head>op:add-dayTimeDurations</head>
                    <example role="signature">
                        <proto name="add-dayTimeDurations" return-type="xs:dayTimeDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-add-dayTimeDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-subtract-dayTimeDurations">
                    <head>op:subtract-dayTimeDurations</head>
                    <example role="signature">
                        <proto name="subtract-dayTimeDurations" return-type="xs:dayTimeDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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>
                    <div4 id="func-subtract-dayTimeDurations-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-multiply-dayTimeDuration">
                    <head>op:multiply-dayTimeDuration</head>
                    <example role="signature">
                        <proto name="multiply-dayTimeDuration" return-type="xs:dayTimeDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:double" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <specref ref="date-time-duration-conformance"/>. If <code>$arg2</code> is
                        <code>NaN</code> an error is raised <errorref class="CA" code="0005"/>
                    </p>
                    <p>Backs up the "*" operator on <code>xs:dayTimeDuration</code> values.</p>
                    <div4 id="func-multiply-yearMonthDuration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-divide-dayTimeDuration">
                    <head>op:divide-dayTimeDuration</head>
                    <example role="signature">
                        <proto name="divide-dayTimeDuration" return-type="xs:dayTimeDuration" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:double" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <specref ref="date-time-duration-conformance"/>. If <code>$arg2</code> is
                        <code>NaN</code> an error is raised <errorref class="CA" code="0005"/>
                    </p>
                    <p>Backs up the "div" operator on <code>xs:dayTimeDuration</code> values.</p>
                    <div4 id="func-divide-yearMonthDuration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-divide-dayTimeDuration-by-dayTimeDuration">
                    <head>op:divide-dayTimeDuration-by-dayTimeDuration</head>
                    <example role="signature">
                        <proto name="divide-dayTimeDuration-by-dayTimeDuration" return-type="xs:decimal" returnEmptyOk="no" isOp="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no">
                            <arg name="arg1" type="xs:dayTimeDuration" emptyOk="no"/>
                            <arg name="arg2" type="xs:dayTimeDuration" emptyOk="no"/>
                        </proto>
                    </example>
                    <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 <code>op:numeric-divide</code> with
                        <code>xs:decimal</code> operands.</p>
                    <p>Backs up the "div" operator on <code>xs:dayTimeDuration</code> values.</p>
                    <div4 id="func-divide-dayTimeDuration-by-dayTimeDuration-examples">
                        <head>Examples</head>
                        <ulist>
                            <item>
                                <p>

                                    <code>op:divide-dayTimeDuration-by-dayTimeDuration(xs:dayTimeDuration("P2DT53M11S"),
                                    xs:dayTimeDuration("P1DT10H))</code> returns <code>1.4378349...</code>
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="timezone.functions">
                <head>Timezone Adjustment Functions on Dates and Time Values</head>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:adjust-dateTime-to-timezone</code>
                            </td>
                            <td rowspan="1" colspan="1">Adjusts an <code>xs:dateTime</code> value to a specific timezone, or
                                to no timezone at all. </td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:adjust-date-to-timezone</code>
                            </td>
                            <td rowspan="1" colspan="1">Adjusts an <code>xs:date</code> value to a specific timezone, or to
                                no timezone at all.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>fn:adjust-time-to-timezone</code>
                            </td>
                            <td rowspan="1" colspan="1">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>
                <div3 id="func-adjust-dateTime-to-timezone">
                    <head>fn:adjust-dateTime-to-timezone</head>
                    <example role="signature">
                        <proto name="adjust-dateTime-to-timezone" return-type="xs:dateTime" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto name="adjust-dateTime-to-timezone" return-type="xs:dateTime" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:dateTime" emptyOk="yes"/>
                            <arg name="timezone" type="xs:dayTimeDuration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <errorref class="DT" code="0003"/> 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>
                    <div4 id="func-adjust-dateTime-to-timezone-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>

                                    <code>fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00"),
                                    ())</code> returns <code>2002-03-07T10:00:00</code>
                                </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-adjust-date-to-timezone">
                    <head>fn:adjust-date-to-timezone</head>
                    <example role="signature">
                        <proto name="adjust-date-to-timezone" return-type="xs:date" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto name="adjust-date-to-timezone" return-type="xs:date" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:date" emptyOk="yes"/>
                            <arg name="timezone" type="xs:dayTimeDuration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <errorref class="DT" code="0003"/> 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>
                    <ulist>
                        <item>
                            <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>
                        </item>
                        <item>
                            <p>Let <code>$r</code> be the result of evaluating
                                    <code>fn:adjust-dateTime-to-timezone($srcdt, $timezone)</code>
                            </p>
                        </item>
                        <item>
                            <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>
                        </item>
                    </ulist>
                    <div4 id="func-adjust-date-to-timezone-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:adjust-date-to-timezone(xs:date("2002-03-07"))</code>
                                    returns <code>2002-03-07-05:00.</code>
                                </p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-date-to-timezone(xs:date("2002-03-07"),
                                    $tz)</code> returns <code>2002-03-07-10:00</code>.</p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-date-to-timezone(xs:date("2002-03-07"),
                                    ())</code> returns <code>2002-03-07.</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"),
                                    ())</code> returns <code>2002-03-07.</code>
                                </p>
                            </item>
                        </ulist>
                    </div4>
                </div3>
                <div3 id="func-adjust-time-to-timezone">
                    <head>fn:adjust-time-to-timezone</head>
                    <example role="signature">
                        <proto name="adjust-time-to-timezone" return-type="xs:time" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                        </proto>
                    </example>
                    <example role="signature">
                        <proto name="adjust-time-to-timezone" return-type="xs:time" returnEmptyOk="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                            <arg name="arg" type="xs:time" emptyOk="yes"/>
                            <arg name="timezone" type="xs:dayTimeDuration" emptyOk="yes"/>
                        </proto>
                    </example>
                    <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 <errorref class="DT" code="0003"/> 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>
                    <ulist>
                        <item>
                            <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>
                        </item>
                        <item>
                            <p> Let <code>$r</code> be the result of evaluating</p>
                            <p>
                                <code>fn:adjust-dateTime-to-timezone($srcdt, $timezone)</code>
                            </p>
                        </item>
                        <item>
                            <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>
                        </item>
                    </ulist>
                    <div4 id="func-adjust-time-to-timezone-examples">
                        <head>Examples</head>
                        <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>
                        <ulist>
                            <item>
                                <p>
                                    <code>fn:adjust-time-to-timezone(xs:time("10:00:00"))</code>
                                    returns <code>10:00:00-05:00</code>
                                </p>
                            </item>
                            <item>
                                <p>

                                    <code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"))</code>
                                    returns <code>12:00:00-05:00</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-time-to-timezone(xs:time("10:00:00"),
                                    $tz)</code> returns <code>10:00:00-10:00</code>
                                </p>
                            </item>
                            <item>
                                <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>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-time-to-timezone(xs:time("10:00:00"), ())</code>
                                    returns <code>10:00:00</code>
                                </p>
                            </item>
                            <item>
                                <p>
                                    <code>fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"),
                                    ())</code> returns <code>10:00:00</code>
                                </p>
                            </item>
                            <item>
                                <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>
                            </item>
                        </ulist>
                    </div4>
                </div3>
            </div2>
            <div2 id="dateTime-arithmetic">
                <head>Arithmetic Operators on Durations, Dates and Times</head>
                <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 <bibref ref="xmlschema-2"/> describes an algorithm for
                    performing such operations.</p>
                <table border="1" summary="Function/operator summary">
                    <thead>
                        <tr>
                            <th rowspan="1" colspan="1">Function</th>
                            <th rowspan="1" colspan="1">Meaning</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:subtract-dateTimes</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the difference between two <code>xs:dateTimes</code> as an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:subtract-dates</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the difference between two <code>xs:dateTimes</code> as an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                       
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:subtract-times</code>
                            </td>
                            <td rowspan="1" colspan="1">Returns the difference between two <code>xs:time</code>s as an <code>xs:dayTimeDuration</code>.</td>
                        </tr>
                        <tr>
                            <td rowspan="1" colspan="1">
                                <code>op:add-yearMonthDuration-to-dateTime</code>
                            </td>
                            <td rowspan="1" cols