
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="/">
		<File>

			<!-- get all the unique due dates and descriptions -->
			<xsl:variable name="unique-batches" select="/EFTOutgoingFile/EFTRecord"/>

			<xsl:for-each select="$unique-batches">
				<xsl:if test="generate-id(.) = generate-id($unique-batches[dueDate=current()/dueDate and description=current()/description])">

					<Batch>
						<!-- Gets the actual repetition -->
						<xsl:variable name="counter" select="position()"/>

						<BatchHeader>
							<descriptiveStatement>
								<xsl:value-of select="description"/>
							</descriptiveStatement>
							<dueDate>
								<xsl:value-of select="dueDate"/>
							</dueDate>
						</BatchHeader>

						<xsl:variable name="eftRecords" select="$unique-batches[dueDate=current()/dueDate and description=current()/description]"/>

						<xsl:for-each select="$eftRecords">
							<DetailRecord>
								<amount>
									<xsl:value-of select="amount"/>
								</amount>
							</DetailRecord>
						</xsl:for-each>

						<BatchTrailer>
							<batchEntryCount>
								<xsl:value-of select="count($eftRecords)"/>
							</batchEntryCount>
							<entryDollarTotal>
								<xsl:value-of select="sum($eftRecords/amount)*100"/>
							</entryDollarTotal>
						</BatchTrailer>
					</Batch>
				</xsl:if>
			</xsl:for-each>

			<FileTrailer>
				<batchCount>
					<!-- Counter shows now the last repetition -->
					<xsl:value-of select="$counter"/>
				</batchCount>
				<detailCount>
					<xsl:value-of select="count(EFTOutgoingFile/EFTRecord)"/>
				</detailCount>
			</FileTrailer>
		</File>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="input.xml" htmlbaseurl="" outputurl="..\..\..\..\temp\testj.xml" processortype="custom" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="java Xi30Xslt %1 %2 %3" additionalpath="" additionalclasspath="${classpath};C:\Program Files\Stylus Studio 2007 XML Enterprise Suite\bin\xi30xslt.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SwaTools\SwaTools.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeFunctionsXI.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeXICommonCollection.jar" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->