I think this is one of those cases where for-each-group doesn't give you
the grouping you want out of the box, so you need to walk the walk and
collect up the items by hand...
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="patient">
<patient>
<xsl:apply-templates select="lab[1]"/>
</patient>
</xsl:template>
<xsl:template match="lab">
<xsl:param name="l" select="()"/>
<xsl:choose>
<xsl:when test="@type=$l/@type">
<group>
<xsl:copy-of select="$l"/>
</group>
<xsl:apply-templates select="(following-sibling::lab,@type)[1]">
<xsl:with-param name="l" select="."/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="(following-sibling::lab,@type)[1]">
<xsl:with-param name="l" select="$l,."/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@type">
<xsl:param name="l" select="()"/>
<group>
<xsl:copy-of select="$l"/>
</group>
</xsl:template>
</xsl:stylesheet>
$ saxon8 grp4.xml grp4.xsl
<?xml version="1.0" encoding="UTF-8"?>
<patient>
<group>
<lab type="1"/>
<lab type="2"/>
<lab type="3"/>
</group>
<group>
<lab type="1"/>
<lab type="3"/>
</group>
<group>
<lab type="1"/>
</group>
<group>
<lab type="1"/>
<lab type="2"/>
<lab type="3"/>
</group>
<group>
<lab type="3"/>
<lab type="1"/>
</group>
</patient>
________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--