public static function transform(string $path)
    {
        if (isset(self::$xpath_cache[$path])) {
            return self::$xpath_cache[$path];
        }

        $tmp_path = self::replaceCharInsideEnclosure($path, ',');
        if (strpos($tmp_path, ',') !== false) {
            $paths = explode(',', $tmp_path);
            $expressions = array();

            foreach ($paths as $single_path) {
                $single_path = str_replace("\0", ',', $single_path); // restore commas
                $xpath = self::transform(trim($single_path));
                $expressions[] = $xpath;
            }

            return implode('|', $expressions);
        }

        // replace spaces inside (), to correctly create tokens (restore later)

        $path_escaped = self::replaceCharInsideEnclosure($path, ' ');

        // create tokens and analyze to create segments

        $tokens = preg_split('/\s+/', $path_escaped);

        $segments = array();

        foreach ($tokens as $key => $token) {
            $token = str_replace("\0", ' ', $token); // restore spaces

            if ($segment = self::getSegmentFromToken($token, $key, $tokens)) {
                $segments[] = $segment;
            }
        }

        // use segments to create array with transformed tokens

        $new_path_tokens = self::transformCssSegments($segments);

        // result tokens to xpath

        $xpath_result = implode('', $new_path_tokens);

        self::$xpath_cache[$path] = $xpath_result;

        return $xpath_result;
    }