<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:ns2="http://cdm-fr.fr/2011/CDM-frSchema"
xmlns:cdm="http://cdm-fr.fr/2006/CDM-frSchema/" cdm:schemaLocation="http://cdm-fr.fr/2006/CDM-frSchema/ http://cdm-fr.fr/cdm/2006/schemas/CDM-fr.xsd">
	<xsl:output method="xml"/>
	<xsl:template match="/">
		<CDM>
			<xsl:variable name="pident" select="/CDM/program[position()=1]/@ident"/>
			<program ident="{$pident}">
				<xsl:copy-of select="/CDM/program[1]/programName"/>
				<xsl:apply-templates select="/CDM/program[1]/programCode"/>
				<programStructure>
					<xsl:apply-templates select="/CDM/program[1]/programStructure/refProgram"/>
				</programStructure>
				<programDescription>
					<xsl:apply-templates select="/CDM/program[1]/programDescription"/>
				</programDescription>
			</program>
		</CDM>
	</xsl:template>
	<xsl:template match="programCode">
		<xsl:copy-of select="."/>
	</xsl:template>
	<xsl:template match="refProgram">
		<xsl:variable name="ident" select="@ref"/>
		<xsl:if test="/CDM/program[@ident=$ident]">
			<refProgram ref="{$ident}" finalite="{/CDM/program[@ident=$ident]/programCode[@codeSet='uniform.finalite']}">
				<xsl:copy-of select="/CDM/program[@ident=$ident]/programCode"/>
				<xsl:copy-of select="/CDM/program[@ident=$ident]/programName"/>
				<xsl:copy-of select="/CDM/program[@ident=$ident]/programDescription"/>
				<xsl:apply-templates select="/CDM/program[@ident=$ident]/programStructure/refProgram"/>
			</refProgram>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>