<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">

<xsl:variable name="siteroot" select="//site/head/@root"/>
<xsl:variable name="siterootlg" select="//site/head/@rootlg"/>
<xsl:variable name="siterootalt" select="//site/head/@rootalt"/>
<xsl:variable name="siterootlang" select="concat(//site/head/@root,'/',//site/head/@lang)"/>
<xsl:variable name="sitecat" select="//site/head/@sitecat"/>
<xsl:variable name="imgpath" select="//site/head/@imgpath"/>
<xsl:variable name="imguserpath" select="//site/head/@imguserpath"/>
<xsl:variable name="lang" select="//site/head/@lang"/>
<xsl:variable name="subsite" select="//site/head/@subsite"/>
<xsl:variable name="libassetsroot" select="//site/head/@libassetsroot"/>
<xsl:variable name="siteassetsroot" select="concat(//site/head/@root,'siteassets/')"/>
<xsl:variable name="publicroot" select="concat(//site/head/@root,'publiccontent/')"/>
<xsl:variable name="cc" select="//*[@currentcat='1']"/>
<xsl:variable name="ccf" select="//*[@finalcat='1']"/>
<xsl:variable name="si" select="//site/head/@si"/>
<xsl:variable name="sa" select="//site/head/@sa"/>
<xsl:variable name="pc" select="//site/head/@pc"/>
<xsl:variable name="ca" select="//site/head/@ca"/>
<xsl:variable name="ci" select="//site/head/@ci"/>
<xsl:variable name="cvi" select="//site/head/@cvi"/>
<xsl:variable name="lg" select="//site/head/@lg"/>

<xsl:template match="@*">
	<xsl:copy/>
</xsl:template>

<xsl:template match="*">
	<xsl:element name="{name()}">
		<xsl:apply-templates select="* | text() | @*"/>
	</xsl:element>
</xsl:template>

<xsl:template name="gen_Header">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta name="keywords">
		<xsl:attribute name="content"><xsl:value-of select="//site/head/@seokw"/><xsl:if test="string-length(//kw[@currentkw='1']) &gt; 0"><xsl:value-of select="concat(',', //kw[@currentkw='1'])"/></xsl:if><xsl:if test="string-length(//site/kw) &gt; 0"><xsl:value-of select="concat(',', //site/kw)"/></xsl:if><xsl:if test="string-length(//*[@currentseo='1']/seokw) &gt; 0"><xsl:value-of select="concat(',', //*[@currentseo='1']/seokw)"/></xsl:if></xsl:attribute>
	</meta>
	<meta name="description">
		<xsl:attribute name="content"><xsl:value-of select="//site/head/@seodesc"/><xsl:if test="string-length(//*[@currentseo='1']/seodesc) &gt; 0"><xsl:value-of select="concat(' ', //*[@currentseo='1']/seodesc)"/></xsl:if></xsl:attribute>
	</meta>
	<xsl:if test="//site/head/@applefix = '1'">
		<meta content='width=device-width; initial-scale=1.0;' name='viewport' />
	</xsl:if>	
	<base href="{$siterootlg}"/>
	<title>
		<xsl:value-of select="//site/head/@title"/>
		<xsl:if test="string-length(//*[@currentseo='1']/seotitre) &gt; 0">
			<xsl:value-of select="concat(' ', //*[@currentseo='1']/seotitre)"/>
		</xsl:if>
	</title>
	<link rel="shortcut icon" href="{concat($si, //site/head/@icon)}"/>
	<xsl:call-template name="gen_Css"/>
	<xsl:if test="//site/head/@iecss = '1'">
		<xsl:comment><![CDATA[[if IE]><link rel="stylesheet" type="text/css" media="screen" href="]]><xsl:value-of select="$siteroot"/>site/assets/<![CDATA[style-ie.css"/><![endif ]]]></xsl:comment>
	</xsl:if>	
	<script type="text/javascript">var SITE_ROOT = '<xsl:value-of select="$siteroot"/>';var SITE_ASSETS = '<xsl:value-of select="$libassetsroot"/>';var SITE_LANG = '<xsl:value-of select="$lang"/>';<xsl:call-template name="gen_JsVar"/></script>
	<xsl:call-template name="gen_Js"/>
	<xsl:call-template name="gen_GAcode"/>
</xsl:template>


<xsl:template name="gen_Css">
	<xsl:for-each select="//site/head/css">
		<xsl:choose>
			<xsl:when test="contains(.,'http://')">
				<link rel="stylesheet" type="text/css" href="."/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="@asset = '1'">
						<link rel="stylesheet" type="text/css" href="{concat($libassetsroot,.)}"/>
					</xsl:when>
					<xsl:otherwise>
						<link rel="stylesheet" type="text/css" href="{concat($siteassetsroot,.)}"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

<xsl:template name="gen_Js">
	<xsl:for-each select="//site/head/javascript">
		<xsl:choose>
			<xsl:when test="contains(.,'http://')">
				<script src="." type="text/javascript">
					<xsl:comment/>
				</script>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="@asset = '1'">
						<script src="{concat($libassetsroot,.)}" type="text/javascript">
							<xsl:comment/>
						</script>
					</xsl:when>
					<xsl:otherwise>
						<script src="{concat($siteassetsroot,.)}" type="text/javascript">
							<xsl:comment/>
						</script>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>


<xsl:template name="gen_JsVar">
	<xsl:for-each select="//site/head/javascriptvar">var <xsl:value-of select="@name"/> = '<xsl:value-of select="@value"/>';</xsl:for-each>
</xsl:template>

<xsl:template name="gen_GAcode">
	<xsl:if test="string-length(//site/content/gacode) &gt; 3">
		<script type="text/javascript">
			var _gaq = _gaq || [];
			_gaq.push(['_setAccount', '<xsl:value-of select="//site/content/gacode"/>']);
			_gaq.push(['_trackPageview']);
			<xsl:if test="//site/content/gacmde">
				<xsl:apply-templates select="//site/content/gacmde/node()"/>
			</xsl:if>
			(function() {
				var ga = document.createElement('script'); ga.type = 'text/javascript';
				ga.async = true;
				ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
				var s = document.getElementsByTagName('script')[0];
				s.parentNode.insertBefore(ga, s);
				//console.log('i');
			})();
		</script>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>
