It's difficult to respond to this kind of post because you don't say where you are having difficulties. If I know where your problems are then I can try and help you over them, but I'm not going to simply code the whole thing for you from scratch.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference