Why bother with the intermediary step of the assigned variable? I’d recommend reviewing the notes on assign global variables, specifically:
Variable assignment and replacement occurs instantly when the template is loaded and may not be affected by the result of another tag’s output.
Essentially the assigned variable is a simple find and replace.