<?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:variable name="ID" select="format-number(dossierID,'0000')"/>
	<xsl:variable name="rappN" select="' Rapporteur  : '"/>
	<xsl:variable name="rappF" select="' Rapporteur  : '"/>
	<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(substring(SDOCNAME,4,4),'####')"/>
			<xsl:variable name="textn1">
				<xsl:apply-templates mode="N" select="TITLE">
					<xsl:sort select="./version" order="descending"/>
				</xsl:apply-templates>
			</xsl:variable>
			<xsl:variable name="textn" select="concat($textn1,', nr.',$nbs,$ID,'/1')"/>
			<xsl:variable name="textf1">
				<xsl:apply-templates mode="F" select="TITLE">
					<xsl:sort select="./version" order="descending"/>
				</xsl:apply-templates>
			</xsl:variable>
			<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="$ID"/>
					</parolis_nr>
				</parolis>
				<xsl:choose>
					<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:value-of select="'jantje'"/>
						<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 van bijzondere')">
						<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 bijzondere wet'"/>
							<xsl:with-param name="waarF" select="'Proposition de loi spéciale'"/>
						</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="textn1a" select="'('"/>
						<xsl:variable name="textn2a" select="concat(')',$textn)"/>
						<xsl:variable name="textf1a" select="'('"/>
						<xsl:variable name="textf2a" select="concat(')',$textf)"/>
						<topic_text>
							<textN>
								<xsl:value-of select="$textn1a"/>
								<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NA"/>
								<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NB"/>
								<xsl:value-of select="concat($textn2a,'.')"/>
							</textN>
							<textF>
								<xsl:value-of select="$textf1a"/>
								<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NA"/>
								<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NB"/>
								<xsl:value-of select="concat($textf2a,'.')"/>
							</textF>
						</topic_text>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:apply-templates select="BICAM/MAINDOC/JOINTDOCS" mode="text"/>
				<topic_note>
					<noteN>
						<xsl:apply-templates select="COMPET_BEVOEGD" mode="N"/>
						<xsl:apply-templates select="COMMISSIES/COMMISSIE/RAPPORTEUR"/>
					</noteN>
					<noteF>
						<xsl:apply-templates select="COMPET_BEVOEGD" mode="F"/>
						<xsl:apply-templates select="COMMISSIES/COMMISSIE/RAPPORTEUR"/>
					</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:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NA"/>
				<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NB"/>
				<xsl:value-of select="$textn2"/>
				<xsl:apply-templates select="BICAM/MAINDOC[1]/SUBDOCS" mode="N"/>
				<xsl:value-of select="'.'"/>
			</textN>
			<textF>
				<xsl:value-of select="$textf1"/>
				<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NA"/>
				<xsl:apply-templates select="BICAM/MAINDOC/AUTEURM" mode="NB"/>
				<xsl:value-of select="$textf2"/>
				<xsl:apply-templates select="BICAM/MAINDOC[1]/SUBDOCS" mode="F"/>
				<xsl:value-of select="'.'"/>
			</textF>
		</topic_text>
	</xsl:template>
	<xsl:template match="JOINTDOCS" mode="text">
		<xsl:for-each select="JOINTDOC">
			<xsl:choose>
				<xsl:when test="substring(./NRJ,4,4) = '0082'">
					</xsl:when>
				<xsl:when test="substring(./NRJ,1,2) = '00'">
					<topic_text>
						<textN>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</textN>
						<textF>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</textF>
					</topic_text>
				</xsl:when>
				<xsl:when test="contains(.,'BESLISSINGEN OVERLEGCOMMISSIE')">
					</xsl:when>
				<xsl:otherwise>
					<topic_text>
						<textN>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</textN>
						<textF>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</textF>
					</topic_text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="JOINTDOCS" mode="note">
		<xsl:for-each select="JOINTDOC">
			<xsl:choose>
				<xsl:when test="substring(./NRJ,4,4) = '0082'">
				</xsl:when>
				<xsl:when test="substring(./NRJ,1,2) = '00'">
					<topic_note>
						<noteN>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</noteN>
						<noteF>
							<xsl:value-of select="substring(./NRJ,4,4)"/>
						</noteF>
					</topic_note>
				</xsl:when>
				<xsl:when test="contains(.,'BESLISSINGEN OVERLEGCOMMISSIE')">
				</xsl:when>
				<xsl:otherwise>
					<topic_note>
						<noteN>
						</noteN>
						<noteF>
						</noteF>
					</topic_note>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="TITLE" mode="N">
		<xsl:if test="position() = 1">
			<xsl:value-of select="substring(normalize-space(TITLE_LONG/TITLE_LONG_textN),1,string-length(normalize-space(TITLE_LONG/TITLE_LONG_textN))-1)"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="TITLE" mode="F">
		<xsl:if test="position() = 1">
			<xsl:value-of select="substring(normalize-space(TITLE_LONG/TITLE_LONG_textF),1,string-length(normalize-space(TITLE_LONG/TITLE_LONG_textF))-1)"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="AUTEURM" mode="NA">
		<xsl:if test="(normalize-space(AUTEURM_TYPE/AUTEURM_TYPE_textN)='AUTEUR')">
			<xsl:value-of select="concat(./AUTEURM_FORNAAM,' ',./AUTEURM_FAMNAAM)"/>
			<xsl:if test="position() != last()">
				<xsl:value-of select="', '"/>
			</xsl:if>
		</xsl:if>
	</xsl:template>
	<xsl:template match="AUTEURM" mode="NB">
		<xsl:if test="(normalize-space(AUTEURM_TYPE/AUTEURM_TYPE_textN)!='AUTEUR')">
			<xsl:if test="(position() = 1 and normalize-space(./AUTEURM_FAMNAAM) != '')">
				<xsl:value-of select="', ['"/>
			</xsl:if>
			<xsl:value-of select="concat(./AUTEURM_FORNAAM,' ',./AUTEURM_FAMNAAM,', ')"/>
			<xsl:if test="(position() = last() and normalize-space(./AUTEURM_FAMNAAM) != '')">
				<xsl:value-of select="']'"/>
			</xsl:if>
		</xsl:if>
	</xsl:template>
	<xsl:template match="COMPET_BEVOEGD" mode="N">
		<xsl:if test="contains(COMPET_BEVOEGD_textN,'ARTIKEL')">
			<xsl:choose>
				<xsl:when test="position()=1 and position()=last()">
					<xsl:value-of select="concat('$',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '),'$')"/>
				</xsl:when>
				<xsl:when test="position()=1">
					<xsl:value-of select="concat('$',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '))"/>
				</xsl:when>
				<xsl:when test="position()=last()">
					<xsl:value-of select="concat('+',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '),'$')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat('+',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '))"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:value-of select="' - '"/>
		</xsl:if>
		<xsl:if test="contains(COMPET_BEVOEGD_textN,'URGENTIE GEVRAAGD')">
			<xsl:value-of select="'$URG80$ voor wetsontwerp : '"/>
			<xsl:value-of select="$ID"/>
			<xsl:value-of select="' - '"/>
		</xsl:if>
		<xsl:choose>
			<xsl:when test="contains(COMPET_BEVOEGD_textN,'ARTIKEL')">
				<xsl:value-of select="$rappN"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$rappN"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="COMPET_BEVOEGD" mode="F">
		<xsl:if test="contains(COMPET_BEVOEGD_textN,'ARTIKEL')">
			<xsl:choose>
				<xsl:when test="position()=1 and position()=last()">
					<xsl:value-of select="concat('$',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '),'$')"/>
				</xsl:when>
				<xsl:when test="position()=1">
					<xsl:value-of select="concat('$',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '))"/>
				</xsl:when>
				<xsl:when test="position()=last()">
					<xsl:value-of select="concat('+',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '),'$')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat('+',substring-after(./COMPET_BEVOEGD_textN,'ARTIKEL '))"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:value-of select="' - '"/>
		</xsl:if>
		<xsl:if test="contains(COMPET_BEVOEGD_textN,'URGENTIE GEVRAAGD')">
			<xsl:value-of select="'$URG80$ pour le projet de loi : '"/>
			<xsl:value-of select="$ID"/>
			<xsl:value-of select="' - '"/>
		</xsl:if>
		<xsl:choose>
			<xsl:when test="contains(COMPET_BEVOEGD_textN,'ARTIKEL')">
				<xsl:value-of select="$rappF"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$rappF"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="RAPPORTEUR">
		<xsl:choose>
			<xsl:when test="position()=last()">
				<xsl:value-of select="concat(./RAPPORTEUR_FORNAAM,' ',./RAPPORTEUR_FAMNAAM)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat(./RAPPORTEUR_FORNAAM,' ',./RAPPORTEUR_FAMNAAM,', ')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="SUBDOCS" mode="N">
		<xsl:for-each select="SUBDOC">
			<xsl:choose>
				<xsl:when test="position() = last()">
					<xsl:choose>
						<xsl:when test="./SUBDOCNR=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(./SUBDOCNR,'###')"/>
				</xsl:when>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="SUBDOCS" mode="F">
		<xsl:for-each select="SUBDOC">
			<xsl:choose>
				<xsl:when test="position() = last()">
					<xsl:choose>
						<xsl:when test="./SUBDOCNR=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(./SUBDOCNR,'###')"/>
				</xsl:when>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
