It sounds like XSLT 2.0 isn't supported in Biztalk, so this answer is in regard to XSLT 1.0.
Assuming your XML input file is well-formed, i.e. wrapped in a single top-level element...
The standard approach for this kind of grouping problem is Meunchian grouping. See for example https://stackoverflow.com/a/1929273/423105 or https://stackoverflow.com/a/2334224/423105. If you have trouble applying those answers, leave a comment with specific questions.