Assume that $source and $dest are instances of DOMDocument. Assume that $sourcedoc contains an element with ID 'sourceID' and that $destdoc contains an element with ID 'destID'. Assume that we have already set up source and destination element variables thus:
<?php
$src = $sourcedoc->getElementById('sourceID');
$dst = $destdoc->getElementById('destID');
?>
Finally, assume that $sel has more than one child node.
In order to import the child elements of $src as children of $dst, you might do something like this:
<?php
$src = $dest->importNode($src, TRUE);
foreach ($src->childNodes as $el) $dst->appendChild($el);
?>
But this does not work. foreach gets confused, because (as noted below) appending an imported element to another existing element in the same document causes it to be removed from its current parent element.
Therefore, the following technique should be used:
<?php
foreach ($src->childNodes as $el) $dst->appendChild($destdoc->importNode($el, TRUE));
?>