Very elegant solution, but I have just 2 concerns.
One is that the definition of the string is varchar(8000), but the master table has values only up to 2047.
The other I'm not sure if is really a problem, but with the lack of an order by you could get results out of order. Then again, maybe the onus of including an order by should be on the code calling this function.
Anyway, I liked the solution. Thanks for posting.