It's a positional grouping problem, much easier in 2.0 using xsl:for-each-group group-starting-with. In 1.0 it's best tackled using sibling recursion and is much trickier, when I'm teaching this exercise usually takes a couple of hours and people get very confused by it.
The general approach is
(a) the template for the parent element does apply-templates to its first child,
(b) the template for the first child in a group does
<group>
<apply-templates select="following-sibling::*[1]"/>
</group>
<apply-templates select="following-sibling::close/following-sibling::*[1]"/>
(c) the template for the close element does nothing (to terminate the recursion)
(d) the template for every other child element outputs itself then applies templates to its immediately following sibling.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference