stm:remove-nsstm:remove-ns
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:remove-ns

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:



Attribute
xpathrequired the target xpath into the operand document
prefixrequired prefix identifier to use for namespace uri

The stm:remove-ns operation removes a namespace and associated prefix from a document fragment located by an xpath. The children of the target element are all moved out of the namespace.

Due to the historical difficulty of handling namespaces they have generally been infrequently used by XML applications. STM attempts to make removal 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.

Limitations: The current implementation only handles namespace removal from elements, though this should cover 90% of use cases.

Due to the limitations of the DOM model removing namespaces is a relatively expensive operation.

Example

Example 1: Remove a namespace

This example first applies a namespace country to the first <b> element and it's children. This namespace on /a/country:b is then removed. The result is the original document but including the namespace declaration.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:apply-ns prefix="country" uri="http://1060.org/stm/apply-ns/eg1" xpath="/a/b[1]" />
          <stm:remove-ns prefix="country" xpath="/a/country:b" />
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.