protected function mergeAttributes(\DOMNode $element, array &$newAttributes)
{
/** @var $attribute \DOMAttr */
foreach ($element->attributes as $attribute) {
$oldAttributeValue = $attribute->hasChildNodes() ? $attribute->value : null;
$newAttributeValue = isset($newAttributes[$attribute->name]) ? $newAttributes[$attribute->name] : null;
$mergedAttributes = array();
if ($newAttributeValue !== null && $newAttributeValue !== $oldAttributeValue) {
$mergedAttributes[] = $newAttributeValue;
}
if ($oldAttributeValue !== null) {
$mergedAttributes[] = $oldAttributeValue;
}
$newAttributes[$attribute->name] = $mergedAttributes !== array() ? implode(' ', $mergedAttributes) : null;
}
}