since using the echo tags like that wont work you can make your own variable tagging system, for example, {:variable:} will represent $variable or {:name:} will represent $name we can use preg_replace to switch those templates into the actual variable data.
here is a little code snippet you can work with and see if you can get it working with your code:
$name = "drew";
$text = "hey there {:name:}, how are you?";
$newtext = preg_replace("/{:(\w+):}/e", "$\\1", $text);
echo $newtext;
basically, you will grab your xml doc with the variable tags in it, make sure the replacements exist before you run the preg_match code, and then apply your transformation after preg and it should be how you want. let me know if you have any troubles.