<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensions" page="functions" subpage="namespace-node"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: saxon:namespace-node()</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: saxon:namespace-node()"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>saxon:namespace-node()</h1>
      <p><b>saxon:namespace-node($prefix as xs:string, $uri as xs:string) ==&gt; node()</b></p>
      <p><i>This extension is obsolescent, as the functionality is available from Saxon 9.2 onwards using the syntax
appearing in the draft XQuery 3.0 specification.</i></p>
      <p>This function creates a new namespace node. The first argument gives the name of the namespace node (that is,
the namespace prefix), while the second gives the namespace URI. The prefix may be "" to create a default namespace;
otherwise it must be a valid NCName. The URI must not be the empty string.</p>
      <p>The function serves the same role in XQuery as the <code>xsl:namespace</code> instruction in XSLT 2.0: it allows
a namespace in the result document to be computed dynamically.</p>
      <p>The namespace node is typically used as part of the computed content of a constructed element node. 
For example:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>declare namespace saxon="http://saxon.sf.net/";
&lt;a xsi:type="my:decimal"&gt;
  { saxon:namespace-node("my", "http://my.uri/"), 12.4 }
&lt;/a&gt;</code>
         </pre>
      </div>
      <p>produces the output:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>&lt;a xmlns:my="http://my.uri/" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:type="my:decimal"&gt;12.4&lt;/a&gt;</code>
         </pre>
      </div>
      <p>In this case the namespace node could equally well be created by adding the namespace declaration
 <code>xmlns:my="http://my.uri/"</code> to the direct element constructor for the &lt;a&gt; element. 
 But this is not always possible, for example
 (a) if the element name is not known statically, or (b) if the namespace URI is not known statically,
 or (c) if the decision whether or not to add the namespace node depends on input data.</p>
      <p><i>Note: the use case for this function relies on an extension to the semantics of XQuery element construction. Saxon treats a
 namespace node appearing in the content of an element constructor according to the XSLT rules: that is, the
 namespace node is added to the containing element in the same way as attributes are added. Attributes and
 namespaces may appear in any order, but must precede any child nodes.</i></p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="stream.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>