protected function initialMatchOnElement($selector, $matches)
{
$element = $selector->element;
if (is_null($element)) {
$element = '*';
}
$found = $this->newMatches();
foreach ($matches as $node) {
// Capture the case where the initial element is the root element.
if ($node->tagName == $element || $element == '*' && $node->parentNode instanceof \DOMDocument) {
$found->attach($node);
}
$nl = $node->getElementsByTagName($element);
$this->attachNodeList($nl, $found);
}
$selector->element = null;
return $found;
}