<!--
<?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="pr" status="ext-review">
    <header>
        <title>XQuery 1.0 and XPath 2.0 Functions and Operators</title>
        <version/>
        <w3c-designation>PR-xpath-functions</w3c-designation>
        <w3c-doctype>W3C Proposed Recommendation</w3c-doctype>
        <pubdate>
            <day>21</day>
            <month>November</month>
            <year>2006</year>
        </pubdate>
        <publoc>
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/PR-xpath-functions-20061121/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2006/PR-xpath-functions-20061121/</loc>
        </publoc>
  <altlocs>
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/PR-xpath-functions-20061121/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/PR-xpath-functions-20061121/diff-from-20060608.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/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>    
	    <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> 
	    <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 href="http://www.w3.org/TR/2005/WD-xpath-functions-20050404/">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/2005/xpath-functions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2005/xpath-functions</loc>.</p>
</abstract>
<status id="status">
<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>
This is a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsPR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Proposed
Recommendation</loc>.
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 on 08 June 2006. 
A revision <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">was published</loc>
in order to give visibility to the technical decisions that had been made in response to
comments received since initial publication of the Candidate Recommendation.</p>
<p>Publication as a Proposed 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 Proposed Recommendation until at least
31 December 2006.</p>

<!--
was 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 href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR">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>. 
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>This specification is designed to be referred to normatively from
other specifications defining a host language for it; it is not
intended to be implemented outside a host language.  The
implementability of this specification has been tested in the context
of its normative inclusion in host languages defined by the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/xquery" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQuery 1.0</loc> and <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/xslt20" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XSLT 2.0</loc> specifications; see
those specifications for implementation reports.</p>

<p> The public review of this specification is now closed. However, errors may still be reported using 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>
Members of the W3C Advisory Committee will find the appropriate review
form for this document by consulting their <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2002/09/wbs/myQuestionnaires" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">list of current
WBS questionnaires</loc>.
Note that substantive technical comments were expected during the Last
Call review period that ended 15 February 2004.
</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/2004/01/pp-impl/18797/status#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 XML Query Working Group and also maintains a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/01/pp-impl/19552/status#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>

<!--
<p>This draft includes corrections and changes based on
<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=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=">public comments</loc> recorded in the W3C public Bugzilla repository (<loc
href="http://www.w3.org/Bugs/Public/">http://www.w3.org/Bugs/Public/</loc>)
used for issue tracking on the <loc href="http://www.w3.org/TR/2005/CR-xpath-functions-20051103/">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 href="http://www.w3.org/TR/2005/CR-xpath-functions-20051103/">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 href="http://www.w3.org/Bugs/Public/">public Bugzilla system</loc> (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 XSLT/XPath/XQuery mailing list, <loc href="mailto:public-qt-comments@w3.org">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 href="http://lists.w3.org/Archives/Public/public-qt-comments/">http://lists.w3.org/Archives/Public/public-qt-comments/
</loc>.</p>

<p>The <loc href="http://www.w3.org/XML/Query/test-suite/">XML Query and XPath Test Suite</loc> is under development. 
Implementors are encouraged to run this test suite and report their results.
A <loc href="http://www.w3.org/XML/Query/test-suite/XQTSReport.html">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
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</loc>. W3C maintains a <loc href="http://www.w3.org/2002/08/xmlquery-IPR-statements">public list of any patent disclosures</loc> made in connection with the deliverables of the XML Query Working Group and also maintains a <loc href="http://www.w3.org/Style/XSL/Disclosures">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 href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</loc> 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>
 -->

            <!-- ****************************************************************************************** -->
            <!-- 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/2005/xpath-operators</code> for operators</p>
					</item> -->
                    <item>
                        <p>

                            <code>http://www.w3.org/2005/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>If the context item is undefined, error <xerrorref spec="XP" class="DY" code="0002" type="type"/> is raised.</p>
             <p>If <code>$arg</code> is the empty sequence, the zero-length string is returned.</p>
                <p>If <code>$arg</code> is a node, the function returns the string-value of the
                    node, as obtained using the <code>dm:string-value</code> accessor defined in the
                        <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. 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> fn:doc(fn:document-uri($arg)) is $arg</eg> -->
<p>In the case of a document node <code>$D</code> returned by the <code>fn:doc</code> function, or a document node at the root of a tree containing a node returned by the <code>fn:collection</code> function, it will always be true that either <code>fn:document-uri($D)</code> returns the empty sequence, or that the following expression is true: <code>fn:doc(fn:document-uri($D))</code> is <code>$D</code>. It is implementation-defined whether this guarantee also holds for document nodes obtained by other means, for example a document node passed as the initial context node of a query or transformation.</p>
            </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="yes" returnSeq="no" returnVaries="no" isSchema="no" isDatatype="no" isSpecial="no" isOp="no">
                        <arg name="arg1" type="xs:date" emptyOk="yes"/>
                        <arg name="arg2" type="xs:time" emptyOk="yes"/>
                    </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 result is the empty sequence if either of the parameters is the empty sequence.</p>
<p>
The timezone of the result is computed as follows:</p>
                <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>
                         