Previous Up Next


p:rename

p:rename — Renames elements, attributes, or processing instructions.

Synopsis

<p:declare-step type="p:rename">
     <p:input port="source"/>
     <p:output port="result"/>
     <p:option name="match" required="true"/>                      <!-- XSLTMatchPattern -->
     <p:option name="new-name" required="true"/>                   <!-- QName -->
     <p:option name="new-prefix"/>                                 <!-- NCName -->
     <p:option name="new-namespace"/>                              <!-- anyURI -->
</p:declare-step>

Description

The p:rename step renames matching elements, attributes, or processing-instructions in the document. It doesn't make any sense to match comment or text nodes, they don't have names.

If the new-name value contains a colon, then its value is interpreted as a QName and there must be an in-scope namespace declaration for that prefix in the pipeline document. It is an error in this case to specify either an new-prefix or new-namespace.

If the new-name option does not contain a colon, you can use the new-namespace and new-prefix options to place it in a namespace and provide a suggested prefix.

Each element, attribute, or processing-instruction that matches the match option is renamed with the specified name. In the case of attributes, if the element already had an attribute with the specified name, it is effectively deleted before the renaming is performed.

With respect to attributes named “xml:base”, the following semantics apply: renaming an fromxml:baseto something else has no effect on the underlying base URI of the element; however, if an attribute is renamed from something else toxml:base”, the base URI of the element is updated accordingly.

If the pattern matches processing instructions, then it is the processing instruction target that is renamed. In this case, it's an error if the new name specifies a namespace.

Errors

Error Description
err:C0023 Occurs if the pattern matches anything other than element, attribute or processing instruction nodes.
err:D0034 Occurs It is a dynamic error to specify a new namespace or prefix if the lexical value of the specified name contains a colon.
err:C0013 Occurs if the pattern matches a processing instruction and the new name has a non-null namespace.

Examples

This pipeline renames the para elements to p:

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:h="http://www.w3.org/1999/xhtml"
                version="1.0">
    
  5   <p:rename match="para" new-name="h:p"/>
    </p:pipeline>
Input Output
1 <doc>
<?vocabulary pseudo-docbook?>
<para role="summary">Some text.</para>
<para>Some other text.</para>
5 </doc>
 
1 <doc>
<?vocabulary pseudo-docbook?>
<h:p xmlns:h="http://www.w3.org/1999/xhtml" role="summary">Some text.</h:p>
<h:p xmlns:h="http://www.w3.org/1999/xhtml">Some other text.</h:p>
5 </doc>

This pipeline renames the role attribute to class:

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:h="http://www.w3.org/1999/xhtml"
                version="1.0">
    
  5   <p:rename match="@role" new-name="class"/>
    </p:pipeline>
Input Output
1 <doc>
<?vocabulary pseudo-docbook?>
<para role="summary">Some text.</para>
<para>Some other text.</para>
5 </doc>
 
1 <doc>
<?vocabulary pseudo-docbook?>
<para class="summary">Some text.</para>
<para>Some other text.</para>
5 </doc>

This pipeline renames the processing instruction:

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:h="http://www.w3.org/1999/xhtml"
                version="1.0">
    
  5   <p:rename match="processing-instruction('vocabulary')"
                new-name="old-vocabulary"/>
    </p:pipeline>
Input Output
1 <doc>
<?vocabulary pseudo-docbook?>
<para role="summary">Some text.</para>
<para>Some other text.</para>
5 </doc>
 
1 <doc>
<?old-vocabulary pseudo-docbook?>
<para role="summary">Some text.</para>
<para>Some other text.</para>
5 </doc>