rename nodename expression
NOTE: THE SEMANTICS OF COMMAND HAS CHANGED IN 2.1.0
This command is very similar to the map command, except that it operates on nodes' names rather than their content. It changes name of every element, attribute or processing-instruction contained in the node-list specified in the second argument expression, according to the value of the nodename expression, which is evaluated in the context of each node in turn.
If the nodename is a Perl
expression, then the name of the node is also stored into Perl's
$_
variable prior to evaluation.
The flag --in-place
(:i
)
can be used to indicate that
the new name should be collected from the $_
variable rather than from the result of the expression itself.
The --namespace
(:n
) argument
may be used to provide namespace for the renamed nodes.
--reverse
(:r
) flag
instruct the map to process the nodelist
in reversed order.
Note: if the expression nodename returns an undefined value for a particular node, the node's original name and namespace are preserved.
Example 46. Substitute dashes with underscores in all node names
xsh> rename :i { s/-/_/g } (//*|//@*)
Example 47. Make all elements start with the name of their parents
xsh> rename concat(local-name(parent::*),'.',local-name(.)) //*[parent::*]