﻿<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema'
version="1.0">
	<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
	<xsl:variable name="cultura" select="substring(//culture/ui/@name,1,2)"></xsl:variable>
	<xsl:variable name="url" select="substring-before(substring-after(//querystring/field[@name='Source'],'?'),'-')"></xsl:variable>
	<xsl:variable name="url2" select="substring-before(//querystring/field[@name=''],'-')"></xsl:variable>
	<xsl:variable name="Idioma">
		<xsl:choose>
			<xsl:when test="$url!=$url2 and $url=''">
				<xsl:value-of select="$url2" />
			</xsl:when>
			<xsl:when test="$cultura!=$url and $url!=$url2 and $url!=''">
				<xsl:value-of select="$url" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$cultura" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="UrlPaginaquienessomos" select="contains(//server/field[@name='URL'], '/quienessomos/')"></xsl:variable>
	<xsl:variable name="UrlPaginanutricion" select="contains(//server/field[@name='URL'], '/nutricion/')"></xsl:variable>
	<xsl:variable name="UrlPaginaoficinavirtual" select="contains(//server/field[@name='URL'], '/oficinavirtual/')"></xsl:variable>
	<xsl:variable name="UrlPaginanewsletter" select="contains(//server/field[@name='URL'], '/newsletter/')"></xsl:variable>
	<xsl:template match="/">
		<table cellpadding="0" cellspacing="0" class="topNav" style="top:0px; width:460px;">
			<tr>
			<xsl:choose>
			<xsl:when test="./data/row[Idioma=$Idioma]">
				<xsl:for-each select="./data/row[Idioma=$Idioma]">
				<xsl:sort select="./position"></xsl:sort>
				<xsl:variable name="UrlEnlacequienessomos" select="contains(Url, '/quienessomos/')"></xsl:variable>
				<xsl:variable name="UrlEnlacenutricion" select="contains(Url, '/nutricion/')"></xsl:variable>
				<xsl:variable name="UrlEnlaceoficinavirtual" select="contains(Url, '/oficinavirtual/')"></xsl:variable>
				<xsl:variable name="UrlEnlacenewsletter" select="contains(Url, '/newsletter/')"></xsl:variable>
					<xsl:choose>
						<xsl:when test="$UrlPaginaquienessomos='true' and $UrlEnlacequienessomos='true'">
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem topNavSelected">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff; width:110px;">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</xsl:when> 
						<xsl:when test="$UrlPaginanutricion='true' and $UrlEnlacenutricion='true'">
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem topNavSelected">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff;">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</xsl:when>
						<xsl:when test="$UrlPaginaoficinavirtual='true' and $UrlEnlaceoficinavirtual='true'">
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem topNavSelected">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff;width:115px;">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</xsl:when>
						<xsl:when test="$UrlPaginanewsletter='true' and $UrlEnlacenewsletter='true'">
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem topNavSelected">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff;">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</xsl:when>

						<xsl:otherwise>
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
				<xsl:if test="$Idioma='gl'">
				<xsl:for-each select="./data/row[Idioma!=$Idioma]">
				<xsl:choose>
				<xsl:when test="substring-before(substring-after(Url, '_'), '.aspx')='ga'">
							<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="topNavItem">
									<tr>
										<td>
											<a class="topNavItem" style="color:#fff">
												<xsl:if test="VentanaNueva='True'">
													<xsl:attribute name="target">_blank</xsl:attribute>
												</xsl:if>
												<xsl:attribute name="href">
													<xsl:value-of select="Url" />
												</xsl:attribute>
												<xsl:value-of select="Title" />
											</a>
										</td>
									</tr>
								</table>
							</td>
				</xsl:when>
				</xsl:choose>
				</xsl:for-each>
				</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
			</tr>
		</table>
	</xsl:template>
	
</xsl:stylesheet>

