<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" version="1.0">
  <xsl:import href="../../../appl/shared/default.xsl"/>
  <xsl:variable name="Rev">
    <!-- Revision van deze cust.xsl -->
    <xsl:value-of select="substring(translate('$Revision$', '$ ', ''), 10)"/>
  </xsl:variable>

	<xsl:template match="rapport">
    <xsl:if test="@view='kibe_v_rap_cntkst_unitgemloc'">
      <table class="rstable">
        <xsl:if test="count(rapport_data/data_row)=0">
          <tr><td><center><b>Geen gegevens gevonden</b></center></td></tr>
        </xsl:if>

        <xsl:variable name="min_unit">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_UNIT" order="ascending"/>
            <xsl:if test="position()=1"><xsl:value-of select="FCLT_F_UNIT"/></xsl:if>
          </xsl:for-each>
        </xsl:variable>
        <xsl:variable name="max_unit">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_UNIT" order="descending"/>
            <xsl:if test="position()=1"><xsl:value-of select="FCLT_F_UNIT"/></xsl:if>
          </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="sortedall">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_UNIT"/>
            <xsl:sort select="FCLT_F_GEMEENTE"/>
            <xsl:sort select="FCLT_F_VESTIGING"/>
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="row_count">
          <xsl:value-of select="count(msxml:node-set($sortedall)/data_row)"/>
        </xsl:variable>

        <xsl:for-each select="msxml:node-set($sortedall)/data_row">
          <xsl:variable name="prev_unit">
            <xsl:choose>
              <xsl:when test="position()=1">Quqelequ</xsl:when>
              <xsl:otherwise><xsl:value-of select="preceding-sibling::data_row[1]/FCLT_F_UNIT"/></xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <xsl:variable name="this_unit">
            <xsl:value-of select="FCLT_F_UNIT"/>
          </xsl:variable>

          <!--Als 'this' != 'prev', dan invoegen kop/som-regels!-->
          <xsl:if test="$this_unit!=$prev_unit">
            <xsl:if test="position()&gt;1">
              <xsl:variable name="prev_m2">
                <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/M2)"/>
              </xsl:variable>
              <xsl:variable name="prev_kp">
                <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/KINDPLAATSEN)"/>
              </xsl:variable>
              <xsl:variable name="prev_ob">
                <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/OMZETBEGROTING)"/>
              </xsl:variable>
              <tr>
                <!--td></td-->
                <td></td>
                <td></td>
                <td style="text-align:right;"><b><xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/KINDPLAATSEN)"/></b></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/OMZETBEGROTING), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/M2), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/HUUR_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/HUUR_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/SCHOONMAAK_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/SCHOONMAAK_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/ENERGIE_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/ENERGIE_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/OVERIG_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/OVERIG_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/TOT_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/TOT_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><xsl:if test="$prev_kp&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/TOT_JJ) div $prev_kp, '0,00', 'european')"/></b></xsl:if></td>
                <td style="text-align:right;"><xsl:if test="$prev_ob&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$prev_unit]/TOT_JJ) div $prev_ob * 100, '0,00', 'european')"/>%</b></xsl:if></td>
              </tr>
              <tr><td colspan="17" style="text-align:left">&#160;</td></tr>
            </xsl:if>
            <tr><td colspan="17" style="vertical-align:top;background-color:#f18e00"><b><xsl:value-of select="FCLT_F_UNIT"/></b></td></tr>
            <tr>
              <!--th rowspan="2" style="vertical-align:middle;border:1px solid white;">Unit</th-->
              <th rowspan="2" style="vertical-align:middle;border:1px solid white;">Gemeente</th>
              <th rowspan="2" style="vertical-align:middle;border:1px solid white;">Vestiging</th>
              <th rowspan="2" style="text-align:center;vertical-align:middle;border:1px solid white;">Kindpl.</th>
              <th rowspan="2" style="text-align:center;vertical-align:middle;border:1px solid white;">Omzet</th>
              <th rowspan="2" style="text-align:center;vertical-align:middle;border:1px solid white;">Opp.</th>
              <th colspan="2" style="text-align:center;border:1px solid white;">Kosten Huur</th>
              <th colspan="2" style="text-align:center;border:1px solid white;">Kosten Schoonmaak</th>
              <th colspan="2" style="text-align:center;border:1px solid white;">Kosten Energie</th>
              <th colspan="2" style="text-align:center;border:1px solid white;">Kosten Overig</th>
              <th colspan="4" style="text-align:center;border:1px solid white;">Kosten Totaal</th>
            </tr>
            <tr>
              <!--th colspan="6" style="border:1px solid white;"></th-->
              <th style="text-align:center;border:1px solid white;">Per jr.</th>
              <th style="text-align:center;border:1px solid white;">Per m2</th>
              <th style="text-align:center;border:1px solid white;">Per jr.</th>
              <th style="text-align:center;border:1px solid white;">Per m2</th>
              <th style="text-align:center;border:1px solid white;">Per jr.</th>
              <th style="text-align:center;border:1px solid white;">Per m2</th>
              <th style="text-align:center;border:1px solid white;">Per jr.</th>
              <th style="text-align:center;border:1px solid white;">Per m2</th>
              <th style="text-align:center;border:1px solid white;">Per jr.</th>
              <th style="text-align:center;border:1px solid white;">Per m2</th>
              <th style="text-align:center;border:1px solid white;">Per kp.</th>
              <th style="text-align:center;border:1px solid white;">% omzet</th>
            </tr>
          </xsl:if>

          <!--Feitelijk data-regel=vestiging-regel!-->
          <tr>
            <!--td><xsl:value-of select="FCLT_F_UNIT"/></td-->
            <td><xsl:value-of select="FCLT_F_GEMEENTE"/></td>
            <td><xsl:value-of select="FCLT_F_VESTIGING"/></td>
            <td style="text-align:right;"><xsl:if test="KINDPLAATSEN!=''"><xsl:value-of select="KINDPLAATSEN"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="OMZETBEGROTING!=''"><xsl:value-of select="format-number(OMZETBEGROTING, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="M2!=''"><xsl:value-of select="format-number(M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="HUUR_JJ!=''"><xsl:value-of select="format-number(HUUR_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="HUUR_M2!=''"><xsl:value-of select="format-number(HUUR_M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="SCHOONMAAK_JJ!=''"><xsl:value-of select="format-number(SCHOONMAAK_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="SCHOONMAAK_M2!=''"><xsl:value-of select="format-number(SCHOONMAAK_M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="ENERGIE_JJ!=''"><xsl:value-of select="format-number(ENERGIE_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="ENERGIE_M2!=''"><xsl:value-of select="format-number(ENERGIE_M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="OVERIG_JJ!=''"><xsl:value-of select="format-number(OVERIG_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="OVERIG_M2!=''"><xsl:value-of select="format-number(OVERIG_M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="TOT_JJ!=''"><xsl:value-of select="format-number(TOT_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="TOT_M2!=''"><xsl:value-of select="format-number(TOT_M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="TOT_KP!=''"><xsl:value-of select="format-number(TOT_KP, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="TOT_PERC!=''"><xsl:value-of select="format-number(TOT_PERC, '0,00', 'european')"/>%</xsl:if></td>
          </tr>

          <!--Als laatste regel, dan invoegen laatste som-regel!-->
          <xsl:if test="position()=$row_count">
            <xsl:variable name="this_m2">
              <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/M2)"/>
            </xsl:variable>
            <xsl:variable name="this_kp">
              <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/KINDPLAATSEN)"/>
            </xsl:variable>
            <xsl:variable name="this_ob">
              <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/OMZETBEGROTING)"/>
            </xsl:variable>
            <tr>
              <!--td></td-->
              <td></td>
              <td></td>
              <td style="text-align:right;"><b><xsl:value-of select="sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/KINDPLAATSEN)"/></b></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/OMZETBEGROTING), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/M2), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/HUUR_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/HUUR_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/SCHOONMAAK_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/SCHOONMAAK_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/ENERGIE_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/ENERGIE_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/OVERIG_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/OVERIG_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/TOT_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/TOT_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><xsl:if test="$this_kp&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/TOT_JJ) div $this_kp, '0,00', 'european')"/></b></xsl:if></td>
              <td style="text-align:right;"><xsl:if test="$this_ob&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_UNIT=$this_unit]/TOT_JJ) div $this_ob * 100, '0,00', 'european')"/>%</b></xsl:if></td>
            </tr>
          </xsl:if>
        </xsl:for-each>

        <!--Als >1 units, dan totaalsom-regel!-->
        <xsl:if test="$min_unit!=$max_unit">
          <xsl:variable name="tot_m2">
            <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row/M2)"/>
          </xsl:variable>
          <xsl:variable name="tot_kp">
            <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row/KINDPLAATSEN)"/>
          </xsl:variable>
          <xsl:variable name="tot_ob">
            <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row/OMZETBEGROTING)"/>
          </xsl:variable>
          <tr>
            <td colspan="2"><b>TOTAAL GENERAAL</b></td>
            <td style="text-align:right;"><b><xsl:value-of select="sum(msxml:node-set($sortedall)/data_row/KINDPLAATSEN)"/></b></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/OMZETBEGROTING), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/M2), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/HUUR_JJ), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><xsl:if test="$tot_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/HUUR_JJ) div $tot_m2, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/SCHOONMAAK_JJ), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><xsl:if test="$tot_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/SCHOONMAAK_JJ) div $tot_m2, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/ENERGIE_JJ), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><xsl:if test="$tot_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/ENERGIE_JJ) div $tot_m2, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/OVERIG_JJ), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><xsl:if test="$tot_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/OVERIG_JJ) div $tot_m2, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/TOT_JJ), '0,00', 'european')"/></b></td>
            <td style="text-align:right;"><xsl:if test="$tot_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/TOT_JJ) div $tot_m2, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="$tot_kp&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/TOT_JJ) div $tot_kp, '0,00', 'european')"/></b></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="$tot_ob&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/TOT_JJ) div $tot_ob * 100, '0,00', 'european')"/>%</b></xsl:if></td>
          </tr>
        </xsl:if>
      </table>
    </xsl:if>

    <xsl:if test="@view='kibe_v_rap_cntkst_bedrsrtloc'">
      <table class="rstable">
        <xsl:if test="count(rapport_data/data_row)=0">
          <tr><td><center><b>Geen gegevens gevonden</b></center></td></tr>
        </xsl:if>

        <xsl:variable name="min_bedr">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_BEDRIJF" order="ascending"/>
            <xsl:if test="position()=1"><xsl:value-of select="FCLT_F_BEDRIJF"/></xsl:if>
          </xsl:for-each>
        </xsl:variable>
        <xsl:variable name="max_bedr">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_BEDRIJF" order="descending"/>
            <xsl:if test="position()=1"><xsl:value-of select="FCLT_F_BEDRIJF"/></xsl:if>
          </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="sortedall">
          <xsl:for-each select="rapport_data/data_row">
            <xsl:sort select="FCLT_F_BEDRIJF"/>
            <xsl:sort select="FCLT_F_CONTRACTSOORT"/>
            <xsl:sort select="FCLT_F_VESTIGING"/>
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="row_count">
          <xsl:value-of select="count(msxml:node-set($sortedall)/data_row)"/>
        </xsl:variable>

        <xsl:for-each select="msxml:node-set($sortedall)/data_row">
          <xsl:variable name="prev_bedr">
            <xsl:choose>
              <xsl:when test="position()=1">Quqelequ</xsl:when>
              <xsl:otherwise><xsl:value-of select="preceding-sibling::data_row[1]/FCLT_F_BEDRIJF"/></xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <xsl:variable name="this_bedr">
            <xsl:value-of select="FCLT_F_BEDRIJF"/>
          </xsl:variable>

          <!--Als 'this' != 'prev', dan invoegen kop/som-regels!-->
          <xsl:if test="$this_bedr!=$prev_bedr">
            <xsl:if test="position()&gt;1">
              <xsl:variable name="prev_m2">
                <xsl:value-of select="msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$prev_bedr]/M2"/>
              </xsl:variable>
              <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$prev_bedr]/M2), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$prev_bedr]/KOSTEN_JJ), '0,00', 'european')"/></b></td>
                <td style="text-align:right;"><xsl:if test="$prev_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$prev_bedr]/KOSTEN_JJ) div $prev_m2, '0,00', 'european')"/></b></xsl:if></td>
              </tr>
              <tr><td colspan="7" style="text-align:left">&#160;</td></tr>
            </xsl:if>
            <tr><td colspan="7" style="background-color:#f18e00"><b><xsl:value-of select="FCLT_F_BEDRIJF"/></b></td></tr>
            <tr>
              <th style="border:1px solid white;">Bedrijf</th>
              <th style="border:1px solid white;">Contractsoort</th>
              <th style="border:1px solid white;">Einddatum</th>
              <th style="border:1px solid white;">Vestiging</th>
              <th style="text-align:right;border:1px solid white;">Opp.</th>
              <th style="text-align:right;border:1px solid white;">Per jr.</th>
              <th style="text-align:right;border:1px solid white;">Per m2</th>
            </tr>
          </xsl:if>

          <!--Feitelijk data-regel=vestiging-regel!-->
          <tr>
            <td><xsl:value-of select="FCLT_F_BEDRIJF"/></td>
            <td><xsl:value-of select="FCLT_F_CONTRACTSOORT"/></td>
            <td><xsl:value-of select="EINDDATUM"/></td>
            <td><xsl:value-of select="FCLT_F_VESTIGING"/></td>
            <td style="text-align:right;"><xsl:if test="M2!=''"><xsl:value-of select="format-number(M2, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="KOSTEN_JJ!=''"><xsl:value-of select="format-number(KOSTEN_JJ, '0,00', 'european')"/></xsl:if></td>
            <td style="text-align:right;"><xsl:if test="KOSTEN_M2!=''"><xsl:value-of select="format-number(KOSTEN_M2, '0,00', 'european')"/></xsl:if></td>
          </tr>

          <!--Als laatste regel, dan invoegen laatste som-regel!-->
          <xsl:if test="position()=$row_count">
            <xsl:variable name="this_m2">
              <xsl:value-of select="msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$this_bedr]/M2"/>
            </xsl:variable>
            <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$this_bedr]/M2), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$this_bedr]/KOSTEN_JJ), '0,00', 'european')"/></b></td>
              <td style="text-align:right;"><xsl:if test="$this_m2&gt;0"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row[FCLT_F_BEDRIJF=$this_bedr]/KOSTEN_JJ) div $this_m2, '0,00', 'european')"/></b></xsl:if></td>
            </tr>
          </xsl:if>
        </xsl:for-each>

        <!--Als >1 bedrijven, dan totaalsom-regel!-->
        <!--xsl:if test="$min_bedr!=$max_bedr">
          <xsl:variable name="tot_m2">
            <xsl:value-of select="sum(msxml:node-set($sortedall)/data_row/M2)"/>
          </xsl:variable>
          <tr>
            <td colspan="4"><b>TOTAAL GENERAAL</b></td>
            <td></td>
            <td style="text-align:right;"><b><xsl:value-of select="format-number(sum(msxml:node-set($sortedall)/data_row/KOSTEN_JJ), '0,00', 'european')"/></b></td>
            <td></td>
          </tr>
        </xsl:if-->
      </table>
    </xsl:if>
	</xsl:template>
</xsl:stylesheet>
