<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="dossierID"/>
	<xsl:template match="/">
		<xsl:variable name="nbs" select="'&#160;'"/>
		<xsl:for-each select="DOSSIER">
			<xsl:variable name="partype" select="'P'"/>
			<xsl:variable name="ID" select="format-number(ID,'####')"/>
			<xsl:variable name="textn1" select="substring(normalize-space(TITLE/textN),1,string-length(normalize-space(TITLE/textN))-1)"/>
			<!-- sluitpunt weg-->
			<!--			<xsl:variable name="textn" select="concat(TITLE/textN,'nr. ',$ID,'/1')"/>-->
			<xsl:variable name="textn" select="concat($textn1,', nr.',$nbs,$ID,'/1')"/>
			<xsl:variable name="textf1" select="substring(normalize-space(TITLE/textF),1,string-length(normalize-space(TITLE/textF))-1)"/>
			<xsl:variable name="textf" select="concat($textf1,', n°',$nbs,$ID,'/1')"/>
			<topic_item>
				<parolis>
					<parolis_type>
						<xsl:value-of select="$partype"/>
					</parolis_type>
					<parolis_nr>
						<xsl:value-of select="$dossierID"/>
					</parolis_nr>
				</parolis>
				<xsl:choose>
					<!--					<xsl:when test="contains(SDOCNAME,'NO-DATA')">-->
					<xsl:when test="ID=''">
						<topic_text>
							<textN>
								<xsl:value-of select="$textn1"/>
							</textN>
							<textF>
								<xsl:value-of select="$textf1"/>
							</textF>
						</topic_text>
					</xsl:when>
					<xsl:when test="contains($textn,'Wetsvoorstel')">
						<xsl:call-template name="text">
							<xsl:with-param name="notaN" select="$textn"/>
							<xsl:with-param name="notaF" select="$textf"/>
							<xsl:with-param name="waarN" select="'Wetsvoorstel'"/>
							<xsl:with-param name="waarF" select="'Proposition de loi'"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:when test="contains($textn,'Voorstel van resolutie')">
						<xsl:call-template name="text">
							<xsl:with-param name="notaN" select="$textn"/>
							<xsl:with-param name="notaF" select="$textf"/>
							<xsl:with-param name="waarN" select="'Voorstel van resolutie'"/>
							<xsl:with-param name="waarF" select="'Proposition de résolution'"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:when test="contains($textn,'Voorstel')">
						<xsl:call-template name="text">
							<xsl:with-param name="notaN" select="$textn"/>
							<xsl:with-param name="notaF" select="$textf"/>
							<xsl:with-param name="waarN" select="'Voorstel'"/>
							<xsl:with-param name="waarF" select="'Proposition'"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:when test="contains($textn,'Wetsontwerp')">
						<xsl:call-template name="text">
							<xsl:with-param name="notaN" select="$textn"/>
							<xsl:with-param name="notaF" select="$textf"/>
							<xsl:with-param name="waarN" select="''"/>
							<xsl:with-param name="waarF" select="''"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="textn1" select="'('"/>
						<xsl:variable name="textn2" select="concat(')',$textn)"/>
						<xsl:variable name="textf1" select="'('"/>
						<xsl:variable name="textf2" select="concat(')',$textf)"/>
						<topic_text>
							<textN>
								<xsl:value-of select="$textn1"/>
								<xsl:for-each select="MAINDOCS/MAINDOC/AUTEURS/AUTEUR">
									<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM,', ')"/>
								</xsl:for-each>
								<xsl:value-of select="concat($textn2,'.')"/>
								<xsl:value-of select="' (Rapporteur : '"/>
								<xsl:call-template name="rapporteurs"/>
								<xsl:value-of select="')'"/>
							</textN>
							<textF>
								<xsl:value-of select="$textf1"/>
								<xsl:for-each select="MAINDOCS/MAINDOC/AUTEURS/AUTEUR">
									<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM,', ')"/>
								</xsl:for-each>
								<xsl:value-of select="concat($textf2,'.')"/>
								<xsl:value-of select="' (Rapporteur : '"/>
								<xsl:call-template name="rapporteurs"/>
								<xsl:value-of select="')'"/>
							</textF>
						</topic_text>
					</xsl:otherwise>
				</xsl:choose>
				<topic_note>
					<xsl:variable name="rappN" select="' Rapporteur  : '"/>
					<xsl:variable name="rappF" select="' Rapporteur  : '"/>
					<noteN>
						<xsl:for-each select="COMPET-BEVOEGD/textN[contains(.,'ARTIKEL')]">
							<xsl:choose>
								<xsl:when test="position()=1 and position()=last()">
									<xsl:value-of select="concat('$',substring-after(.,'ARTIKEL '),'$')"/>
								</xsl:when>
								<xsl:when test="position()=1">
									<xsl:value-of select="concat('$',substring-after(.,'ARTIKEL '))"/>
								</xsl:when>
								<xsl:when test="position()=last()">
									<xsl:value-of select="concat('+',substring-after(.,'ARTIKEL '),'$')"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat('+',substring-after(.,'ARTIKEL '))"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</noteN>
					<noteF>
						<xsl:for-each select="COMPET-BEVOEGD/textN[contains(.,'ARTIKEL')]">
							<xsl:choose>
								<xsl:when test="position()=1 and position()=last()">
									<xsl:value-of select="concat('$',substring-after(.,'ARTIKEL '),'$')"/>
								</xsl:when>
								<xsl:when test="position()=1">
									<xsl:value-of select="concat('$',substring-after(.,'ARTIKEL '))"/>
								</xsl:when>
								<xsl:when test="position()=last()">
									<xsl:value-of select="concat('+',substring-after(.,'ARTIKEL '),'$')"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat('+',substring-after(.,'ARTIKEL '))"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</noteF>
				</topic_note>
			</topic_item>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="text">
		<xsl:param name="notaN"/>
		<xsl:param name="notaF"/>
		<xsl:param name="waarN"/>
		<xsl:param name="waarF"/>
		<xsl:variable name="textn1" select="concat($waarN,' (')"/>
		<xsl:variable name="textn2" select="concat(') ',substring-after($notaN,$waarN))"/>
		<xsl:variable name="textf1" select="concat($waarF,' (')"/>
		<xsl:variable name="textf2" select="concat(') ',substring-after($notaF,$waarF))"/>
		<topic_text>
			<textN>
				<xsl:value-of select="$textn1"/>
				<xsl:call-template name="auteurs"/>
				<xsl:value-of select="$textn2"/>
				<xsl:for-each select="SUBDOCS/SUBDOC">
					<xsl:choose>
						<xsl:when test="position()=last()">
							<xsl:choose>
								<xsl:when test="NR=002">
									<xsl:variable name="et" select="' en '"/>
									<xsl:value-of select="$et"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:variable name="et" select="' tot '"/>
									<xsl:value-of select="$et"/>
								</xsl:otherwise>
							</xsl:choose>
							<xsl:value-of select="format-number(NR,'###')"/>
						</xsl:when>
					</xsl:choose>
				</xsl:for-each>
				<xsl:value-of select="'.'"/>
				<xsl:value-of select="' (Rapporteur : '"/>
				<xsl:call-template name="rapporteurs"/>
				<xsl:value-of select="')'"/>
			</textN>
			<textF>
				<xsl:value-of select="$textf1"/>
				<xsl:call-template name="auteurs"/>
				<xsl:value-of select="$textf2"/>
				<xsl:for-each select="SUBDOCS/SUBDOC">
					<xsl:if test="position()=last()">
						<xsl:choose>
							<xsl:when test="NR=002">
								<xsl:variable name="et" select="' et '"/>
								<xsl:value-of select="$et"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:variable name="et" select="' à '"/>
								<xsl:value-of select="$et"/>
							</xsl:otherwise>
						</xsl:choose>
						<xsl:value-of select="format-number(NR,'###')"/>
					</xsl:if>
				</xsl:for-each>
				<xsl:value-of select="'.'"/>
				<xsl:value-of select="' (Rapporteur : '"/>
				<xsl:call-template name="rapporteurs"/>
				<xsl:value-of select="')'"/>
			</textF>
		</topic_text>
	</xsl:template>
	<xsl:template name="auteurs">
		<xsl:for-each select="MAINDOCS/MAINDOC/AUTEURS/AUTEUR">
			<xsl:choose>
				<xsl:when test="position()=last() and position()=1">
					<xsl:value-of select="normalize-space(concat(FORNAAM,' ',FAMNAAM))"/>
				</xsl:when>
				<xsl:when test="position()=last()">
					<xsl:value-of select="normalize-space(concat(FORNAAM,' ',FAMNAAM))"/>
				</xsl:when>
				<xsl:when test="position()=1">
					<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM,', ')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM,', ')"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="rapporteurs">
		<xsl:for-each select="COMMS/COMM/RAPPORTEUR">
			<xsl:choose>
				<xsl:when test="position()=last()">
					<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat(FORNAAM,' ',FAMNAAM,', ')"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
