This issue is an interesting one in that there are more then one problem here that will cause high memory and even what looks to be a problem that will affect the performance of this snippet as well.
So the two main problems are that we are using XSLT.Load inside of a loop which means that we are going to create a new dynamic assembly for each loop iteration. The other problem is string concatenation. Instead of using the + to build our string in each loop, we should use StringBuilder to save on memory.
These two issues are documented here:
PRB- Cannot unload assemblies that you create and load by using script How to improve string concatenation performance in Visual C# ...
Go to the complete details ...