view flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl @ 3359:7b601099db10

FixA: Overview: Added legend at bottom of overview table. flys-client/trunk@5046 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 18 Jul 2012 17:05:02 +0000
parents 6d96443ed6e6
children 89df168f289c
line wrap: on
line source
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="UTF-8"/>

  <xsl:param name="project-uuid">de3f3307-3429-4ff9-8f43-3fb2fcf21b27</xsl:param>
  <xsl:param name="render-checkboxes" select="true()"/>
  <xsl:param name="callback"/>

  <xsl:template match="@*" mode="min">
    <xsl:if test="position() = 1">
      <xsl:value-of select="number(.)"/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="@*" mode="max">
    <xsl:if test="position() = last()">
      <xsl:value-of select="number(.)"/>
    </xsl:if>
  </xsl:template>

  <xsl:variable name="events-min">
    <xsl:choose>
      <xsl:when test="count(/fixings/events/event/sector) &gt; 0">
        <xsl:apply-templates mode="min" select="/fixings/events/event/sector/@from">
          <xsl:sort data-type="number" select="."/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="number(/fixings/river/@from)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="events-max">
    <xsl:choose>
      <xsl:when test="count(/fixings/events/event/sector) &gt; 0">
        <xsl:apply-templates mode="max" select="/fixings/events/event/sector/@to">
          <xsl:sort data-type="number" select="."/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="number(/fixings/river/@to)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:template name="percent">
    <xsl:param name="sector"/>
    <xsl:variable name="rfrom" select="number($events-min)"/>
    <xsl:variable name="rto" select="number($events-max)"/>
    <xsl:variable name="rlength" select="$rto - $rfrom"/>

    <xsl:variable name="sfrom" select="number($sector/@from)"/>
    <xsl:variable name="sto" select="number($sector/@to)"/>
    <xsl:variable name="slength" select="$sto - $sfrom"/>
    <xsl:value-of select="100.0 * ($slength div $rlength)"/>
  </xsl:template>

  <xsl:template name="emit-gap">
    <xsl:param name="sector"/>
    <xsl:variable name="preds" select="$sector/preceding-sibling::sector"/>
    <xsl:variable name="num-preds" select="count($preds)"/>
    <xsl:variable name="glength">
      <xsl:choose>
        <xsl:when test="$num-preds &lt; 1">
          <xsl:variable name="rfrom" select="number($events-min)"/>
          <xsl:value-of select="number($sector/@from) - $rfrom"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="bend" select="number($preds[last()]/@to)"/>
          <xsl:value-of select="number($sector/@from) - $bend"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="number($glength) &lt; 0.05 "/>
      <xsl:otherwise>
        <div>
          <xsl:attribute name="style">
            <xsl:text>width:</xsl:text>
              <xsl:variable name="rfrom" select="number($events-min)"/>
              <xsl:variable name="rto" select="number($events-max)"/>
              <xsl:variable name="rlength" select="$rto - $rfrom"/>
              <xsl:value-of select="100.0 * ($glength div $rlength)"/>
            <xsl:text>%;float:left</xsl:text>
          </xsl:attribute>
          <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="sector" mode="sectors">
    <xsl:call-template name="emit-gap">
      <xsl:with-param name="sector" select="."/>
    </xsl:call-template>
    <div>
      <xsl:attribute name="style">
        <xsl:text>background:</xsl:text>
        <xsl:choose>
          <xsl:when test="@class = '0'">green</xsl:when>
          <xsl:when test="@class = '1'">blue</xsl:when>
          <xsl:when test="@class = '2'">magenta</xsl:when>
          <xsl:when test="@class = '3'">red</xsl:when>
          <xsl:otherwise>black</xsl:otherwise>
        </xsl:choose>
        <xsl:text>;width:</xsl:text>
        <xsl:call-template name="percent">
          <xsl:with-param name="sector" select="."/>
        </xsl:call-template>
        <xsl:text>%</xsl:text>
        <xsl:text>;float:left</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:text>km </xsl:text>
        <xsl:value-of select="@from"/>
        <xsl:text> - </xsl:text>
        <xsl:value-of select="@to"/>
        <xsl:choose>
          <xsl:when test="@class = '0'"> / Q um MNQ</xsl:when>
          <xsl:when test="@class = '1'"> / Q um MQ</xsl:when>
          <xsl:when test="@class = '2'"> / Q um MHQ</xsl:when>
          <xsl:when test="@class = '3'"> / Q über HQ5</xsl:when>
        </xsl:choose>
      </xsl:attribute>
      <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
    </div>
  </xsl:template>

  <xsl:template match="event">
    <tr id="{@cid}">
      <xsl:if test="$render-checkboxes">
        <td>
          <input type="checkbox" name="{$project-uuid}:{@cid}" checked="true" onclick="{$callback}"/>
        </td>
      </xsl:if>
      <td>
        <xsl:apply-templates mode="sectors"/>
      </td>
      <td align="center">
        <xsl:attribute name="title"><xsl:value-of select="@description"/></xsl:attribute>
        <xsl:value-of select="@date"/>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="events">
    <table width="97%" border="1" cellspacing="0" cellpadding="0"
           style="font-size: 10pt;font-family:Arial;Verdana,sans-serif">
      <colgroup>
        <xsl:if test="$render-checkboxes">
            <col width="20px"/>
        </xsl:if>
        <col width="*"/>
        <col width="75px"/>
      </colgroup>
      <tr>
        <xsl:if test="$render-checkboxes">
          <th>&#160;</th>
        </xsl:if>
        <th>km <xsl:value-of select="$events-min"/> - <xsl:value-of select="$events-max"/></th>
        <th>Ereignis</th>
      </tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>

  <xsl:template match="/">
    <xsl:apply-templates/>
    <hr/>
    <table border="1" cellspacing="0" cellpadding="0">
      <caption>Legende</caption>
      <tr>
        <th>Farbe</th>
        <th colspan="2">Bedeutung</th>
      </tr>
      <tr>
        <td style="background: green">&#160;</td>
        <td>um MNQ</td>
        <td>Q &#8712; [0, (MNQ+MQ)/2)</td>
      </tr>
      <tr>
        <td style="background: blue">&#160;</td>
        <td>um MQ</td>
        <td>Q &#8712; [(MNQ+MQ)/2, (MQ+MHQ)/2)</td>
      </tr>
      <tr>
        <td style="background: magenta">&#160;</td>
        <td>um MHQ</td>
        <td>Q &#8712; [(MQ+MHQ)/2, HQ5)</td>
      </tr>
      <tr>
        <td style="background: red">&#160;</td>
        <td>über HQ5</td>
        <td>Q &#8712; [HQ5, &#8734;)</td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template match="text()"/>
  <xsl:template match="text()" mode="sectors"/>

</xsl:stylesheet>

http://dive4elements.wald.intevation.org