﻿<?xml version="1.0"?>
<!--                                   -->
<!-- Last update: 23 February 2012     -->
<!-- Copyright (c) 2009-2011 O. Narat. -->
<!-- All rights reserved.              -->
<!--                                   -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <!--                                                                           -->
    <xsl:variable name="width_col_1" select="80"/>
    <xsl:variable name="width_col_2" select="160"/>
    <xsl:variable name="width_col_3" select="80"/>
    <xsl:variable name="width_col_4" select="320"/>
    <xsl:variable name="size_img_col_2" select="80"/>
    <xsl:variable name="size_img_col_4" select="160"/>
    <xsl:variable name="n_philosophers" select="count(philosophers/philosopher)"/>
    <!--                                                                           -->
    <html>
      <head>
        <title>Philosophers (<xsl:value-of select="$n_philosophers"/>)</title>
        <link rel="stylesheet" type="text/css" href="../../style/style.css"/>
      </head>
      <body>
        <p align="center" style="text-align:center;">
          <h1 align="center" style="text-align:center;">Philosophers</h1>
          <table border="1" align="center" style="text-align:center;">
            <tr align="center" style="font: normal bold 10.0pt verdana, sans-serif;text-align:center;">
              <th>
                <xsl:attribute name="width"><xsl:value-of select="$width_col_1"/></xsl:attribute>
                #
              </th>
              <th>
                <xsl:attribute name="width"><xsl:value-of select="$width_col_2"/></xsl:attribute>
                Philosopher <br/>(<xsl:value-of select="$n_philosophers"/> philosophers)
              </th>
              <th>
                <xsl:attribute name="width"><xsl:value-of select="$width_col_3"/></xsl:attribute>
                Country
              </th>
              <th>
                <xsl:attribute name="width"><xsl:value-of select="$width_col_4"/></xsl:attribute>
                Images / quotes
              </th>
            </tr>
            <!--               -->
            <!-- for-each loop -->
            <!--               -->
            <xsl:for-each select="philosophers/philosopher">
              <!--                                                                           -->
              <!-- !!!! variable for position() is mandatory for Opera Internet Browser !!!! -->
              <!--                                                                           -->
              <xsl:variable name="position" select="position()"/>
              <!--                                                                           -->
              <xsl:variable name="last" select="last()"/>
              <xsl:variable name="name" select="name"/>
              <xsl:variable name="fullName" select="fullName"/>
              <xsl:variable name="country" select="country"/>
              <xsl:variable name="philosopher" select="document(concat($name, '.xml'))/philosopher"/>
              <xsl:variable name="n_img" select="count($philosopher/img)"/>
              <xsl:variable name="src_quotes" select="$philosopher/src_quotes[@language='en']"/>
              <xsl:variable name="quotes" select="document($src_quotes)/quotes"/>
              <xsl:variable name="n_quotes" select="count($quotes/quote)"/>
              <!--                                                                           -->
              <tr align="left" style="font: normal normal 10.0pt verdana, sans-serif;text-align:left;">
                <!--   -->
                <!-- # -->
                <!--   -->
                <td>
                  <xsl:attribute name="width"><xsl:value-of select="$width_col_1"/></xsl:attribute>
                  <p>
                    # <xsl:value-of select="format-number($position, '00')"/> / <xsl:value-of select="$last"/>
                  </p>
                </td>
                <!--             -->
                <!-- Philosopher -->
                <!--             -->
                <td align="center" style="font: normal normal 10.0pt verdana, sans-serif;text-align:center;">
                  <xsl:attribute name="width"><xsl:value-of select="$width_col_2"/></xsl:attribute>
                  <p>
                    <img>
                      <xsl:attribute name="width"><xsl:value-of select="$size_img_col_2"/></xsl:attribute>
                      <xsl:attribute name="height"><xsl:value-of select="$size_img_col_2"/></xsl:attribute>
                      <xsl:attribute name="src"><xsl:value-of select="$name"/>.gif</xsl:attribute>
                      <xsl:attribute name="alt"><xsl:value-of select="$fullName"/></xsl:attribute>
                      <xsl:attribute name="title"><xsl:value-of select="$fullName"/></xsl:attribute>
                    </img>
                    <br/>
                    <xsl:value-of select="$fullName"/>
                  </p>
                </td>
                <!--         -->
                <!-- Country -->
                <!--         -->
                <td align="center" style="font: normal normal 10.0pt verdana, sans-serif;text-align:center;">
                  <xsl:attribute name="width"><xsl:value-of select="$width_col_3"/></xsl:attribute>
                  <p>
                    <img>
                      <xsl:attribute name="src">../flags/<xsl:value-of select="$country"/>.gif</xsl:attribute>
                      <xsl:attribute name="alt"><xsl:value-of select="$country"/></xsl:attribute>
                      <xsl:attribute name="title"><xsl:value-of select="$country"/></xsl:attribute>
                    </img>
                  </p>
                </td>
                <!--                 -->
                <!-- Images / quotes -->
                <!--                 -->
                <td>
                  <xsl:attribute name="width"><xsl:value-of select="$width_col_4"/></xsl:attribute>
                  <xsl:if test="$n_img > 0">
                    <xsl:variable name="img" select="$philosopher/img[1]"/>
                    <xsl:variable name="src" select="$img/src"/>
                    <xsl:variable name="caption" select="$img/caption[@language='en']"/>
                    <a>
                      <xsl:attribute name="href"><xsl:value-of select="$src"/></xsl:attribute>
                      <img>
                        <xsl:attribute name="width"><xsl:value-of select="$size_img_col_4"/></xsl:attribute>
                        <xsl:attribute name="height"><xsl:value-of select="$size_img_col_4"/></xsl:attribute>
                        <xsl:attribute name="src"><xsl:value-of select="$src"/></xsl:attribute>
                        <xsl:attribute name="alt"><xsl:value-of select="$caption"/></xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="$caption"/></xsl:attribute>
                      </img>
                    </a>
                  </xsl:if>
                  <xsl:if test="$n_img > 1">
                    <xsl:variable name="img" select="$philosopher/img[2]"/>
                    <xsl:variable name="src" select="$img/src"/>
                    <xsl:variable name="caption" select="$img/caption[@language='en']"/>
                    <a>
                      <xsl:attribute name="href"><xsl:value-of select="$src"/></xsl:attribute>
                      <img>
                        <xsl:attribute name="width"><xsl:value-of select="$size_img_col_4"/></xsl:attribute>
                        <xsl:attribute name="height"><xsl:value-of select="$size_img_col_4"/></xsl:attribute>
                        <xsl:attribute name="src"><xsl:value-of select="$src"/></xsl:attribute>
                        <xsl:attribute name="alt"><xsl:value-of select="$caption"/></xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="$caption"/></xsl:attribute>
                      </img>
                    </a>
                  </xsl:if>
                  <br/>
                  <br/>
                  <xsl:if test="$n_img > 2">
                    <a>
                      <xsl:attribute name="href"><xsl:value-of select="concat($name, '.xml')"/></xsl:attribute>
                      Other images (<xsl:value-of select="$n_img"/>)...
                    </a>
                    <br/>
                    <br/>
                  </xsl:if>
                  <xsl:if test="$n_quotes > 0">
                    <xsl:value-of select="$quotes/quote[1]"/>
                    <br/>
                    <br/>
                  </xsl:if>
                  <xsl:if test="$n_quotes > 1">
                    <a>
                      <xsl:attribute name="href"><xsl:value-of select="$src_quotes"/></xsl:attribute>
                      Other quotes (<xsl:value-of select="$n_quotes"/>)...
                    </a>
                    <br/>
                    <br/>
                  </xsl:if>
                </td>
              </tr>
            </xsl:for-each>
            <!--                      -->
            <!-- end of for-each loop -->
            <!--                      -->
          </table>
        </p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

