Previous Up Next


p:namespace-rename

p:namespace-rename — Changes the URI associated with a namespace binding.

Synopsis

<p:declare-step type="p:namespace-rename">
     <p:input port="source"/>
     <p:output port="result"/>
     <p:option name="from"/>                                       <!-- anyURI -->
     <p:option name="to"/>                                         <!-- anyURI -->
     <p:option name="apply-to" select="'all'"/>                    <!-- "all" | "elements" | "attributes" -->
</p:declare-step>

Description

In the serialized form of an XML document, changing the URI associated with a namespace declaration is a small, local operation. In an XPath data model, changing the URI associated with a namespace binding effects not just the element on which the changes is made, but potentially all of it's descendants.

The p:namespace-rename step exists to accomplish this task. It changes the URI associated with a namespace binding for an entire substree of the document. This renaming can be applied to elements, attributes, or both elements and attribute, as controlled by the apply-to option.

This step cannot perform operations that are forbidden by XML. You cannot change the XML namespace (http://www.w3.org/XML/1998/namespace) or the XMLNS namespace (http://www.w3.org/2000/xmlns/).

If the value of the from option is the same as the value of the to option, the input is reproduced unchanged on the output. Otherwise, namespace bindings, namespace attributes and element and attribute names are changed as follows:

FIXME:

The apply-to option is primarily intended to make it possible to avoid renaming attributes when the from option specifies no namespace, since many attributes are in no namespace.

Care should be taken when specifying no namespace with the to option. Prefixed names in content, for example QNames and XPath expressions, may end up with no appropriate namespace binding.

Errors

Error Description
err:C0014 Occurs if the XML namespace (http://www.w3.org/XML/1998/namespace) or the XMLNS namespace (http://www.w3.org/2000/xmlns/) is the value of either the from option or the to option.

Examples

One use of p:namepace-rename is to move content that is (or isn't) in a namespace into (or out of) a namespace.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:namespace-rename from=""
  5                       to="http://www.w3.org/1999/xhtml"/>
    </p:pipeline>
Input Output
1 <html>
<head>
<title>My Title</title>
</head>
5 <body>
<p>Hello world.</p>
</body>
</html>
 
1 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
</head>
5 <body>
<p>Hello world.</p>
</body>
</html>

It can also be used to change the namespace associated with attributes.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:namespace-rename from=""
  5                       to="http://www.w3.org/1999/xlink"
                          apply-to="attributes"/>
    </p:pipeline>
Input Output
1 <doc>
<para href="http://www.w3.org/">Some text.</para>
</doc>
 
1 <doc>
<para xmlns:_1="http://www.w3.org/1999/xlink"
_1:href="http://www.w3.org/">Some text.</para>
</doc>