<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="RowByType" match="row" use="concat(generate-id(preceding-sibling::row[1][type='RELEASE'] ), releaseid)"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:for-each select="row[type != 'RELEASE'][count(.|key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))[1] )= 1]">
<xsl:copy>
<xsl:copy-of select="id"/>
<xsl:copy-of select="site"/>
<xsl:copy-of select="order"/>
<xsl:copy-of select="date"/>
<xsl:copy-of select="userid"/>
<type>
<xsl:choose>
<xsl:when test="preceding-sibling::row[1][type='RELEASE']">
<xsl:value-of select="'RELEASE'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'TRACK'"/>
</xsl:otherwise>
</xsl:choose>
</type>
<xsl:copy-of select="trackid"/>
<xsl:copy-of select="title"/>
<xsl:copy-of select="mixtitle"/>
<xsl:copy-of select="artist"/>
<xsl:copy-of select="remixer"/>
<xsl:copy-of select="releaseid"/>
<xsl:copy-of select="releasename"/>
<xsl:copy-of select="catalognumber"/>
<xsl:copy-of select="upc"/>
<xsl:copy-of select="genre"/>
<xsl:copy-of select="copyright"/>
<xsl:copy-of select="composer"/>
<xsl:copy-of select="lyricyst"/>
<xsl:copy-of select="medley"/>
<xsl:copy-of select="isrc"/>
<xsl:copy-of select="chartid"/>
<xsl:copy-of select="charttitle"/>
<xsl:copy-of select="labelid"/>
<xsl:copy-of select="labelname"/>
<xsl:copy-of select="distributorid"/>
<xsl:copy-of select="distributorname"/>
<xsl:variable name="AddSum">
<xsl:value-of select="preceding-sibling::row[type='RELEASE'][1]/following-sibling::row/releaseid | /order"/>
</xsl:variable>
<xsl:if test="preceding-sibling::row[1][type='RELEASE']">
<price>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/price) + preceding-sibling::row[type='RELEASE'][1]/price"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="price"/>
</xsl:otherwise>
</xsl:choose>
</price>
<fee>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/fee) + preceding-sibling::row[type='RELEASE'][1]/fee"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="fee"/>
</xsl:otherwise>
</xsl:choose>
</fee>
<amount>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/amount) + preceding-sibling::row[type='RELEASE'][1]/amount"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="amount"/>
</xsl:otherwise>
</xsl:choose>
</amount>
<royalty>
<xsl:choose>
<xsl:when test="releaseid | order= $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/royalty) + preceding-sibling::row[type='RELEASE'][1]/royalty"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="royalty"/>
</xsl:otherwise>
</xsl:choose>
</royalty>
<mechanicals>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/mechanicals) + preceding-sibling::row[type='RELEASE'][1]/mechanicals"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="mechanicals"/>
</xsl:otherwise>
</xsl:choose>
</mechanicals>
<taxes>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/taxes) + preceding-sibling::row[type='RELEASE'][1]/taxes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="taxes"/>
</xsl:otherwise>
</xsl:choose>
</taxes>
<expense>
<xsl:choose>
<xsl:when test="releaseid = $AddSum">
<xsl:value-of select="sum(key('RowByType', concat(generate-id(preceding-sibling::row[type='RELEASE'][1]), releaseid))/expense) + preceding-sibling::row[type='RELEASE'][1]/expense"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="expense"/>
</xsl:otherwise>
</xsl:choose>
</expense>
</xsl:if>
<xsl:if test="preceding-sibling::row[1][type !='RELEASE']">
<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>
<taxes>
<xsl:value-of select="taxes"/>
</taxes>
<expense>
<xsl:value-of select="expense"/>
</expense>
</xsl:if>
<xsl:copy-of select="year"/>
<xsl:copy-of select="term"/>
<xsl:copy-of select="state"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="AddRoyaltyv2" userelativepaths="yes" externalpreview="no" url="..\..\Test 3_25\Exported 3_25.xml" htmlbaseurl="" outputurl="" processortype="saxon8" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="" ><advancedProp name="sInitialMode" value=""/><advancedProp name="bSchemaAware" value="false"/><advancedProp name="bXsltOneIsOkay" value="true"/><advancedProp name="bXml11" value="false"/><advancedProp name="iValidation" value="0"/><advancedProp name="bExtensions" value="true"/><advancedProp name="iWhitespace" value="0"/><advancedProp name="sInitialTemplate" value=""/><advancedProp name="bTinyTree" value="true"/><advancedProp name="bUseDTD" value="false"/><advancedProp name="bWarnings" value="true"/></scenario></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Test 3_25\Exported 3_25.xml" destSchemaRoot="document" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="Test 3_25\Exported 3_25.xml" srcSchemaRoot="document" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"></template><template match="/*"></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->