You are here

public function QueryPath::siblings in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::siblings()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::siblings()

File

QueryPath/QueryPath.php, line 1052

Class

QueryPath

Code

public function siblings($selector = NULL) {
  $found = new SplObjectStorage();
  foreach ($this->matches as $m) {
    $parent = $m->parentNode;
    foreach ($parent->childNodes as $n) {
      if ($n->nodeType == XML_ELEMENT_NODE && $n !== $m) {
        $found
          ->attach($n);
      }
    }
  }
  if (empty($selector)) {
    $this
      ->setMatches($found);
  }
  else {
    $this->matches = $found;
    $this
      ->filter($selector);
  }
  return $this;
}