miércoles, 18 de junio de 2014

<?xml version="1.0" encoding="UTF-8"?>
<!--
===============================
Lenguajes de Marcas
Bloque 5, actividad 5, parte 1.
Alumno: Miguel I. García López.
===============================

Enunciado:

"Generar un fichero XSL (p1.xsl) en el que se
muestre una tabla con todos los datos de los
productos (salvo la foto) que el supermercado
tiene almacenados."

La tabla se muestra ordenada por nº de referencia del producto.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<!-- Definimos el nombre del programa de gestión y el copyright -->

<xsl:variable name="programa"  select="'SuperMarket de Luxe v1.05'"/>
<xsl:variable name="copyright" select="'(c) 2014 Miguel I. García López'"/>

<!-- Inicio de la salida HTML -->

<html>
<head>
<title>
Actividad 5.1: Miguel I. García López
</title>

<!-- Definición de estilos -->

<style>
body
{
font-family: Tahoma, Verdana, Arial, sans-serif;
text-align: center;
}
table, th, td
{
border-style: outset;
border-width: 2px;
border-color: black;
border-collapse:collapse;
}
th
{
font-family: "Times News Roman", serif;
font-variant: small-caps;
font-weight: bold;
font-size: medium;
color: white;
background-color: brown;
text-align: center;
}
td
{
font-family: Tahoma, Verdana, Arial, sans-serif;
font-size: small;
text-align: left;
}
</style>
</head>

<body>

<!-- Mostrar el logotipo del supermercado -->

<img src="{/productos/@logo}" alt="Logo del supermercado" />

<!-- Mostrar el nombre del supermercado entre corchetes -->

<h1>
[<xsl:value-of select="/productos/@supermercado"/>]
</h1>

<!-- Mostrar el título del informe, y el nº de productos listados -->

<h2>
Listado de productos, ordenados por nº de referencia:

<xsl:value-of select="count(/productos/producto)"/> productos en total.
</h2>

<!-- Mostrar la tabla -->

<table style="width: 95%; margin-left: auto; margin-right: auto">

<!-- Mostrar las cabeceras -->

<tr>
<th>Ref.</th>
<th>Categoria</th>
<th>Producto</th>
<th>Descripción</th>
<th>Distribuidor</th>
<th>Comerciales</th>
<th>Precio</th>
<th>Unidad</th>
<th>Código de barras</th>
<th>Oferta</th>
<th>Más información</th>
</tr>

<!-- Listar productos -->

<xsl:for-each select="/productos/producto">

<!-- Ordenar por nº de referencia -->

<xsl:sort select="@referencia"/>

<!-- Mostrar una fila por cada producto -->

<tr style="background-color: silver; vertical-align: top">

<!-- Mostrar la referencia del producto -->

<td style="font-weight: bold"><xsl:value-of select="@referencia"/></td>

<!-- Cada categoría tiene un color de celda diferente -->

<xsl:choose>
<!-- Categoría LACTEOS: -->
<xsl:when test="@categoria = 'LACTEOS'">
<td style="text-align: center; background-color:white"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría HORTALIZAS: -->
<xsl:when test="@categoria = 'HORTALIZAS'">
<td style="text-align: center; background-color:green"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría ZUMOS: -->
<xsl:when test="@categoria = 'ZUMOS'">
<td style="text-align: center; background-color:yellow"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría REFRESCOS: -->
<xsl:when test="@categoria = 'REFRESCOS'">
<td style="text-align: center; background-color:red"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría COSMETICA: -->
<xsl:when test="@categoria = 'COSMETICA'">
<td style="text-align: center; background-color:FUCHSIA"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría AGUA: -->
<xsl:when test="@categoria = 'AGUA'">
<td style="text-align: center; background-color:blue"><xsl:value-of select="@categoria"/></td>
</xsl:when>
<!-- Categoría desconocida: Esto no debería ocurrir nunca. -->
<xsl:otherwise>
<td style="text-align: center; background-color:black"><xsl:value-of select="@categoria"/></td>
</xsl:otherwise>
</xsl:choose>

<!-- Mostrar nombre del producto y descripción -->

<td><xsl:value-of select="nombre"/></td>
<td><xsl:value-of select="descripcion"/></td>

<!-- Mostrar el nombre de la empresa distribuidora: primero
la razón social, y luego el CIF.
P. ej.: 'Aguas Barranqueras, S.A. - CIF: A2223335Y'
-->
<td>
<xsl:value-of select="distribuidor/empresa/razon_social"/>
- CIF:
<xsl:value-of select="distribuidor/empresa/cif"/>
</td>

<!-- Mostrar dentro de la misma celda los
nombres de todos los comerciales, separados por
comas y un punto al final.
Si el comercial tiene un nº de teléfono
asignado, mostrarlo junto al nombre.
P. ej.: 'Pepe Pozo, Juan Agüero tlf. 93444555.'

Si no hay comerciales, mostrar: 'No disponible'.
-->

<td>
<xsl:choose>

<!-- Si hay comerciales: -->
<xsl:when test="count(distribuidor/comerciales/comercial) > 0">
<xsl:for-each select="distribuidor/comerciales/comercial">
<xsl:value-of select="."/>
<xsl:if test="@tlf != ''">
tlf. <xsl:value-of select="@tlf"/>
</xsl:if>
<xsl:if test="position() != last()">, </xsl:if>
<xsl:if test="position() = last()">.</xsl:if>
</xsl:for-each>
</xsl:when>

<!-- Si no hay comerciales: -->
<xsl:otherwise>
No disponible
</xsl:otherwise>
</xsl:choose>
</td>

<!-- Mostrar el precio, y a continuación el símbolo del euro -->

<td style="text-align: right">
<xsl:value-of select="precio"/> €
</td>

<!-- Mostrar unidad, y código de barras -->

<td><xsl:value-of select="unidad"/></td>
<td><xsl:value-of select="codigo_barras"/></td>

<!-- Si el producto está en oferta, mostrarla en negrita.  -->

<xsl:if test="oferta != ''">
<td style="font-weight: bold; text-align: center">
<xsl:value-of select="oferta"/>
</td>
</xsl:if>

<!-- Si no está en oferta, mostrar un guión: '-' -->

<xsl:if test="oferta = ''">
<td style="text-align: center">-</td>
</xsl:if>

<!-- Mostrar la URL -->

<td><xsl:value-of select="mas_info"/></td>

</tr>
</xsl:for-each>
</table>

<!-- Mostrar el nombre del programa y copyright -->

<h2>
<xsl:value-of select="$programa"/> - <xsl:value-of select="$copyright"/>
</h2>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

No hay comentarios:

Publicar un comentario