copy

Usage

copy xpath location xpath

Aliases

cp

Description

Copies nodes matching the first xpath to the destinations determined by the location directive relative to the second xpath. If more than one node matches the first xpath than it is copied to the position relative to the corresponding node matched by the second xpath according to the order in which are nodes matched. Thus, the n'th node matching the first xpath is copied to the location relative to the n'th node matching the second xpath.

The possible values for location are: after, before, into, replace and cause copying the source nodes after, before, into (as the last child-node). the destination nodes. If replace location is used, the source node is copied before the destination node and the destination node is removed.

Some kind of type conversion is used when the types of the source and destination nodes are not equal. Thus, text, cdata, comment or processing instruction node data prepend, append or replace value of a destination attribute when copied before,after/into or instead (replace) an attribute, and vice versa.

Attributes may be copied after, before or into some other attribute to append, prepend or replace the destination attribute value. They may also replace the destination attribute completely (both its name and value). To copy an attribute from one element to another, simply copy the attribute node into the destination element.

Elements may be copied into other elements (which results in appending the child-list of the destination element), or before, after or instead (replace) other nodes of any type except attributes.

Example 13. Replace living-thing elements in the document b with the coresponding creature elements of the document a.

xsh> copy a://creature replace b://living-thing