Perhaps if you showed us an example of the input, and what you are trying to get out. The above code is half xslt/xpath and half verbose pseudo code and I can't really understand what you are trying to do.
We don't know what $toBeReplacedString is, nor $replacementString.
|