Search code examples
xpath

Remove or replace some text from XPath string


Is it possible to remove or replace text on XPath string?

Using XPath I get url with http://www and I want to remove http://www, so the same XPath query would return me only a link without http://www. I can't find anything about removing or replacing Xpath string.

Is it possible? If so, how to do this?


Solution

  • Have you tried substring-after?

    substring-after('http://www.stackoverflow.com', 'http://www.')
    

    Example:

    <demo>http://www.stackoverflow.com</demo>
    

    XPath:

    //demo/substring-after(., 'http://www.')
    

    Yields:

    stackoverflow.com
    

    Check online demo here.