copy [--respective|:r] expression location expression
$results := copy [--respective|:r] expression location expression
Copies nodes in the first node-list expression (source nodes) to the destinations determined by the the location directive applied to nodes in the second node-list expression (target nodes). If the source node-list contains more than one node, than N'th node in the source node-list is copied to the location relative to the N'th node in the target node-list.
If --respective|:r
option
is used, then the target node-list expression
is evaluated in the context of the source node
being copied.
Possible values for location are:
after
, before
,
into
, replace
,
append
and prepend
. The first
three location directives cause making a copy of the source nodes
after, before, and within (as the last child-node) the target
nodes, respectively.
If replace
location directive is used,
source node are copied before the respective
target nodes and target nodes are removed.
The append
and prepend
location directives allow,
depending on the destination node type,
either inserting copies of the
source nodes as the first or last child nodes of
a destination element or appending/prepending
destination node data in case of non-element destination nodes.
See location argument type
for more detail.
The command returns a node-list consisting of the copies of all source nodes created by the command.
Despite the fact the command is named "copy", nodes resulting from copying the source nodes may pass through certain type conversion before they are inserted at the appointed destinations. This, however, only happens in cases where the types of the source and target nodes are not compatible with the location directive. See location argument type for more detail.
Note that XSH2 refuses to create multiple top-level
elements using copy
,
move and similar commands.
Example 24. Replace living-thing elements in the document b with copies of the corresponding creature elements from the document $a.
xsh> copy $a//creature replace $b//living-thing
Example 25. Copy every element into itself
xsh> copy --respective $a//* into .
xsh> copy $a//* into $a//*
#same as
above