Re: [xsl] Grouping duplicate elements under one element

Subject: Re: [xsl] Grouping duplicate elements under one element
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Wed, 22 May 2002 00:37:44 +0200
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



Current Thread