<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!-- Version: 7.0 -->

	<xsl:include href="pbdmi-common-7.xsl"/>

	<xsl:output indent="yes"/>

	<xsl:template match="*">

		<!-- HEADER -->
		<xsl:element name="FILETRANSMISSION">
			<xsl:attribute name="FILELAYOUTTYPE">
				<xsl:value-of select="FileLayoutType"/>
			</xsl:attribute>
			<xsl:attribute name="FILEID">
				<xsl:value-of select="FileId"/>
			</xsl:attribute>
			<xsl:attribute name="SCHOOLYEAR">
				<xsl:value-of select="SchoolYear"/>
			</xsl:attribute>

			<xsl:variable name="fips" select="FipsStateCode"/>

			<!--loop through agency elements-->
			<xsl:for-each select="Agency">
				<!--<AGENCY FIPSSTATECODE="01" STATEAGENCYIDNUMBER="01" STATELEAIDNUMBER="001000-0000001">-->
				<xsl:element name="AGENCY">
					<xsl:attribute name="FIPSSTATECODE">
						<xsl:value-of select="$fips"/>
					</xsl:attribute>
					<xsl:attribute name="STATEAGENCYIDNUMBER">
						<xsl:value-of select="StateAgencyIdNumber"/>
					</xsl:attribute>

					<xsl:if test="StateLeaIdNumber">
						<xsl:attribute name="STATELEAIDNUMBER">
							<xsl:value-of select="StateLeaIdNumber"/>
						</xsl:attribute>
					</xsl:if>

					<!--loop through FEDERALPROGRAM child elements-->
					<xsl:for-each select="FederalProgram">
						<!--<FEDERALPROGRAM CFDAABBRV="84.331" ALLOCATEDFUNDS="123456789" >-->
						<xsl:element name="FEDERALPROGRAM">
							<xsl:attribute name="CFDAABBRV">
								<xsl:value-of select="FederalProgramCode"/>
							</xsl:attribute>

							<xsl:if test="FullDollarAmount">
								<xsl:attribute name="ALLOCATEDFUNDS">
									<xsl:value-of select="FullDollarAmount"/>
								</xsl:attribute>
							</xsl:if>

							<xsl:if test="FundingAllocationType">
								<xsl:attribute name="FUNDALLOCTYPE">
									<xsl:value-of select="FundingAllocationType"/>
								</xsl:attribute>
							</xsl:if>
						
							<!--<EXPLANATION></EXPLANATION>-->
							<xsl:if test="Explanation">
								<xsl:attribute name="EXPLANATION">
									<xsl:value-of select="Explanation"/>
								</xsl:attribute>
							</xsl:if>
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>