private static function add($target, $node)
{
if ($node instanceof \DOMDocument) {
if ($node->documentElement instanceof \DOMElement) {
$target->appendChild($target->ownerDocument->importNode($node->documentElement, TRUE));
}
} elseif ($node->ownerDocument !== $target->ownerDocument) {
$target->appendChild($target->ownerDocument->importNode($node, TRUE));
} else {
$target->appendChild($node->cloneNode(TRUE));
}
}