<?xml version="1.0" encoding="utf-8"?>
<!-- Mapix default theme controller -->
<xsl:stylesheet  version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:http="exslt://mapix/core/http"
	xmlns:file="exslt://mapix/file/file"
	xmlns:lang="exslt://mapix/lang">
	<xsl:output omit-xml-declaration="yes" indent="no"/>

	<!-- Functions and templates -->
	<xsl:include href="exslt://mapix/file/file"/>
	<xsl:include href="../../lang/template.xsl"/>
	<xsl:include href="template.xsl"/>

	<!-- Language detection from URI -->
	<xsl:variable name="lang" select="lang:detect()"/>

	<!-- Home controller -->
	<xsl:template match="http:request[http:virtual-uri='' or http:virtual-uri=lang:detect()]">
		<xsl:call-template name="page">
			<xsl:with-param name="menu" select="document(concat($content-dir,'/',$lang,'/menu.html'))"/>
			<xsl:with-param name="messages" select="document(concat($content-dir,'/messages.xml'))"/>
			<xsl:with-param name="content" select="document(concat($content-dir,'/',$lang,'/index.html'))"/>
		</xsl:call-template>
	</xsl:template>

	<!-- Page controller -->
	<xsl:template match="http:request[file:exists(concat($content-dir,http:virtual-uri))]" priority="-1">
		<xsl:call-template name="page">
			<xsl:with-param name="menu" select="document(concat($content-dir,'/',$lang,'/menu.html'))"/>
			<xsl:with-param name="messages" select="document(concat($content-dir,'/',$lang,'/messages.xml'))"/>
			<xsl:with-param name="content" select="document(concat($content-dir,'/',http:virtual-uri))"/>
		</xsl:call-template>
	</xsl:template>

	<!-- 404 controller -->
	<xsl:template match="http:request" priority="-2">
		<http:header>HTTP/1.0 404 Not Found</http:header>
		<xsl:call-template name="page">
			<xsl:with-param name="menu" select="document(concat($content-dir,'/',$lang,'/menu.html'))"/>
			<xsl:with-param name="messages" select="document(concat($content-dir,'/',messages.xml'))"/>
			<xsl:with-param name="content" select="document(concat($content-dir,'/',$lang,'/404.html'))"/>
		</xsl:call-template>
	</xsl:template>
</xsl:stylesheet>
