stm:remove-ns
STM by Example
Index > Books > Declarative Development Guide > Reference Library > Developer Guides > STM By Example > 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. See remove-ns-decl.

<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

Example 2: Remove Namespace Completely

This example is essentially the same as Example 1. However we now entirely remove the namespace by using the remove-ns-decl operation on /a/b

<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:remove-ns-decl prefix="country" uri="http://1060.org/stm/apply-ns/eg1" xpath="/a/b" />
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

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