<apidoc:module name="QNameBuiltins" category="QNameBuiltins" lib="fn" xmlns:apidoc="http://marklogic.com/xdmp/apidoc"><apidoc:summary access="public" category="QNameBuiltins" bucket="W3C-Standard Functions">
These built-in functions are XQuery functions defined to operate on 
qualified name (xs:QName) values. They are defined in
<a href="http://www.w3.org/TR/xpath-functions/" xmlns="http://www.w3.org/1999/xhtml">XQuery 1.0 
and XPath 2.0 Functions and Operators</a>. 
</apidoc:summary><apidoc:function name="resolve-QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
  Returns an <code>xs:QName</code> value (that is, an expanded QName) 
  by taking an <code>xs:string</code> that has the lexical form of an 
  <code>xs:QName</code> (a string in the form "prefix:local-name" or 
  "local-name") and resolving it using the in-scope namespaces for a 
  given element. 
</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="qname" type="xs:string?" optional="false">
  A string of the form "prefix:local-name".
  </apidoc:param>
      <apidoc:param name="element" type="element()" optional="false">
  An element providing the in-scope namespaces to use to resolve the 
  qualified name. 
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:QName?</apidoc:return>
    <apidoc:usage>
<p xmlns="http://www.w3.org/1999/xhtml">Sometimes the requirement is to construct an <code>xs:QName</code> 
without using the default namespace. This can be achieved by writing: 
</p>
<pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
     if ( fn:contains($qname, ":") ) 
     then ( fn:resolve-QName($qname, $element) ) 
     else ( fn:QName("", $qname) )
</pre>
<p xmlns="http://www.w3.org/1999/xhtml">If the requirement is to construct an <code>xs:QName</code> using the 
namespaces in the static context, then the <code>xs:QName</code> 
constructor should be used. 
</p>
<p xmlns="http://www.w3.org/1999/xhtml">
If $qname does not have the correct lexical form for <code>xs:QName</code> 
an error is raised [err:FOCA0002]. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $qname is the empty sequence, returns the empty sequence.
</p><p xmlns="http://www.w3.org/1999/xhtml">
More specifically, the function searches the namespace bindings of $element for
a binding whose name matches the prefix of $qname, or the zero-length string
if it has no prefix, and constructs an expanded QName whose local name is
taken from the supplied $qname, and whose namespace URI is taken from the
string value of the namespace binding. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the $qname has a prefix and if there is no namespace binding for $element
that matches this prefix, then an error is raised [err:FONS0004]. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the $qname has no prefix, and there is no namespace binding for $element
corresponding to the default (unnamed) namespace, then the resulting
expanded QName has no namespace part. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
The prefix (or absence of a prefix) in the supplied $qname argument is retained
in the returned expanded QName, as discussed in Section 2.1 Terminology[DM].
</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
Assume that the element bound to $element has a single 
namespace binding bound to the prefix "eg". 

fn:resolve-QName("hello", $element) 

=&gt; a QName with local name "hello"
   that is in no namespace. 

fn:resolve-QName("eg:myFunc", $element) 

=&gt; an xs:QName whose namespace URI is specified 
   by the namespace binding corresponding to the 
   prefix "eg" and whose local name is "myFunc".
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
  Returns an <code>xs:QName</code> with the namespace URI given in $paramURI. 
  If $paramURI is the zero-length string or the empty sequence, it 
  represents "no namespace"; in this case, if the value of $paramQName 
  contains a colon (:), an error is raised [err:FOCA0002]. 
  The prefix (or absence of a prefix) in $paramQName is retained in 
  the returned xs:QName value. The local name in the result is taken 
  from the local part of $paramQName.
</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="paramURI" type="xs:string?" optional="false">
A namespace URI, as a string.
  </apidoc:param>
      <apidoc:param name="paramQName" type="xs:string" optional="false">
A lexical qualified name (xs:QName), a string of the form "prefix:localname" 
or "localname".
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:QName</apidoc:return>
    <apidoc:usage>
<p xmlns="http://www.w3.org/1999/xhtml">
  If $paramQName does not have the correct lexical form for 
  <code>xs:QName</code> an error is raised [err:FOCA0002]. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
  Note that unlike xs:QName this function does not require an
  <code>xs:string</code> literal as the argument.
</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
fn:QName("http://www.example.com/example", "person") 

=&gt; an xs:QName with namespace URI = 
   "http://www.example.com/example", 
   local name = "person", and
   prefix = "". 

fn:QName("http://www.example.com/example", "ht:person")

