Grouping By Adjacent Key Values (Code)

<xsl:for-each-group select="node()" 
     group-adjacent="self::ul or self::ol">
  <xsl:choose>
    <xsl:when test="current-grouping-key()">
      <xsl:copy-of select="current-group()"/>  
    </xsl:when>
    <xsl:otherwise>
      <p>
        <xsl:copy-of
             select="current-group()"/>
      </p>
    </xsl:otherwise>  
  </xsl:choose>
</xsl:for-each-group>