Insert Nodes
Description and syntax
Inserts one or more nodes before, after, or inside the specified target node.
insert (node|nodes) items into targetNode
insert (node|nodes) items as first into targetNode
insert (node|nodes) items as last into targetNode
insert (node|nodes) items before targetNode
insert (node|nodes) items after targetNode
Details
•The expression items must return a sequence of items. Even though the keyword node|nodes is used, items can be a sequence of non-node items.
•The expression targetNode must point to a single target node.
•If the keyword into is used, targetNode must be an element node or document-element node.
•If the keyphrase as first or as last is used, the insertion is as first or last children, respectively.
•If the keyword into is used alone, then attributes are appended to existing attributes, and elements are inserted as first children.
•If the keyword before or after is used, targetNode can be of any type.
•If an attribute is being inserted, its name must not duplicate that of an already existing attribute.
Examples
for $i in /book/section return
insert nodes (attribute id { 'somevalue' }, <newelement>some content including the numbers "{ 1 to 3}"</newelement>)
into $i