<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcq="http://purl.org/dc/qualifiers/1.0/" xmlns:math="http://exslt.org/math" xmlns:set="http://exslt.org/sets" xmlns:date="http://exslt.org/dates-and-times" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl date math set" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!--
<xsl:import href="/www/ximsroot/skins/default/stylesheets/simpledb_default.xsl"/>
-->
<!--
<xsl:import href="http://www.uibk.ac.at/ionen-angewandte-physik/stylesheets/include/common.xsl"/>
<xsl:import href="http://www.uibk.ac.at/ionen-angewandte-physik/stylesheets/include/iap.xsl"/>
-->
<xsl:import href="nanobio.xsl"/>
<!--
<xsl:import href="/www/ximspubroot/uniweb/ionen-angewandte-physik/stylesheets/default.xsl"/>
-->

<xsl:output method="xml" encoding="iso-8859-1" media-type="text/html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="no"/>
<xsl:param name="onepage" select="1"/>
<xsl:param name="request.uri"/>
<xsl:param name="wantedyear"/>
<xsl:param name="wantedmonth"/>

<xsl:variable name="datepropid" select="/document/member_properties/member_property[name='date']/@id"/>
<xsl:variable name="operatorpropid" select="/document/member_properties/member_property[name='operator']/@id"/>
<xsl:variable name="typepropid" select="/document/member_properties/member_property[name='type']/@id"/>
<xsl:variable name="shortpropid" select="/document/member_properties/member_property[name='short']/@id"/>
<xsl:variable name="longpropid" select="/document/member_properties/member_property[name='long']/@id"/>
<xsl:variable name="runpropid" select="/document/member_properties/member_property[name='run']/@id"/>
<xsl:variable name="scpropid" select="/document/member_properties/member_property[name='scancycle']/@id"/>

<xsl:variable name="path_to_db" select="/document/context/object/location_path"/>
<xsl:variable name="currentyear" select="date:year()"/>
<xsl:variable name="currentmonth" select="date:month-in-year()"/>

<xsl:variable name="months">
    <xsl:for-each select="/document/context/object/children/object/member_values/member_value[property_id=$datepropid]/value">
        <month><xsl:value-of select="substring(.,1,7)"/>
            <jahr><xsl:value-of select="date:year(substring(.,1,7))"/></jahr>
            <monat><xsl:value-of select="date:month-name(substring(.,1,7))"/></monat>
            <monatzahl><xsl:value-of select="date:month-in-year(substring(.,1,7))"/></monatzahl>
        </month>
    </xsl:for-each>
</xsl:variable>
<xsl:variable name="days">
    <xsl:for-each select="/document/context/object/children/object">
        <day><xsl:value-of select="substring(member_values/member_value[property_id=$datepropid]/value,1,10)"/>
            <jahr><xsl:value-of select="date:year(substring(member_values/member_value[property_id=$datepropid]/value,1,10))"/></jahr>
            <monat><xsl:value-of select="date:month-name(substring(member_values/member_value[property_id=$datepropid]/value,1,10))"/></monat>
            <monatzahl><xsl:value-of select="date:month-in-year(substring(member_values/member_value[property_id=$datepropid]/value,1,10))"/></monatzahl>
            <tag><xsl:value-of select="date:day-in-month(substring(member_values/member_value[property_id=$datepropid]/value,1,10))"/></tag>
            <eintrag_loc><xsl:value-of select="location"/></eintrag_loc>
            <eintrag_type><xsl:value-of select="member_values/member_value[property_id=$typepropid]/value"/></eintrag_type>
        </day>
    </xsl:for-each>
</xsl:variable>

