<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
	<HC_DATA>
		<xsl:for-each select="HC_DATA/HEADER">
			<HEADER><xsl:copy-of select="TRANS_CODE | RPT_YEAR | RPT_QTR | DATA_TYPE |  SUBMISSION_TYPE | PROCESS_DATE | AHCA_NUM | ORG_NAME"/>
				<CONTACT_PERSON>
				<xsl:copy-of select="NAME | PHONE | EMAIL | STREET | CITY | STATE | ZIP"/>
				</CONTACT_PERSON>
			</HEADER>
		</xsl:for-each>
		<RECORDS>
			<xsl:for-each select="HC_DATA/RECORD">
				<RECORD id="{RECORD_ID}">
				<xsl:copy-of select="AHCA_NUM | PATIENT_SSN | PATIENT_RACE | PATIENT_BIRTHDATE | PATIENT_SEX | PATIENT_ZIP | ADMIT_TYPE | ADMIT_SOURCE | ADMIT_DATE | DISCH_DATE | DISCH_STATUS | PRINC_PAYER_CODE | PRINC_DIAG_CODE"/>
					<xsl:for-each select="OTHER_CODE">
						<OTHER_DIAG_CODE>
						<xsl:copy-of select="."/>
						<PRESENT_ON_ADMIT>
							<xsl:value-of select="translate(following-sibling::PRESENT_ON_ADMIT[1],'E',' ')"/>
						</PRESENT_ON_ADMIT>
						</OTHER_DIAG_CODE>
					</xsl:for-each>
					<xsl:choose>
					<xsl:when test="PRINC_PROC_CODE">
						<xsl:element name="PRIN_PROC_CODE">
						<xsl:element name="PROC_CODE">
						<xsl:value-of select="PRINC_PROC_CODE"/>
						</xsl:element>
						<xsl:element name="PROC_DATE">
						<xsl:value-of select="PRINC_PROC_DATE"/>
						</xsl:element>
						</xsl:element>
						</xsl:when>
						</xsl:choose>
					<xsl:for-each select="PROC_CODE">
						<OTHER_PROC_CODE>
						<xsl:copy-of select="."/>
						<xsl:copy-of select="following-sibling::PROC_DATE[1]"/>
						</OTHER_PROC_CODE>
					</xsl:for-each>
					<xsl:copy-of select="ATTENDING_PHYS_ID"/>
					<xsl:copy-of select="ATTENDING_PHYS_ID/following-sibling::*"/>
					<xsl:for-each select="EXTERNAL_CAUSE[following-sibling::PRESENT_ON_ADMIT[1]]">
					<xsl:value-of select="translate(following-sibling::PRESENT_ON_ADMIT[1],'E',' ')"/>
					</xsl:for-each>
					</RECORD>
			</xsl:for-each>
		</RECORDS>
		<TRAILER>
			<NUMBER_OF_RECORDS><xsl:variable name="mask" select="''"/>
			<xsl:variable name="r-count" select="count(HC_DATA/RECORD)"/>
			<xsl:variable name="padding" select="substring($mask, 1, (string-length($mask) - string-length($r-count)) )"/>
			<xsl:value-of select="concat($padding, $r-count)"/>
			</NUMBER_OF_RECORDS>
		</TRAILER>
	</HC_DATA>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="no" name="Beaches" userelativepaths="yes" externalpreview="no" url="XSLInput.xml" htmlbaseurl="" outputurl="Output.xml" processortype="internal" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/><scenario default="yes" name="Downtown IP" userelativepaths="yes" externalpreview="no" url="adapter:./Downtown IP 07.conv?ah882px.txt" htmlbaseurl="" outputurl="" processortype="internal" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Output.xml" destSchemaRoot="HC_DATA" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="XSLInput.xml" srcSchemaRoot="HC_DATA" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"><block path="HC_DATA/xsl:for&#x2D;each" x="247" y="72"/><block path="HC_DATA/RECORDS/xsl:for&#x2D;each" x="170" y="183"/><block path="HC_DATA/RECORDS/xsl:for&#x2D;each/RECORD/xsl:for&#x2D;each" x="207" y="89"/><block path="HC_DATA/RECORDS/xsl:for&#x2D;each/RECORD/xsl:for&#x2D;each[1]" x="167" y="89"/><block path="HC_DATA/TRAILER/NUMBER_OF_RECORDS/xsl:value&#x2D;of" x="287" y="89"/></template></MapperBlockPosition></MapperMetaTag>
</metaInformation>
-->