This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Grouping duplicate elements under one element
Uslu, Cihan Y (MED) wrote:
> Hi,
> I have the following XML fragment, and I want to group duplicate course
> elements under one course element. WHat is the best way of doing it?
> Cihan
>
It's again the old trusty spell named Muenchean grouping, just
invoked three times in the last few hours.
<xsl:key name="course" match="course" use="LOCAL_CRSE_CD"/>
<xsl:template match="courses">
<courses>
<xsl:for-each select="course[generate-id()=
generate-id(key('course',LOCAL_CRSE_CD)[1])]">
<course>
<xsl:copy-of select="LOCAL_CRSE_CD"/>
<xsl:for-each select="key('course',LOCAL_CRSE_CD)">
<xsl:copy-of select="*[not(self::LOCAL_CRSE_CD)]"/>
</xsl:for-each>
</course>
</xsl:for-each>
</courses>
</xsl:template>
Beware, untested.
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list