A namespace is a URI associated with a document node which is expressed by a short-hand prefix on the element name.
The stm:apply-ns operation applies a namespace to a document fragment located by an xpath reference to an element.
The children of the target element are all moved into the namespace. The xmlns: declaration will be made on target element.
If the target xpath is multivalued then each fragment will be processed and a namespace declaration will be made on each fragment root element.
Due to the historical difficulty of handling namespaces they have generally been infrequently used by XML applications.
STM attempts to make assignment of namespaces straightforward. We anticipate that namespace assigment can be a valuable
tool in XML processing. For example portions of an in-process document may be moved into a temporary namespace to hide it
from intermediate processing steps before moving it back to the original namespace on completion.
stm:apply-ns is namespace aware, it cannot be used to overwrite an existing namespace. An existing namespace must first
be removed before applying a new namepspace, see stm:remove-ns.
Limitations: The current implementation only handles namespace assignment to elements, though this should
cover 90% of use cases.
Note: Remember that subsequent operations must use the namespace in any xpath that references these newly namespaced fragment!
Due to the limitations of the DOM model applying namespaces is a relatively expensive operation.