=&gt; an xs:QName with namespace URI = 
   "http://www.example.com/example", 
   local name = "person",
   and prefix = "ht".
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="expanded-QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
  [0.9-ml only, use <a href="#fn:QName"><code>fn:QName</code></a> instead] 
  Returns an 
  <code>xs:QName</code> with the namespace URI given in $paramURI and
  the local name in $paramLocal. 
  If $paramURI is the zero-length string or the empty sequence, it 
  represents "no namespace".
</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="paramURI" type="xs:string?" optional="false">
   A namespace URI, as a string.
  </apidoc:param>
      <apidoc:param name="paramLocal" type="xs:string" optional="false">
   A localname, as a string.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:QName</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: this function only exists in 0.9-ml :)
xquery version "0.9-ml"
fn:expanded-QName("http://www.example.com/example", "person") 

=&gt; an xs:QName with namespace URI = 
   "http://www.example.com/example", 
   local name = "person". 

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="prefix-from-QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
  Returns an <code xmlns="http://www.w3.org/1999/xhtml">xs:NCName</code> representing the prefix of $arg. 
  The empty sequence is returned if $arg is the empty sequence or 
  if the value of $arg contains no prefix. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="arg" type="xs:QName?" optional="false">
A qualified name.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:NCName?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";
declare namespace ex="http://www.example.com/example";

fn:prefix-from-QName(
   fn:QName("http://www.example.com/example", "person") )

=&gt; empty sequence, because the QName constructed 
   by fn:QName does not have a prefix 
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
let $qn := fn:QName("http://www.w3.org/XML/1998/namespace", "lang")
return
fn:prefix-from-QName(fn:node-name( attribute {$qn} {"en"}))

=&gt; xml 
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="local-name-from-QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
  Returns an <code xmlns="http://www.w3.org/1999/xhtml">xs:NCName</code> representing the local part of 
  $arg. If $arg is the empty sequence, returns the empty sequence. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="arg" type="xs:QName?" optional="false">
A qualified name.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:NCName?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
fn:local-name-from-QName(
   fn:QName("http://www.example.com/example", "person") )

=&gt; person 
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="namespace-uri-from-QName" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
  Returns the namespace URI for $arg as an <code xmlns="http://www.w3.org/1999/xhtml">xs:string</code>. If 
  $arg is the empty sequence, the empty sequence is returned. If $arg 
  is in no namespace, the zero-length string is returned. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="arg" type="xs:QName?" optional="false">
  A qualified name.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:anyURI?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
fn:namespace-uri-from-QName(
  fn:QName("http://www.example.com/example", "person") ) 
 
=&gt; the namespace URI corresponding to
   "http://www.example.com/example". 
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="namespace-uri-for-prefix" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
  Returns the namespace URI of one of the in-scope namespaces for $element,
  identified by its namespace prefix. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
  If $element has an in-scope namespace whose namespace prefix is equal to
  $prefix, it returns the namespace URI of that namespace. If $prefix is the
  zero-length string or the empty sequence, it returns the namespace URI of
  the default (unnamed) namespace. Otherwise, it returns the empty sequence. 
</p><p xmlns="http://www.w3.org/1999/xhtml">
  Prefixes are equal only if their Unicode code points match exactly.
</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="prefix" type="xs:string?" optional="false">
  A namespace prefix to look up.
  </apidoc:param>
      <apidoc:param name="element" type="element()" optional="false">
  An element node providing namespace context.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:anyURI?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "0.9-ml"
declare namespace ex="http://www.example.com/example"

let $x := &lt;ex:hello&gt;1&lt;/ex:hello&gt;
return
fn:namespace-uri-for-prefix("ex", $x)
 
=&gt; the namespace URI corresponding to
   "http://www.example.com/example".   
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="in-scope-prefixes" type="builtin" lib="fn" category="QNameBuiltins" bucket="W3C-Standard Functions" hidden="false">
    <apidoc:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
Returns the prefixes of the in-scope namespaces for $element. For namespaces
that have a prefix, it returns the prefix as an xs:NCName. For the default
namespace, which has no prefix, it returns the zero-length string.  
</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="element" type="element()" optional="false">
The element whose in-scope prefixes will be returned.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "0.9-ml"
declare namespace a="a"
declare namespace b="b"

let $x := &lt;a:hello&gt;hello
            &lt;b:goodbye&gt;goodbye&lt;/b:goodbye&gt;
	  &lt;/a:hello&gt;
return
fn:in-scope-prefixes($x)

=&gt; a

xquery version "0.9-ml"
declare namespace a="a"
declare namespace b="b"

let $x := &lt;a:hello&gt;hello
            &lt;b:goodbye&gt;goodbye&lt;/b:goodbye&gt;
	  &lt;/a:hello&gt;
return
fn:in-scope-prefixes($x/b:goodbye)

=&gt; b a
</pre></apidoc:example>
  </apidoc:function></apidoc:module>