view flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl @ 2912:329db21372ba

FixA: Extent of overview is determined by min/max km of sectors. flys-client/trunk@4733 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jun 2012 17:30:42 +0000
parents 7715324132bf
children 6d96443ed6e6
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 &#8712; [0, (MNQ+MQ)/2) </xsl:when>
          <xsl:when test="@class = '1'"> / Q &#8712; [(MNQ+MQ)/2, (MQ+MHQ)/2)</xsl:when>
          <xsl:when test="@class = '2'"> / Q &#8712; [(MQ+MHQ)/2, HQ5)</xsl:when>
          <xsl:when test="@class = '3'"> / Q &#8712; [HQ5, &#8734;)</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="95%" border="1" cellspacing="0" cellpadding="0"
           style="font-size: 11pt;font-family:Arial;Verdana,sans-serif">
      <colgroup>
        <xsl:if test="$render-checkboxes">
            <col width="20px"/>
        </xsl:if>
        <col width="*"/>
        <col width="90px"/>
      </colgroup>
      <tr>
        <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/>
  </xsl:template>

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

</xsl:stylesheet>

http://dive4elements.wald.intevation.org