8. insert-after

insert-after(inserted, after?)

Insert inserted, one or more nodes, after node after. Parameter after defaults to the context node.



insert-after(<meta name="{$metaName}" content="{$metaContent}"/>, $title);

Always pass detached nodes as the first argument of insert or replace

The nodes passed as the first argument of commands insert-after, insert-before, insert-into or replace must have no parent nodes (“detached nodes”).

Example: something like what follows works fine:

insert-after($caption, $table);

While something like what follows will report an execution error:

insert-after($caption, $table);

When passing detached nodes is not possible or not desirable, simply use XPath extension function copy() to copy the nodes. Example:

insert-after(copy($caption), $table);