You are here

public function QueryPath::prev in QueryPath 6

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

File

QueryPath/QueryPath.php, line 1462

Class

QueryPath

Code

public function prev($selector = NULL) {
  $found = new SplObjectStorage();
  foreach ($this->matches as $m) {
    while (isset($m->previousSibling)) {
      $m = $m->previousSibling;
      if ($m->nodeType === XML_ELEMENT_NODE) {
        if (!empty($selector)) {
          if (qp($m, NULL, $this->options)
            ->is($selector)) {
            $found
              ->attach($m);
            break;
          }
        }
        else {
          $found
            ->attach($m);
          break;
        }
      }
    }
  }
  $this
    ->setMatches($found);
  return $this;
}