private static function transformCssSegments(array $segments)
    {
        $new_path_tokens = array();

        foreach ($segments as $num => $segment) {
            if ($segment->relation_token === '>') {
                $new_path_tokens[] = '/';
            } elseif ($segment->relation_token === '~' || $segment->relation_token === '+') {
                $new_path_tokens[] = '/following-sibling::';
            } else {
                $new_path_tokens[] = '//';
            }

            if ($segment->selector !== '') {
                $new_path_tokens[] = $segment->selector; // specific tagname
            } else {
                $new_path_tokens[] = '*'; // any tagname
            }

            if ($segment->relation_token === '+' && isset($segments[$num-1])) { // add adjacent filter
                $prev_selector = implode('', self::transformCssSegments([$segments[$num-1]]));
                $new_path_tokens[] = '[preceding-sibling::*[1][self::'.ltrim($prev_selector, '/').']]';
            }

            foreach (array_reverse($segment->attribute_filters) as $attr) {
                $new_path_tokens[] = self::transformAttrSelector($attr);
            }

            foreach (array_reverse($segment->pseudo_filters) as $attr) {
                $new_path_tokens[] = self::transformCssPseudoSelector($attr, $new_path_tokens);
            }
        }

        return $new_path_tokens;
    }
private static function transformCssSegments(array $segments)
    {
        $new_path_tokens = array();

        foreach ($segments as $num => $segment) {
            if ($segment->relation_token === '>') {
                $new_path_tokens[] = '/';
            } elseif ($segment->relation_token === '~' || $segment->relation_token === '+') {
                $new_path_tokens[] = '/following-sibling::';
            } else {
                $new_path_tokens[] = '//';
            }

            if ($segment->selector !== '') {
                $new_path_tokens[] = $segment->selector; // specific tagname
            } else {
                $new_path_tokens[] = '*'; // any tagname
            }

            if ($segment->relation_token === '+' && isset($segments[$num-1])) { // add adjacent filter
                $prev_selector = implode('', self::transformCssSegments([$segments[$num-1]]));
                $new_path_tokens[] = '[preceding-sibling::*[1][self::'.ltrim($prev_selector, '/').']]';
            }

            foreach (array_reverse($segment->attribute_filters) as $attr) {
                $new_path_tokens[] = self::transformAttrSelector($attr);
            }

            foreach (array_reverse($segment->pseudo_filters) as $attr) {
                $new_path_tokens[] = self::transformCssPseudoSelector($attr, $new_path_tokens);
            }
        }

        return $new_path_tokens;
    }
private static function transformCssSegments ( array $ segments ) { $ new_path_tokens = array ( ) ; foreach ( $ segments as $ num => $ segment ) { if ( $ segment -> relation_token === '>' ) { $ new_path_tokens [ ] = '/' ; } elseif ( $ segment -> relation_token === '~' || $ segment -> relation_token === '+' ) { $ new_path_tokens [ ] = '/following-sibling::' ; } else { $ new_path_tokens [ ] = '//' ; } if ( $ segment -> selector !== '' ) { $ new_path_tokens [ ] = $ segment -> selector ; // specific tagname } else { $ new_path_tokens [ ] = '*' ; // any tagname } if ( $ segment -> relation_token === '+' && isset ( $ segments [ $ num - 1 ] ) ) { // add adjacent filter $ prev_selector = implode ( '' , self :: transformCssSegments ( [ $ segments [ $ num - 1 ] ] ) ) ; $ new_path_tokens [ ] = '[preceding-sibling::*[1][self::' . ltrim ( $ prev_selector , '/' ) . ']]' ; } foreach ( array_reverse ( $ segment -> attribute_filters ) as $ attr ) { $ new_path_tokens [ ] = self :: transformAttrSelector ( $ attr ) ; } foreach ( array_reverse ( $ segment -> pseudo_filters ) as $ attr ) { $ new_path_tokens [ ] = self :: transformCssPseudoSelector ( $ attr , $ new_path_tokens ) ; } } return $ new_path_tokens ; }
Transform css segments to xpath

@param object[] $segments

@return string[] $new_path_tokens
Transform css segments to xpath