I didn't show the structure of your input XML, but my guess is that you can't easily perform this transform using an XSL templatelet i.e. you'd need to specify a full stylesheet with 2 templates... 1st one to pick up the context node and the 2nd to iterate the "rows" (called from the 1st).
I should also say that you could do this by applying a model driven transform i.e. populate an object model with the row data from the XML and then apply a template (e.g. FreeMarker, XSLT, StringTemplate)