Grouping By Ending Value (Code)

<xsl:for-each-group select="*" 
     group-ending-with="page[not(@continued
                                 ='yes')]">
  <pageset>
    <xsl:for-each select="current-group()">
      <page><xsl:value-of select="."/></page>
    </xsl:for-each> 
  </pageset>
</xsl:for-each-group>