<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="dossierID"/>
	<xsl:param name="legislat"/>

	<xsl:template match="/" name="map_to_correct_ID">
		<xsl:choose>
			<xsl:when test="string-length($dossierID)=4">
				<xsl:call-template name="readfile2">
					<xsl:with-param name="ID" select="$dossierID"/>
					<xsl:with-param name="legis" select="$legislat"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="string-length($dossierID)=3">
				<xsl:call-template name="readfile2">
					<xsl:with-param name="ID" select="concat('0',$dossierID)"/>
					<xsl:with-param name="legis" select="$legislat"/>					
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="string-length($dossierID)=2">
				<xsl:call-template name="readfile2">
					<xsl:with-param name="ID" select="concat('00',$dossierID)"/>
					<xsl:with-param name="legis" select="$legislat"/>					
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="string-length($dossierID)=1">
				<xsl:call-template name="readfile2">
					<xsl:with-param name="ID" select="concat('000',$dossierID)"/>
					<xsl:with-param name="legis" select="$legislat"/>					
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
			
				<xsl:call-template name="no-dossier"/>
				
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
		
<xsl:template name="readfile2">
		<xsl:param name="ID"/>
		<xsl:param name="legis"/>		
		<!-- when legislat not given, will be resolved by cocoon sitemap -->
		<xsl:variable name="XML_content" select="document(concat(concat(concat(concat('cocoon://FLWB/',$legis),'/'),$ID),'.xml'))//FLWBDOC"/>
		<xsl:choose>
			<xsl:when test="string-length($XML_content)=0">
				<xsl:call-template name="no-dossier"/>
			</xsl:when>
			<xsl:otherwise>
			<DOSSIER>
				<ID><xsl:value-of  select="$XML_content//SDOCNAME"/>
				</ID>
				<title>
					<xsl:copy-of select="$XML_content//TITN"/>
					<xsl:copy-of  select="$XML_content//TITF"/>
				</title>
			</DOSSIER>			
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


<xsl:template name="no-dossier">
		<DOSSIER>
				<ID>NO-DOSSIER
				</ID>
				<title>
					<TITN>
						geen titel beschikbaar
					</TITN>
					<TITF>
						pas de titre disponible
					</TITF>
				</title>
</DOSSIER>
</xsl:template>
				
		
</xsl:stylesheet>
