<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="hourly" match="Detail/Entity/Quantity" use="concat(HourlyBeginTime, HourlyEndTime)"/> 
	<xsl:template match="/EDI">
		<xsl:for-each-group select="Detail/Entity" group-by=".">
			<xsl:variable name="entity" select="current-grouping-key()"/>
			<xsl:value-of select="concat(., ':&#10;')"/>
			<xsl:for-each-group select="../Quantity" group-by="concat(HourlyBeginTime, HourlyEndTime)">
				<xsl:for-each select="current-group()/HourlyQuantity">
					<xsl:value-of select="concat('     ', ., ' + &#10;')"/>
				</xsl:for-each>
				
				<xsl:value-of select="'---------------- &#10;'"/>
				<xsl:variable name="quantity" select="format-number(sum(current-group()/HourlyQuantity), '#')"/>
				<xsl:value-of select="concat('QTY: ', string($quantity), ' ', current-grouping-key() , '&#10;&#10;')"/>
			</xsl:for-each-group>
		</xsl:for-each-group>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="edi.xml" userelativepaths="yes" externalpreview="no" url="edi.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="bXsltOneIsOkay" value="true"/><advancedProp name="bSchemaAware" 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="bWarnings" value="true"/><advancedProp name="bUseDTD" value="false"/></scenario></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->