public function prepend($xpath, $prefix)
    {
        $expressions = array();

        // If the xpath prefix contains a union we need to wrap it in parentheses.
        if (preg_match(self::UNION_PATTERN, $prefix)) {
            $prefix = '('.$prefix.')';
        }

        // Split any unions into individual expressions.
        foreach ($this->splitUnionParts($xpath) as $expression) {
            $expression = trim($expression);
            $parenthesis = '';

            // If the union is inside some braces, we need to preserve the opening braces and apply
            // the prefix only inside it.
            if (preg_match('/^[\(\s*]+/', $expression, $matches)) {
                $parenthesis = $matches[0];
                $expression = substr($expression, strlen($parenthesis));
            }

            // add prefix before element selector
            if (0 === strpos($expression, '/')) {
                $expression = $prefix.$expression;
            } else {
                $expression = $prefix.'/'.$expression;
            }
            $expressions[] = $parenthesis.$expression;
        }

        return implode(' | ', $expressions);
    }
public function prepend($xpath, $prefix)
    {
        $expressions = array();

        // If the xpath prefix contains a union we need to wrap it in parentheses.
        if (preg_match(self::UNION_PATTERN, $prefix)) {
            $prefix = '('.$prefix.')';
        }

        // Split any unions into individual expressions.
        foreach ($this->splitUnionParts($xpath) as $expression) {
            $expression = trim($expression);
            $parenthesis = '';

            // If the union is inside some braces, we need to preserve the opening braces and apply
            // the prefix only inside it.
            if (preg_match('/^[\(\s*]+/', $expression, $matches)) {
                $parenthesis = $matches[0];
                $expression = substr($expression, strlen($parenthesis));
            }

            // add prefix before element selector
            if (0 === strpos($expression, '/')) {
                $expression = $prefix.$expression;
            } else {
                $expression = $prefix.'/'.$expression;
            }
            $expressions[] = $parenthesis.$expression;
        }

        return implode(' | ', $expressions);
    }
public function prepend ( $ xpath , $ prefix ) { $ expressions = array ( ) ; // If the xpath prefix contains a union we need to wrap it in parentheses. if ( preg_match ( self :: UNION_PATTERN , $ prefix ) ) { $ prefix = '(' . $ prefix . ')' ; } // Split any unions into individual expressions. foreach ( $ this -> splitUnionParts ( $ xpath ) as $ expression ) { $ expression = trim ( $ expression ) ; $ parenthesis = '' ; // If the union is inside some braces, we need to preserve the opening braces and apply // the prefix only inside it. if ( preg_match ( '/^[\(\s*]+/' , $ expression , $ matches ) ) { $ parenthesis = $ matches [ 0 ] ; $ expression = substr ( $ expression , strlen ( $ parenthesis ) ) ; } // add prefix before element selector if ( 0 === strpos ( $ expression , '/' ) ) { $ expression = $ prefix . $ expression ; } else { $ expression = $ prefix . '/' . $ expression ; } $ expressions [ ] = $ parenthesis . $ expression ; } return implode ( ' | ' , $ expressions ) ; }
Prepends the XPath prefix to the given XPath.

The returned XPath will match elements matching the XPath inside an element
matching the prefix.

@param string $xpath
@param string $prefix

@return string
Prepends the XPath prefix to the given XPath .