<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="sh" match="SalesHeader" use="concat(SalesDate,Location,RevenueCentre)"/>
<xsl:key name="st" match="SalesTransaction" use="concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)"/>
<xsl:template match="/MainHeader/OrganisationHeader">
<MainHeader xmlns="">
<OrganisationHeader>
<xsl:for-each select="SalesHeader[generate-id(.)=generate-id(key('sh',concat(SalesDate,Location,RevenueCentre)))]">
<SalesHeader>
<xsl:copy-of select="SalesDate"/>
<xsl:copy-of select="Location"/>
<xsl:copy-of select="RevenueCentre"/>
<xsl:copy-of select="ActionIfDataExists"/>
<xsl:variable name="cur-header" select="concat(SalesDate,Location,RevenueCentre)"/>
<xsl:for-each select="key('sh',$cur-header)/SalesTransaction[generate-id(.)=generate-id(key('st',concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)))]">
<SalesTransaction>
<xsl:variable name="cur-trans" select="concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)"/>
<xsl:copy-of select="PLU"/>
<xsl:copy-of select="Description"/>
<Quantity><xsl:value-of select="sum(key('st',$cur-trans)/Quantity)"/></Quantity>
<VAT><xsl:value-of select="format-number(sum(key('st',$cur-trans)/VAT),'#0.00')"/></VAT>
<TotalGrossSales><xsl:value-of select="format-number(sum(key('st',$cur-trans)/TotalGrossSales),'#0.00')"/></TotalGrossSales>
<xsl:copy-of select="NetSalesPrice"/>
<xsl:copy-of select="GrossSalesPrice"/>
<TotalNetSales><xsl:value-of select="sum(key('st',$cur-trans)/TotalNetSales)"/></TotalNetSales>
<xsl:copy-of select="CategoryCode"/>
<xsl:copy-of select="SaleType"/>
</SalesTransaction>
</xsl:for-each>
</SalesHeader>
</xsl:for-each>
</OrganisationHeader>
</MainHeader>
</xsl:template>
</xsl:stylesheet>
|