<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
   <xsl:output indent="yes"/>
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="document">
      <xsl:copy>
         <xsl:apply-templates select="@*|row[1]"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="row">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
      <xsl:apply-templates select="following-sibling::*[1]"/>
   </xsl:template>
   <xsl:template match="row[type = 'RELEASE']">
      <xsl:apply-templates mode="eat-up" select="following-sibling::*[1]">
	  	<xsl:with-param name="title" select="title"/>
			<xsl:with-param name="artist" select="artist"/>
			<xsl:with-param name="releasename" select="releasename"/>
			<xsl:with-param name="catalognumber" select="catalognumber"/>
			<xsl:with-param name="upc" select="upc"/>
			<xsl:with-param name="copyright" select="copyright"/>
			<xsl:with-param name="composer" select="composer"/>
			<xsl:with-param name="lyricist" select="lyricist"/>
			<xsl:with-param name="medley" select="medley"/>
			<xsl:with-param name="isrc" select="isrc"/>
			<xsl:with-param name="charttitle" select="charttitle"/>
         <xsl:with-param name="price" select="price"/>
		 <xsl:with-param name="fee" select="fee"/>
		 <xsl:with-param name="amount" select="amount"/>
		 <xsl:with-param name="royalty" select="royalty"/>
		 <xsl:with-param name="mechanicals" select="mechanicals"/>
		 <xsl:with-param name="expense" select="expense"/>
         <xsl:with-param name="row"     select="."/>
      </xsl:apply-templates>
   </xsl:template>
   <xsl:template match="row" mode="eat-up">
   	<xsl:param name="title"/>
	<xsl:param name="artist"/>
	<xsl:param name="releasename"/>
	<xsl:param name="catalognumber"/>
	<xsl:param name="upc"/>
	<xsl:param name="copyright"/>
	<xsl:param name="composer"/>
	<xsl:param name="lyricist"/>
	<xsl:param name="medley"/>
	<xsl:param name="isrc"/>
	<xsl:param name="charttitle"/>
      <xsl:param name="price"/>
	  <xsl:param name="fee"/>
	  <xsl:param name="amount"/>
	  <xsl:param name="royalty"/>
	  <xsl:param name="mechanicals"/>
	  <xsl:param name="expense"/>
      <xsl:param name="row"/>
      <xsl:variable name="prev-id" select="preceding-sibling::row[1]/releaseid"/>
      <xsl:choose>
         <xsl:when test="order = $row/order and ( not($prev-id) or releaseid = $prev-id )">
            <xsl:apply-templates mode="eat-up" select="following-sibling::*[1]">
               <xsl:with-param name="title" select="title"/>
			   <xsl:with-param name="artist" select="artist"/>
				<xsl:with-param name="releasename" select="releasename"/>
				<xsl:with-param name="catalognumber" select="catalognumber"/>
				<xsl:with-param name="upc" select="upc"/>
				<xsl:with-param name="copyright" select="copyright"/>
				<xsl:with-param name="composer" select="composer"/>
				<xsl:with-param name="lyricist" select="lyricist"/>
				<xsl:with-param name="medley" select="medley"/>
				<xsl:with-param name="isrc" select="isrc"/>
				<xsl:with-param name="charttitle" select="charttitle"/>
			   <xsl:with-param name="price" select="$price + price"/>
			   <xsl:with-param name="fee" select="$fee + fee"/>
			   <xsl:with-param name="amount" select="$amount + amount"/>
			   <xsl:with-param name="royalty" select="$royalty + royalty"/>
			   <xsl:with-param name="mechanicals" select="$mechanicals + mechanicals"/>
			   <xsl:with-param name="expense" select="$expense + expense"/>
               <xsl:with-param name="row"     select="$row"/>
            </xsl:apply-templates>
         </xsl:when>
         <xsl:otherwise>
            <xsl:element name="{ name($row) }">
               <xsl:apply-templates select="$row/@*|$row/*[not(self::title | self::artist | self::releasename | self::catalognumber | self::upc | self::copyright | self::composer | self::lyricist | self::medley | self::isrc | self::charttitle | self::price | self::fee | self::amount | self::royalty | self::mechanicals | self::expense)]|$prev-id"/>
               <title>
                  <xsl:value-of select="$title"/>
               </title>
			   <artist>
                  <xsl:value-of select="$artist"/>
               </artist>
			   <releasename>
                  <xsl:value-of select="$releasename"/>
               </releasename>
			   <catalognumber>
                  <xsl:value-of select="$catalognumber"/>
               </catalognumber>
			   <upc>
                  <xsl:value-of select="$upc"/>
               </upc>
			   <copyright>
                  <xsl:value-of select="$copyright"/>
               </copyright>
			   <lyricist>
                  <xsl:value-of select="$lyricist"/>
               </lyricist>
			    <medley>
                  <xsl:value-of select="$medley"/>
               </medley>
			   <isrc>
                  <xsl:value-of select="$isrc"/>
               </isrc>
			   <charttitle>
                  <xsl:value-of select="$charttitle"/>
               </charttitle>
			   <price>
                  <xsl:value-of select="$price"/>
               </price>
			   <fee>
                  <xsl:value-of select="$fee"/>
               </fee>
			   <amount>
                  <xsl:value-of select="$amount"/>
               </amount>
			   <royalty>
                  <xsl:value-of select="$royalty"/>
               </royalty>
			   <mechanicals>
			   		<xsl:value-of select="$mechanicals"/>
			   </mechanicals>
			   <expense>
			   		<xsl:value-of select="$expense"/>
					</expense>
            </xsl:element>
            <xsl:apply-templates select="."/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet><!-- Stylesheet edited using Stylus Studio - (c) 2004-2006. Progress Software Corporation. All rights reserved. -->