<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!-- Created: July 2011 -->
	<!-- Version: 7.0 -->
	<!-- Last Modified: August 2011 -->

	<xsl:include href="pbdmi-common-7.xsl"/>	
	<xsl:output indent="yes" method="xml"/>

	<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"/>

			<xsl:variable name="tablename" select="concat(substring(FileLayoutType, 1, 3), 'NDLONGTERM')"/>

			<!--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 SEANDLONGTERM/LEANDLONGTERM child elements-->
					<xsl:for-each select="NorDLongTerm">

						<xsl:element name="TABLETYPE">
							<xsl:attribute name="TYPEABBRV">
								<xsl:value-of select="$tablename"/>
							</xsl:attribute>

							<xsl:attribute name="TOTALINDICATOR">
								<xsl:value-of select="TotalIndicator"/>
							</xsl:attribute>

							<!--<CATEGORY TYPE="ACADSUBASSESS" VALUE="11"/>-->
							<xsl:apply-templates select="AcademicSubjectAssess">
								<xsl:with-param name="value">
									<xsl:value-of select="AcademicSubjectAssess"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<CATEGORY TYPE="NEGDELPROGTYP" VALUE="NEGLECT"/>-->
							<xsl:apply-templates select="NorDProgramSubpart1">
								<xsl:with-param name="value">
									<xsl:value-of select="NorDProgramSubpart1"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<CATEGORY TYPE="NEGDELPROGTYP2" VALUE="ATRISK"/>-->
							<xsl:apply-templates select="NorDProgramSubpart2">
								<xsl:with-param name="value">
									<xsl:value-of select="NorDProgramSubpart2"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<CATEGORY TYPE="PREPOSTTEST" VALUE="PRE-POST"/>-->
							<xsl:apply-templates select="PrePostTest">
								<xsl:with-param name="value">
									<xsl:value-of select="PrePostTest"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<CATEGORY TYPE="PRETESTRESULT" VALUE="GRDLVL"/>-->
							<xsl:apply-templates select="PreTestResult">
								<xsl:with-param name="value">
									<xsl:value-of select="PreTestResult"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<AMOUNT>500</AMOUNT>-->
							<xsl:apply-templates select="Amount">
								<xsl:with-param name="value">
									<xsl:value-of select="Amount"/>
								</xsl:with-param>
							</xsl:apply-templates>

							<!--<EXPLANATION></EXPLANATION>-->
							<xsl:apply-templates select="Explanation">
								<xsl:with-param name="value">
									<xsl:value-of select="Explanation"/>
								</xsl:with-param>
							</xsl:apply-templates>
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>