SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
| Introduction
| EXSLT Extensions
| Extension attributes (XSLT only)
| Additional serialization parameters
» | Extension functions
| Extension instructions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# saxon:namespace-node()

saxon:namespace-node($prefix as xs:string, $uri as xs:string) ==> node()

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.

The function serves the same role in XQuery as the `xsl:namespace` instruction in XSLT 2.0: it allows a namespace in the result document to be computed dynamically.

The namespace node is typically used as part of the computed content of a constructed element node. For example:

    declare namespace saxon="http://saxon.sf.net/";
    <a xsi:type="my:decimal">
      { saxon:namespace-node("my", "http://my.uri/"), 12.4 }
    </a>

produces the output:

    <a xmlns:my="http://my.uri/"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:type="my:decimal">12.4</a>

In this case the namespace node could equally well be created by adding the namespace declaration `xmlns:my="http://my.uri/"` to the direct element constructor for the <a> 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.

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.

Next