This is a procedure i wrote some years ago now. want to do the same for xml csv , then seperate one for pdf and rtf templates if you want full details of project let me know