You are here

protected function QueryPathCssEventHandler::onlyChild in QueryPath 7.3

Same name and namespace in other branches
  1. 6 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::onlyChild()
  2. 7.2 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::onlyChild()
1 call to QueryPathCssEventHandler::onlyChild()
QueryPathCssEventHandler::pseudoClass in QueryPath/CssEventHandler.php

File

QueryPath/CssEventHandler.php, line 846

Class

QueryPathCssEventHandler

Code

protected function onlyChild() {
  $matches = $this
    ->candidateList();
  $found = new SplObjectStorage();
  foreach ($matches as $item) {
    $parent = $item->parentNode;
    $kids = array();
    foreach ($parent->childNodes as $kid) {
      if ($kid->nodeType == XML_ELEMENT_NODE) {
        $kids[] = $kid;
      }
    }
    if (count($kids) == 1 && $kids[0] === $item) {
      $found
        ->attach($kids[0]);
    }
  }
  $this->matches = $found;
}