Dyluck Dyluck - 2 months ago 8
HTML Question

XPath to prepend string to each returned string?

I'm trying to work with XPath. I am using an XPath tool in which I do not have the ability to programmatically resolve this issue and hope there is simply an XPath syntax to deal with this.

I have an XPath like this:

//article/x:div[2]/x:div[1]/x:h1/x:a/@href


which of course lists out all the URLs of the matching elements.
What I do need to do is append the domain name to the front of each listed match as the returned url is relative.

I've tried
concat()
but it says syntax is wrong or it only gives me the first match. I need it to return each match with the appended domain name.

Answer

XPath 1.0

You're out of luck if you cannot further process the returned list of strings.

XPath 2.0

Append /concat('domain', .) to the end of your XPath to prepend 'domain' to each result.

Comments