<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="doc">
  <xsl:copy>
    <xsl:copy-of select="@*"/>

<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>

  </xsl:copy>
</xsl:template>

</xsl:stylesheet>