Name

cx:namespace-delete — Delete namespace declarations.

Synopsis

<p:declare-step type="cx:namespace-delete" xmlns:cx="http://xmlcalabash.com/ns/extensions">
     <p:input port="source"/>
     <p:output port="result"/>
     <p:option name="prefixes"/>                                   <!-- ListOfStrings -->
</p:declare-step>

Description

This step aggressively removes all of the namespaces identified by the specified prefixes from the document. The prefixes must be in-scope at the point where the cx:namespace-delete element occurs.

Consider this document:

<doc xmlns:ns1="http://example.com/ns1"
     xmlns:ns2="http://example.com/ns2">
  <para ns1:attr="value">This document has
unspecified semantics with respect to
<ns1:item>{ns1:foo}</ns1:item> and
<ns2:item>{ns2:bar}</ns2:item>.</para>
</doc>

If the following step is used to remove the “ns1” prefix,

<cx:namespace-delete xmlns:ns1="http://example.com/ns1"
                     prefixes="ns1"/>

the resulting document will be:

<doc xmlns:ns2="http://example.com/ns2">
  <para attr="value">This document has
unspecified semantics with respect to
<item>{ns1:foo}</item> and
<ns2:item>{ns2:bar}</ns2:item>.</para>
</doc>

Observe that the namespace declaration has been stripped off both elements and attributes. If prefixes occur in places, such as attribute values or text content, not “visible” to the XML specification, they are not changed.

Note

Removing namespace declarations from attributes can introduce well-formedness problems. For example, if the “para” element in the example had an attr attribute in no namespace, deleting “ns1” would leave two attributes with the same name on the element. This is not well-formed and the step would fail.

This problem can be addressed by first deleting the offending attributes, perhaps like so:

<p:delete xmlns:ns1="http://example.com/ns1"
          match="*[@ns1:attr]/@attr"/>