public function xpath(string $xpath_query)
    {
        $result = $this->createChildInstance();

        if (isset($this->document)) {
            $result->xpath_query = $xpath_query;

            if (isset($this->root_instance) || isset($this->xpath_query)) {  // all nodes as context
                foreach ($this->nodes as $node) {
                    if ($result_node_list = $this->xpathQuery('.'.$xpath_query, $node)) {
                        $result->loadDomNodeList($result_node_list);
                    }
                }
            } else { // whole document
                if ($result_node_list = $this->xpathQuery($xpath_query)) {
                    $result->loadDomNodeList($result_node_list);
                }
            }
        }

        return $result;
    }
public function xpath(string $xpath_query)
    {
        $result = $this->createChildInstance();

        if (isset($this->document)) {
            $result->xpath_query = $xpath_query;

            if (isset($this->root_instance) || isset($this->xpath_query)) {  // all nodes as context
                foreach ($this->nodes as $node) {
                    if ($result_node_list = $this->xpathQuery('.'.$xpath_query, $node)) {
                        $result->loadDomNodeList($result_node_list);
                    }
                }
            } else { // whole document
                if ($result_node_list = $this->xpathQuery($xpath_query)) {
                    $result->loadDomNodeList($result_node_list);
                }
            }
        }

        return $result;
    }
public function xpath ( string $ xpath_query ) { $ result = $ this -> createChildInstance ( ) ; if ( isset ( $ this -> document ) ) { $ result -> xpath_query = $ xpath_query ; if ( isset ( $ this -> root_instance ) || isset ( $ this -> xpath_query ) ) { // all nodes as context foreach ( $ this -> nodes as $ node ) { if ( $ result_node_list = $ this -> xpathQuery ( '.' . $ xpath_query , $ node ) ) { $ result -> loadDomNodeList ( $ result_node_list ) ; } } } else { // whole document if ( $ result_node_list = $ this -> xpathQuery ( $ xpath_query ) ) { $ result -> loadDomNodeList ( $ result_node_list ) ; } } } return $ result ; }
Use xpath and return new DomQuery with resulting nodes

@param string $xpath_query

@return static
Use xpath and return new DomQuery with resulting nodes