<xsl:template match="/document/context/object">
    <html>
        <head>
            <xsl:call-template name="meta"/>
            <link type="text/css" rel="stylesheet" href="http://www.uibk.ac.at/stylesheets/default.css"/>
            <link type="text/css" rel="stylesheet" href="http://www.uibk.ac.at/ionen-angewandte-physik/stylesheets/ionen.css"/>
        <title>
            <xsl:value-of select="title"/> - Institut für Ionenphysik und Angewandte Physik - Universität Innsbruck
        </title>
        </head>
	<body>
            <xsl:comment>UdmComment</xsl:comment>
            <table width="100%">
                <xsl:call-template name="iap_header_xims"/>
            </table>
            <h1><xsl:value-of select="title"/></h1>
            <table width="100%">
                <tbody>
                    <tr><td><h2>All entries sorted by date</h2></td>
                        <td><h2>Last entries</h2></td>
                    </tr>
                    <tr><td valign="top">
                    <xsl:choose>
                        <xsl:when test="$wantedyear != ''">
                            <xsl:call-template name="tagliste">
                                <xsl:with-param name="wantedyear" select="$wantedyear"/>
                                <xsl:with-param name="wantedmonth" select="$wantedmonth"/>
                            </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="monatsliste"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    </td>
                    <td><table valign="top">
                        <thead>
                            <tr><td>Date</td><td>Operator</td><td>Type</td><td>Short</td><td>Run</td><td>Scan Cycle</td></tr>
                        </thead>
                        <tbody>
                            <xsl:apply-templates select="children/object">
                                <xsl:sort select="translate(title,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" order="ascending"/>
                            </xsl:apply-templates>
                        </tbody>
                    </table></td></tr>
                </tbody>
            </table>
        </body>
    </html>
</xsl:template>

<!--<xsl:template name="childrenlist">
    <table width="100%">
        <thead>
        <tr><td>Date</td><td>Operator</td><td>Type</td><td>Short</td></tr>
        </thead>
        <tbody>
        <xsl:apply-templates select="children/object">
            <xsl:sort select="translate(title,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" order="ascending"/>
        </xsl:apply-templates>
        </tbody>
    </table>
</xsl:template>-->

<xsl:template match="children/object">
    <tr>
        <td><a href="http://xims.uibk.ac.at{$goxims_stay}{$path_to_db}/{location}">
         <xsl:value-of select="substring-before(member_values/member_value[property_id=$datepropid]/value,' ')"/>
        </a>
        </td>
        <td><xsl:value-of select="member_values/member_value[property_id=$operatorpropid]/value"/></td>
        <td><xsl:value-of select="member_values/member_value[property_id=$typepropid]/value"/></td>
        <td><xsl:value-of select="member_values/member_value[property_id=$shortpropid]/value"/></td>
        <td><xsl:value-of select="member_values/member_value[property_id=$runpropid]/value"/></td>
        <td><xsl:value-of select="member_values/member_value[property_id=$scpropid]/value"/></td>
    </tr>
</xsl:template>

<xsl:template name="monatsliste">
    <xsl:for-each select="set:distinct(exsl:node-set($months)/month)">
        <xsl:sort select="jahr" order="descending" data-type="number"/>
        <xsl:sort select="monatzahl" order="descending" data-type="number"/>
        <a href="?wantedyear={jahr};wantedmonth={monatzahl}"><xsl:value-of select="concat(jahr,'-',monat)"/></a><br/>
    </xsl:for-each>
</xsl:template>

<xsl:template name="tagliste">
    <xsl:param name="wantedyear" select="$currentyear"/>
    <xsl:param name="wantedmonth" select="$currentmonth"/>
    <xsl:for-each select="exsl:node-set($days)/day/jahr[text() = $wantedyear]">
        <xsl:sort select="tag" order="ascending" data-type="number"/>
        <xsl:if test="../monatzahl/text() = $wantedmonth">
            <a title="" href="http://xims.uibk.ac.at{$goxims_stay}{$path_to_db}/{../eintrag_loc}">
                <xsl:value-of select="concat(.,'-',../monat,'-',../tag)"/>
            </a><xsl:text>: </xsl:text><xsl:value-of select="../eintrag_type"/><br/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

<xsl:template name="simpledbmembertitle">
    <span class="simpledb_membertitle">
        <a title="{location}" href="http://xims.uibk.ac.at{$goxims_content}{$absolute_path}/{location}">
            <xsl:value-of select="title"/>
        </a>
    </span>
</xsl:template>
</xsl:stylesheet>