The insert action inserts items into an instance, and has 5 attributes, all optional:
ref or bind that gives a destination sequence
(default an empty sequence);context, that gives the context for the ref
(default the element context);origin, evaluated in the in-scope evaluation context, that
specifies a source sequence, (default, the last item in the destination
sequence);at, that specifies a numeric location in the destination
sequence for the insertion (default, the size of the destination
sequence);position, whether to insert before or
after the destination location (default
after).After successful conclusion, an xforms-insert event is
dispatched to the destination instance with appropriate context information,
including a list of the items inserted.
An insert action has no effect if:
at attribute, evaluated as a number in the Element
Evaluation Context and rounded to the nearest integer, is not a number or
is out of bounds of a non-empty destination sequence.Each item of the source sequence is inserted:
at and
position.If an item to be inserted is a node, it and its entire subtree are copied and inserted; if it is an atomic value, a text node is created and inserted.
An item is not inserted:
If the destination location is a root element, the item must be an element, and it replaces the destination element and its children, otherwise the item is not inserted.
If the destination sequence has sort properties, the inserted nodes will end
up sorted accordingly, regardless of the at and
position attributes.
| Document | Element | Attribute | Text | NS | PI | Comment | |
|---|---|---|---|---|---|---|---|
| Document | X | Replaces root element | X | X? | X? | Insert? | Insert? |
| Root element | X | Replaces root element | Becomes/replaces attr | Sibling? | Insert/replace | Insert | Insert |
| Element | X | Sibling unless parent is doc | Becomes/replaces attr | Sibling | Insert/replace | Insert | Insert |
| Attribute | X | X | Replaces or sibling | X? | X | X | X |
| Text | X | Sibling unless parent is doc | X | Concat | X | Sibling | Sibling |
| NS | X | X | X | X | Sibling or replace | X | X |
| PI | X | Sibling unless parent is doc | X | Sibling | X | Sibling | Sibling |
| Comment | X | Sibling unless parent is doc | X | Sibling | X | Sibling | Sibling |
https://www.w3.org/community/xformsusers/wiki/XForms_2.0#The_insert_Element
The text for the insert element is two pages of fairly opaque text, which I have recently thought about a lot trying to make it more digestible.
=====
The target-sequence is obtained from the element evaluation context.
The origin-sequence is obtained
the nodes of the origin-sequence are added one by one to the context element
the last element of the target-sequence is copied, and added to the target sequence
the origin-sequence is obtained
the nodes are added one by one to the target sequence.
An origin sequence is obtained by evaluating the origin attribute in the in-scope evaluation context, and removing any root nodes (parents of document elements) from the resulting sequence. An implementation may choose not to include namespace nodes in the origin-sequence, in particular if the namespace axis is not supported or if inserting the namespace node would make the data model inconsistent.
An element is added to a sequence:
by inserting the element at the appropriate sort position in the sequence
by inserting the element according to the at and
position values:
it is evaluated as a number in the Element Evaluation Context and
rounded to the nearest integer;
if the result is not a number, is less than 1 or is greater than the
target-sequence size: the insert action has no effect.
The size of the target-sequence is used
===============
The insert action has no effect