It appears that the problem is something to do with the mysterious "dp:set-variable" element. Which we don't know anything about.
Neither do we know anything about the problem. "Not splitting" isn't helpful, as that leaves an entire universe of things which might be happening instead.
If you are saying that the substring() function doesn't work, then you should post the value of the $BackendURL variable, the result of the substring() function, and what you thought the result should be.