Please use a title that describes your problem. Everyone posting to this list needs help with XSL transformation, and most people would like the answer yesterday (though most have the good sense not to say so, since it tends to discourage people from answering - that's because people who are in too much of a hurry often come back immediately with supplementary questions rather than taking time to study the answers).
In fact your question is a standard grouping problem, and if you search for "XSLT Grouping" in the index of your favourite XSLT textbook or on the web then you will find good explanations of how to solve such problems in XSLT 1.0 or XSLT 2.0 - the 2.0 solutions are much easier.
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference