xinsert command


Usage

xinsert [--namespace expression] node-type expression location xpath

Aliases

xadd

Description

Create new nodes of the node-type given in the 1st argument of name specified in the 2nd argument and insert them to locations relative to nodes in the node-list specified in the 4th argument.

For element nodes, the the 2nd argument expression should evaluate to something like "<element-name att-name='attvalue' ...>". The < and > characters are optional. If no attributes are used, the expression may simply consist the element name. Note, that in the first case, the quotes are required since the expression contains spaces.

Attribute nodes use the following syntax: "att-name='attvalue' [...]".

For the other types of nodes (text, cdata, comments) the expression should contain the node's literal content. Again, it is necessary to quote all whitespace and special characters as in any expression argument.

The location argument should be one of: after, before, into, replace, append or prepend. See documentation of the location argument type for more detail.

Optionally, for element and attribute nodes, a namespace may be specified with --namespace or :n. If used, the expression should evaluate to the desired namespace URI and the name of the element or attribute being inserted must have a prefix.

The command returns a node-list consisting of nodes it created.

Note, that instead of xinsert, you can alternatively use one of xsh:new-attribute, xsh:new-cdata, xsh:new-chunk, xsh:new-comment, xsh:new-element, xsh:new-element-ns, xsh:new-pi, and xsh:new-text together with the command xcopy.

Example 1. Give each chapter a provisional title element.

xsh> my $new_titles := xinsert element "<title font-size=large underline=yes>" \
  into /book/chapter
xsh> xinsert text "Change me!" into $new_titles;

Example 2. Same as above, using xcopy and xsh:new-... instead of xinsert

xsh> my $new_titles := xcopy xsh:new-element("title","font-size","large","underline","yes") \
  into /book/chapter
xsh> xcopy xsh:new-text("Change me!") into $new_titles;

See Also

insert, move, xmove

Sections

Tree modification