RE: [xsl] Grouping - starting with certain element and ending before certain elements

Subject: RE: [xsl] Grouping - starting with certain element and ending before certain elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 5 Oct 2005 13:34:35 +0100
> So I want to keep the order of all elements but group each <IDM>
> element followed by a number of siblings up to another <IDM>, a <LV2>
> or a <LV3> element and wrap this sequence in a <phrase> section. 


The XSLT 2.0 solution that comes to mind is:

<xsl:for-each-group group-starting-with="IDM|LV2|LV3">
  <xsl:choose>
  <xsl:when test="self::IDM">
    <phrase>
      <xsl:copy-of select="current-group()"/>
    </phrase>
  </xsl:when>
  <xsl:otherwise>
    <xsl:copy-of select="current-group()"/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:for-each-group>

Michael Kay
http://www.saxonica.com/

Current Thread