<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template name="readfile">
		<xsl:param name="ID"/>
		<xsl:param name="legis"/>
		<xsl:param name="type"/>
		<!-- when legislat not given, will be resolved by cocoon sitemap -->
		<!-- xsl:variable name="XML_content" select="document(concat(concat(concat(concat('http://localhost:8080/cocoon/FLWB/',$legis),'/'),$ID),'.xml'))//FLWBDOC"/ -->
		<!--  Error when trying ?ID=BROL -->
		<!--xsl:variable name="XML_content" select="document(concat(concat('cocoon://FLWB/51/',$ID),'.xml'))//FLWBDOC"/-->
		<xsl:variable name="leg">
			<xsl:choose>
				<xsl:when test="string-length($legis)=0">
					<xsl:value-of select="'51'"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$legis"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="typ">
			<xsl:choose>
				<xsl:when test="string-length($type)=0">
					<xsl:value-of select="'K'"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$type"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:call-template name="type1">
			<xsl:with-param name="ID" select="$ID"/>
			<xsl:with-param name="legis" select="$leg"/>
			<xsl:with-param name="type" select="$typ"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="no-dossier">
		<xsl:param name="ID"/>
		<xsl:param name="type"/>
		<xsl:variable name="ID1" select="concat($type,$ID)"/>
		<FLWBDOC>
			<SDOCNAME>NO-DOSSIER for <xsl:value-of select="$ID1"/>
			</SDOCNAME>
			<TITF>NO-DOSSIER for <xsl:value-of select="$ID1"/>
			</TITF>
			<TITN>NO-DOSSIER for <xsl:value-of select="$ID1"/>
			</TITN>
		</FLWBDOC>
	</xsl:template>
	<xsl:template name="type1">
		<xsl:param name="ID"/>
		<xsl:param name="legis"/>
		<xsl:param name="type"/>
		<xsl:variable name="XML_content" select="document(concat('http://localhost:8080/cocoon/FLWB/',$legis,'/',$type,$ID,'.xml'))//FLWBDOC"/>
		<xsl:choose>
			<xsl:when test="string-length($XML_content)=0">
				<xsl:call-template name="no-dossier">
					<!--					<xsl:with-param name="ID" select="concat($ID,'pech',$legis,$type)"/>-->
					<xsl:with-param name="ID" select="$ID"/>
					<xsl:with-param name="type" select="$type"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="$XML_content"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
