<?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" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:variable name="id" select="substring(//SDOCNAME/new_line,3,5)"/>

	<xsl:template match="*">
		<xsl:copy>
			<xsl:apply-templates select="node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="DOC1|DOC2|DOC3|DOC4|DOC5|DOC6|DOC7|DOC8|DOC9|DOC10">
		<xsl:variable name="docxA" select="substring( .,10,5)"/>
		<xsl:if test="$docxA=$id">
			<DOC>
				<xsl:apply-templates/>
			</DOC>
		</xsl:if>
		<xsl:if test="not($docxA=$id)">
			<JOINDOC>
				<xsl:apply-templates/>
			</JOINDOC>
		</xsl:if>		
	</xsl:template>
	<xsl:template match="DOC1A|DOC2A|DOC3A|DOC4A|DOC5A|DOC6A|DOC7A|DOC8A|DOC9A|DOC10A">
		<DOCA>
			<xsl:apply-templates/>
		</DOCA>
	</xsl:template>
	<xsl:template match="DOC1N|DOC2N|DOC3N|DOC4N|DOC5N|DOC6N|DOC7N|DOC8N|DOC9N|DOC10N">
		<DOCN>
			<xsl:apply-templates/>
		</DOCN>
	</xsl:template>
	<xsl:template match="DOC1F|DOC2F|DOC3F|DOC4F|DOC5F|DOC6F|DOC7F|DOC8F|DOC9F|DOC10F">
		<DOCF>
			<xsl:apply-templates/>
		</DOCF>
	</xsl:template>
	<xsl:template match="COMM2|COMM3|COMM4|COMM5|COMM6|COMM7|COMM8|COMM9|COMM10">
		<COMM>
			<xsl:apply-templates/>
		</COMM>
	</xsl:template>
	
</xsl:stylesheet>
