Your IP : 18.220.152.28


Current Path : /usr/local/mgr5/skins/dragon/
Upload File :
Current File : //usr/local/mgr5/skins/dragon/print.xsl

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:mgr="http://ispsystem.com/xslplugin" xmlns:xdsl="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes="mgr">
  <xsl:import href="extfunc.xsl"/>
  <xsl:output method="html" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
  <xsl:variable name="meta" select="/doc/metadata"/>
  <xsl:variable name="msg" select="/doc/messages"/>
  <xsl:variable name="commondir">/manimg/common/</xsl:variable>
  <xsl:variable name="binary" select="/doc/@binary"/>
  <xsl:variable name="host" select="/doc/@host"/>
  <xsl:variable name="basehref" select="/doc/basehref"/>
 
  <xsl:variable name="theme" select="/doc/@theme"/>
  <xsl:key name="msg" match="/doc/messages/msg" use="@name"/>
  <xsl:template match="/" priority="100">
    <html>
      <head>
        <xsl:if test="$basehref != ''"><base href="{$basehref}"/></xsl:if>
        <link rel="stylesheet" media="screen, print" href="{$commondir}css/print-version.css" type="text/css"/>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <title><xsl:value-of select="key('msg', 'title')"/></title>
      </head>
      <body>
        <xsl:choose>
          <xsl:when test="not(metadata) and error">
            <div id="fatal-error-tab1" class="b-fatal-error">
              <div class="b-fatal-error__round">
                <div class="b-fatal-error__inner">
                  <div class="b-fatal-error__sign">
                    <div class="b-fatal-error__sign-top"><xsl:text> </xsl:text></div>
                    <div class="b-fatal-error__sign-body"><xsl:text> </xsl:text></div>
                    <div class="b-fatal-error__sign-empty"><xsl:text> </xsl:text></div>
                    <div class="b-fatal-error__sign-dot"><xsl:text> </xsl:text></div>
                  </div>
                  <div class="b-fatal-error__message"><xsl:value-of select="/doc/error/msg"/></div>
                </div>
               </div>
             <div class="b-fatal-error__triangle"></div>
            </div>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="$meta/@type = 'list'">
                <h1 class="b-title"><xsl:value-of select="$msg/msg[@name = 'title']"/></h1>
                <xsl:call-template name="list"/>
              </xsl:when>
              <xsl:when test="$meta/@type = 'report'">
                <script type="text/javascript" src="https://www.google.com/jsapi"></script>
                <script type="text/javascript">
                  var renderChartArr = [];
                  document.addEventListener("DOMContentLoaded", function() {
                    google.load('visualization', '1', { 'callback': 'console.log("2 sec wait")', 'packages': ['corechart'] });
                    checkChartLoad();
                    //getConvert();
                  }, false);

                  var timeInt;
                  function checkChartLoad() {
                    if (google.visualization !== undefined &amp;&amp; google.visualization.arrayToDataTable !== undefined) {
                      var l = renderChartArr.length;
                      while(l--) {
                        renderChart(renderChartArr[l]);
                      }
                    } else {
                      setTimeout(function(){
                        checkChartLoad();
                      }, 10);
                    }
                  }

                </script>
                <h1 class="b-title"><xsl:value-of select="$msg/msg[@name = 'title']"/></h1>
                <xsl:call-template name="report"/>
              </xsl:when>
              <xsl:when test="$meta/@type = 'form'">
                <h1>Cannot print Form</h1>
              </xsl:when>
              <xsl:when test="$meta/@type = 'map'">
                <h1>Cannot print Map</h1>
              </xsl:when>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </body>
    </html>
  </xsl:template>

  <!--list-->
  <xsl:template name="list">
    <xsl:variable name="psort" select="/doc/p_sort"/>
    <xsl:variable name="porder" select="/doc/p_order"/>
    <!--main table-->
    <table class="b-table">
      <!--headers-->
      <tr class="b-table__row b-table__row_head">
        <xsl:for-each select="$meta/coldata/col">
          <th colname="{@name}" class="b-table__th">
            <xsl:if test="@width"><xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute></xsl:if>
            <xsl:if test="position() = last()"><xsl:attribute name="class">b-table__th b-table__th_last </xsl:attribute></xsl:if>
            <div>
              <table cellpadding="0" cellspacing="0" border="0" class="thtbl">
                <tr>
                  <td class="thtbl-1">
                    <xsl:value-of select="$msg/msg[@name=current()/@name]"/>
                  </td>
                  <td class="thtbl-2">
                    <img src="{$commondir}img/e.gif" width="10" height="7" id="sortimg{position()-1}">
                      <xsl:choose>
                        <xsl:when test="@sorted and starts-with(@sorted, '+')"><xsl:attribute name="src">/manimg/common/img/down.gif</xsl:attribute></xsl:when>
                        <xsl:when test="@sorted and starts-with(@sorted, '-')"><xsl:attribute name="src">/manimg/common/img/up.gif</xsl:attribute></xsl:when>
                      </xsl:choose>
                    </img>
                  </td>
                </tr>
              </table>
            </div>
          </th>
        </xsl:for-each>
      </tr>
      <xsl:for-each select="/doc/elem">
        <xsl:variable name="el" select="."/>
          <tr class="b-table__row">
            <xsl:for-each select="$meta/coldata/col">
              <xsl:variable name="col" select="."/>
              <xsl:variable name="cell-style">
                <xsl:if test='$el/*[local-name() = current()/@name]/@xprop'>padding: 2px 3px;</xsl:if>
              </xsl:variable>

              <td class="b-table__col">
                <xsl:attribute name="style"><xsl:value-of select="$cell-style"/></xsl:attribute>
                <xsl:if test="position() = last()"><xsl:attribute name="class">b-table__col b-table__col_last</xsl:attribute></xsl:if>
                <xsl:if test="position() = 1"><xsl:attribute name="class">b-table__col b-table__col_first</xsl:attribute></xsl:if>
                <xsl:choose>
                  <!-- column is text data from element inner xml tag. @name contain name of xml tag -->
                  <xsl:when test="@type='data' or @type='msg'">
                    <xsl:call-template name="coldata"><xsl:with-param name="el" select="$el"/><xsl:with-param name="col" select="$col"/></xsl:call-template>
                  </xsl:when>
                  <!-- column contain element properties as image. for example, site have php, cgi, ... -->
                  <xsl:when test="prop or xprop">
                    <xsl:call-template name="colprop">
                      <xsl:with-param name="el" select="$el"/><xsl:with-param name="col" select="$col"/>
                    </xsl:call-template>
                  </xsl:when>
                  <!-- td column contain indicator -->
                  <xsl:when test="@type='indicator'">
                    <xsl:attribute name="class">b-table__col b-table__col_type_indicator <xsl:if test="position() = last()"> b-table__col b-table__col_last</xsl:if><xsl:if test="position() = 1"> b-table__col b-table__col_first</xsl:if></xsl:attribute>
                    <xsl:call-template name="indicator">
                      <xsl:with-param name="used" select="$el/*[local-name() = concat(current()/@name, '_used')]"/>
                      <xsl:with-param name="all" select="$el/*[local-name() = concat(current()/@name, '_total')]"/>
                    </xsl:call-template>
                  </xsl:when>
                </xsl:choose>
              </td>
            </xsl:for-each>
          </tr>
        </xsl:for-each>
      <tr class="t-table__row_footer_yes b-table__row">
        <xsl:for-each select="$meta/coldata/col">
          <xsl:variable name="ccol" select="."/>
          <xsl:if test="position()=1 or @stat or prop/@stat or xprop/@stat">
            <td class="b-table__col">
              <xsl:attribute name="colspan">
                <xsl:call-template name="fcols">
                  <xsl:with-param name="ccol" select="."/>
                </xsl:call-template>
              </xsl:attribute>
              <xsl:if test="not( $ccol/following-sibling::col[@stat or prop/@stat or xprop/@stat] )"><xsl:attribute name="class">b-table__col b-table__col_last</xsl:attribute></xsl:if>
              <!--<div id="{position()-1}-foot"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></div>-->
              <xsl:choose>
                <xsl:when test="@total and position() != 1">
                  <xsl:value-of select="@total"/>
                </xsl:when>
                <xsl:when test="position() = 1">
                  <xsl:value-of select="$msg/msg[@name = 'msg_total']"/>: <xsl:value-of select="/doc/p_elems"/>
                </xsl:when>
                <xsl:when test="prop or xprop">
                  <xsl:call-template name="footerprop">
                    <xsl:with-param name="col" select="$ccol"/>
                  </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </td>
          </xsl:if>
        </xsl:for-each>
      </tr>
    </table>

  </xsl:template>

<!--table content-->
  <xsl:template name="coldata">
    <xsl:param name="el"/>
    <xsl:param name="col"/>
    <xsl:variable name="dataelem" select="$el/*[local-name() = $col/@name]"/>
      <xsl:if test="$col/@wrap">
        <xsl:attribute name="style">white-space: normal;</xsl:attribute>
      </xsl:if>
      <xsl:if test="$dataelem/@color">
        <xsl:choose>
          <xsl:when test="position() = last()">
            <xsl:attribute name="class">b-table__col b-table__col_last status-<xsl:value-of select="$dataelem/@color"/></xsl:attribute>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="class">b-table__col status-<xsl:value-of select="$dataelem/@color"/></xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <xsl:if test="$col/@align">
        <xsl:attribute name="align"><xsl:value-of select="$col/@align"/></xsl:attribute>
      </xsl:if>

      <!-- element have image. for example, folder and file image in file manager -->
      <xsl:call-template name="colprop">
        <xsl:with-param name="el" select="$el"/>
        <xsl:with-param name="col" select="$col"/>
      </xsl:call-template>

      <div class="b-table__prop-text">
        <xsl:if test="$col/@wrap">
          <xsl:attribute name="style">white-space: normal;</xsl:attribute>
        </xsl:if>
        <!-- print element content. if it's empty then print 1x1 gif -->
        <xsl:choose>
          <xsl:when test="$dataelem!=''">
            <xsl:choose>
              <xsl:when test="$col/*[local-name() = 'prop' or local-name() = 'xprop']">
                <xsl:choose>
                  <xsl:when test="$col/@noescaping">
                    <xsl:value-of select="$dataelem" disable-output-escaping="yes"/>
                  </xsl:when>
                  <xsl:otherwise><xsl:value-of select="$dataelem"/></xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <xsl:choose>
                  <xsl:when test="$col/@noescaping">
                    <xsl:value-of select="$dataelem" disable-output-escaping="yes"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$dataelem"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></xsl:otherwise>
        </xsl:choose>
      </div>
  </xsl:template>

<!--colprop-->
  <xsl:template name="colprop">
    <xsl:param name="el"/>
    <xsl:param name="col"/>
    <xsl:variable name="props" select="$col/*[local-name() = 'prop' or local-name() = 'xprop']"/>
    <xsl:if test="count($props) != 0">
      <!--<xsl:attribute name="class">-->
        <!--<xsl:if test="$datael/@color">status-<xsl:value-of select="$datael/@color"/></xsl:if> b-table__col b-table__col_type_prop-->
      <!--</xsl:attribute>-->
      <div>
        <xsl:if test="$col/@align">
          <xsl:attribute name="align"><xsl:value-of select="$col/@align"/></xsl:attribute>
        </xsl:if>

        <xsl:attribute name="class">b-table__props-wrapper</xsl:attribute>

        <xsl:for-each select="$props">
          <xsl:variable name="on" select="current()/@img"/>
          <xsl:variable name="anym" select="current()/@animated"/>
          <xsl:variable name="nnn">
            <xsl:choose>
              <xsl:when test="local-name() = 'xprop'">
                <xsl:value-of select="current()/@name"/><xsl:value-of select="current()/@value"/>
              </xsl:when>
              <xsl:otherwise><xsl:value-of select="current()/@name"/></xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <xsl:variable name="xprop" select="$el/*[concat(local-name(), .) = $nnn]"/>
          <xsl:variable name="prop" select="$el/*[local-name() = $nnn]"/>
          <xsl:choose>
            <!--xprop name + value-->
            <xsl:when test="$xprop and current()/@value">
              <xsl:for-each select="$xprop">
                <xsl:call-template name="prop">
                  <xsl:with-param name="imgs" select="$on"/>
                  <xsl:with-param name="animated" select="$anym"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <!--xprop or prop  name -->
            <xsl:when test="$prop and count($col/*[@name = local-name($prop) and @value = $prop]) = 0">
              <xsl:for-each select="$prop">
                <xsl:call-template name="prop">
                  <xsl:with-param name="imgs" select="$on"/>
                  <xsl:with-param name="animated" select="$anym"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>

      </div>
    </xsl:if>
  </xsl:template>

  <!-- Property image -->
  <xsl:template name="prop">
    <xsl:param name="imgs"/>
    <xsl:param name="animated"/>
    <!--<xsl:choose>-->
    <img>
      <xsl:attribute name="class"> b-prop</xsl:attribute>

      <xsl:call-template name="pngsrc">
        <xsl:with-param name="src">
          <xsl:value-of select="$commondir"/>img/<xsl:value-of select="$imgs"/>.png</xsl:with-param>
        <xsl:with-param name="animated" select="$animated"/>
      </xsl:call-template>
    </img>
  </xsl:template>

  <!-- Indicator -->
  <xsl:template name="indicator">
    <xsl:param name="used"/><xsl:param name="all"/>

    <!-- Usage percentage -->
    <xsl:variable name="val" select="ceiling($used * 100 div $all)"/>

    <!-- Indicator -->
    <xsl:choose>
      <xsl:when test="not($used) and not($all)">
        <div><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></div>
      </xsl:when>
      <xsl:otherwise>
        <!-- Text under usage indicator -->
        <div class="int"><xsl:value-of select="$used"/><xsl:if test="$all!=''"> / <xsl:value-of select="$all"/></xsl:if></div>

        <div class="inl">
          <xsl:choose>
            <!-- Only green cell -->
            <xsl:when test="$all='' or not($val) or $val = '' or $val&lt;1"><xsl:attribute name="style">width: 1px; background: transparent;</xsl:attribute></xsl:when>
            <!-- Only red cell -->
            <xsl:when test="$val&gt;99"><xsl:attribute name="style">width: 100%;</xsl:attribute></xsl:when>
            <!-- Red and green cells -->
            <xsl:otherwise><xsl:attribute name="style">width: <xsl:value-of select="$val"/>%;</xsl:attribute></xsl:otherwise>
          </xsl:choose>
          <img src="{$commondir}img/e.gif" width="1" height="1"/>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="fcols">
    <xsl:param name="ccol"/>

    <xsl:variable name="cpos">
      <xsl:for-each select="$meta/coldata/col">
        <xsl:if test="current()/@name = $ccol/@name"><xsl:value-of select="position()"/></xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="fpos">
      <xsl:for-each select="$meta/coldata/col">
        <xsl:if test="current()/@name = $ccol/following-sibling::col[@stat or prop/@stat or xprop/@stat][1]/@name"><xsl:value-of select="position()"/></xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="total" select="count($meta/coldata/col)"/>

    <xsl:choose>
      <xsl:when test="$fpos != ''"><xsl:value-of select="$fpos - $cpos"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="$total + 1 - $cpos"/></xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="footerprop">
    <xsl:param name="col"/>
    <xsl:variable name="props" select="$col/*[local-name() = 'prop' or local-name() = 'xprop']"/>
    <xsl:for-each select="$props">
      <xsl:if test="current()/@total and current()/@total != 0">
        <span class="b-footer-prop">
          <xsl:variable name="on" select="current()/@img"/>
          <xsl:variable name="anym" select="current()/@animated"/>
          <xsl:call-template name="prop">
            <xsl:with-param name="imgs" select="$on"/>
            <xsl:with-param name="animated" select="$anym"/>
          </xsl:call-template>
          - <xsl:value-of select="@total"/>
        </span>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>

<!--make img-->
  <xsl:template name="pngsrc">
    <xsl:param name="src"/><xsl:param name="animated"/>

    <xsl:choose>
      <xsl:when test="$animated = 'yes'">
        <xsl:attribute name="src"><xsl:value-of select="substring-before($src,'.png')"/>.gif</xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="src"><xsl:value-of select="$src"/></xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!--report-->
  <xsl:template name="report">

    <script type="text/javascript">
      var pageUrl = '<xsl:value-of select="concat($host, $binary)"/>';
      <xsl:text disable-output-escaping="yes">
       function tb_rep_countstat (tid, totaltypes, convertTypes) {
        var tbl = document.getElementById(tid);
        if (!tbl) return;

        var htbl = tbl.tBodies[0];
        var ctbl = tbl.tBodies[1];
        var ftbl = tbl.tBodies[2];

        for (var i=0; i&lt;totaltypes.length; i++) {
          var value = "&amp;nbsp;";

          if (totaltypes[i] == "count") {
            value = ctbl.rows.length;
          } else if (totaltypes[i] == "sum") {
            value = 0; fixnum = 0;
            for (var j=0; j&lt;ctbl.rows.length; j++) {
              if (ctbl.rows[j].cells[i].innerHTML !== '') {
                var orig = ctbl.rows[j].cells[i].getAttribute('data-orig'),
                    cval;
                if (orig) {
                  cval = parseFloat(orig);
                  if (isNaN(cval)) {
                    cval = 0;
                  }
                } else {
                  cval = parseFloat(ctbl.rows[j].cells[i].innerHTML.replace(" ", ""));
                  if (isNaN(cval)) {
                    cval = 0;
                  }
                  if (String(cval).match(/\d+\.(\d+)/)) { fixnum = (String(RegExp.$1).length > fixnum) ? String(RegExp.$1).length : fixnum; }
                }
                value += cval;
              }
            }
            if (value.toFixed) {
              value =  value.toFixed(fixnum);
            }
          } else if (totaltypes[i] == "avg") {
            var sum = 0, orig;
            for (var j=0; j&lt;ctbl.rows.length; j++)  {
              orig = ctbl.rows[j].cells[i].getAttribute('data-orig');
              if (orig) {
                sum += orig-0;
              } else {
                if (ctbl.rows[j].cells[i].innerHTML !== '') {
                  sum += parseFloat(ctbl.rows[j].cells[i].innerHTML);
                }
              }
            }
            value = sum / ctbl.rows.length;
            if (value.toFixed) {
              value =  value.toFixed(2);
            }
          }

          ftbl.rows[0].cells[i].innerHTML = value;
      }
      getConvert();
    }
     function getConvert() {
        $('.b-table__col[data-convert]').each(function() {
          var self = this;
          $.ajax({
             url: pageUrl,
             type: 'post',
             data: 'func=convert&amp;sfrom=ajax&amp;name=' + this.getAttribute('data-convert') + '&amp;value=' + this.innerHTML,
             success: function(resp) {
               self.innerHTML = resp.convertValue;
             }
          })
        });
      }

      function renderChart(diagram) {
        var ht = document.getElementById(diagram["hid"]),
            mt = document.getElementById(diagram["mid"]),
            id = diagram.cid,
            len = diagram.data.length,
            lines = len == 1 ? false : true,
            diagramCont = document.getElementById(diagram.cid),
            showTextEvery = 'automatic',
            pointSize = 0;
        if (len &lt; 32) { pointSize = 3; };
        // One point on line Graph
        if (diagram["type"] == "line" &amp;&amp; mt.rows.length == 1) {
          diagramCont.style.display = 'none';
          return;
        }

        // Short line template
        if (diagram["type"] == "line" &amp;&amp; mt.rows.length &lt; 32) { ctemplate = "isp-shortline"; }

        // Point names and series names
        var labels = [];
        var datanames = {};
        var datacols = {};
        for (var i=0; i&lt;ht.rows[0].cells.length; i++) {
          if (ht.rows[0].cells[i].getAttribute("colname") == diagram["label"]) {
            for (var j=0; j&lt;mt.rows.length; j++) {
              labels.push(String(mt.rows[j].cells[i].innerHTML).replace(/&lt;.*?&gt;/g,"").replace(/^\s*|\s*$/g,"").replace(/&gt;/g,"&gt;").replace(/&lt;/g,"&gt;").substr(0,30) );
            }
          }
          for (var j=0; j&lt;diagram["data"].length; j++) {
            if (ht.rows[0].cells[i].getAttribute("colname") == diagram["data"][j]) {
              datacols[diagram["data"][j]]  = i;
              datanames[diagram["data"][j]]  = String(ht.rows[0].cells[i].innerHTML).replace(/&lt;.*?&gt;/g,"").replace(/^\s*|\s*$/g,"");
            }
          }
        }

        var data;
        if (!lines) {
          elem = ["fake", datanames[diagram.data[0]]];
          data = [elem];
          len = mt.rows.length;
          i = 0;
          var orig;
          for (var i = 0; i &lt; len; i++) {
            if (diagram.type == 'pie') {
              orig = mt.rows[i].cells[datacols[diagram.data[0]]].getAttribute('data-orig');
              if (i &lt; 5) {
                if (orig) {
                  elem = [labels[i], parseFloat(orig)];
                } else {
                  elem = [labels[i], parseFloat(String(mt.rows[i].cells[datacols[diagram.data[0]]].innerHTML).replace(/\s/g, ''))];
                }
                data.push(elem);
              } else if (i == 5) {
                if (orig) {
                  elem = ['others', parseFloat(orig)];
                } else {
                  elem = ['others', parseFloat(String(mt.rows[i].cells[datacols[diagram.data[0]]].innerHTML).replace(/\s/g, ''))];
                }
                data.push(elem);
              } else {
                if (orig) {
                  elem[1] += parseFloat(orig);
                } else {
                  elem[1] += parseFloat(String(mt.rows[i].cells[datacols[diagram.data[0]]].innerHTML).replace(/\s/g, ''));
                }
                if (i == len - 1) {
                  elem[1] =  parseFloat(elem[1].toFixed(2));
                }
              }
            } else {
              orig = mt.rows[i].cells[datacols[diagram.data[0]]].getAttribute('data-orig');
              if (orig) {
                elem = [labels[i], parseFloat(orig)];
              } else {
                elem = [labels[i], parseFloat(String(mt.rows[i].cells[datacols[diagram.data[0]]].innerHTML).replace(/\s/g, ''))];
              }
              data.push(elem);
            }
          }
        } else {
          elem = ["fake"];
          labelsLen = diagram.data.length;
          labelsLenSrc = labelsLen;
          i = 0;
          while (labelsLen--) {
            elem.push(datanames[diagram.data[i]]);
            i++;
          }
          data = [elem];
          len = mt.rows.length;
          j = 0;
          var orig = '';
          while (len--) {
            elem = [labels[j]];
            labelsLen = labelsLenSrc;
            i = 0;
            while (labelsLen--) {
              orig = mt.rows[j].cells[datacols[diagram.data[i]]].getAttribute('data-orig');
              if (orig) {
                elem.push(parseFloat(orig));
              } else {
                elem.push(parseFloat(String(mt.rows[j].cells[datacols[diagram.data[i]]].innerHTML).replace(/\s/g, '')));
              }
              i++;
            }
            data.push(elem);
            j++;
          }
        }

        if (diagram &amp;&amp; diagram.type === 'pie') {
          cdata = google.visualization.arrayToDataTable(data);
          options = {
            <!--title : diagram.labelText[0],-->
            'backgroundColor.stroke': '#fff',
            'vAxis': {
              'minValue': 0,
              'textStyle': { 'fontSize': '11'}
            },
            'is3D': true,
            'legend': {
              'alignment': 'start',
              'textStyle': { 'fontSize': '11'}
            }
          };
          chart = new google.visualization.PieChart(document.getElementById(id));
          chart.draw(cdata, options);
        } else if (diagram &amp;&amp; diagram.type == 'histogram') {
          cdata = google.visualization.arrayToDataTable(data);
          options = {
            'backgroundColor.stroke': '#fff',
            'vAxis': { 'minValue': 0,
              'textStyle': { 'fontSize': '11'}
            },
            'hAxis': {
              'textStyle': { 'fontSize': '11'}
            },
            'legend': {
              'position': 'top',
              'alignment': 'start',
              'textStyle': { 'fontSize': '11'}
            }
          };
          chart = new google.visualization.ColumnChart(document.getElementById(id));
          chart.draw(cdata, options);
        } else if (diagram &amp;&amp; diagram.type == 'line')  {
          cdata = google.visualization.arrayToDataTable(data);
          options = {
            'backgroundColor.stroke' : '#fff',
            'vAxis' : {
              'minValue' : 0,
              'textStyle' : { 'fontSize' : '11'}
            },
            'hAxis' : {
              'showTextEvery' : showTextEvery,
              'textStyle' : {'fontSize' : '11'}
            },
            'pointSize' : pointSize,
            'focusTarget' : 'category',
            'legend' : {
              'position': 'top',
              'alignment' : 'start',
              'textStyle' : {'fontSize' : '11'}
            }
          };
          chart = new google.visualization.LineChart(document.getElementById(id));
          chart.draw(cdata, options);
        }
      }
      </xsl:text>
    </script>

    <div align="center" class="title-report" id="title-report"></div>
      <xsl:call-template name="desc"/>

      <!--Check Empty report-->
      <xsl:call-template name="checkempty"/>
      <xsl:for-each select="$meta/form/field">
        <xsl:variable name="pname" select="@name"/>
        <xsl:for-each select="./*">
          <xsl:choose>
            <xsl:when test="local-name() = 'input' and @type = 'text' and /doc/*[local-name() = current()/@name] != ''">
              <div>
                <label><strong><xsl:if test="not(parent::node()/@noname)"><xsl:value-of select="key('msg', $pname)"/>: </xsl:if></strong></label>
                <span><xsl:value-of select="/doc/*[local-name() = current()/@name]"/></span>
              </div>
            </xsl:when>
            <xsl:when test="local-name() = 'select'">
              <div>
                <label><strong><xsl:if test="not(parent::node()/@noname)"><xsl:value-of select="key('msg', $pname)"/>: </xsl:if></strong></label>
                <xsl:for-each select="/doc/*[local-name() = $pname]">
                  <xsl:if test="position()!=1">; </xsl:if>
                  <span><xsl:value-of select="/doc/slist[@name=$pname]/val[@key = current()/text()]"/></span>
                </xsl:for-each>
              </div>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:for-each>
      <xsl:if test="count(/doc/reportdata/*) != 0">
        <xsl:apply-templates select="$meta/band"><xsl:with-param name="pelem" select="/doc/reportdata"/></xsl:apply-templates>
      </xsl:if>
  </xsl:template>

  <!--desc-->
  <xsl:template name="desc">
    <xsl:if test="/doc/messages/msg[@name='report_info']">
      <div class="report_info">
        <xsl:value-of select="key('msg', 'report_info')" disable-output-escaping="yes"/>
      </div>
    </xsl:if>
    <div class="field_desc">
      <xsl:for-each select="$meta/form/field">
        <xsl:variable name="desc" select="$msg/msg[@name= concat('descript', '_', current()/@name)]"/>
        <xsl:if test="$desc != ''">
          <div>
            <span class="field_name"><xsl:value-of select="$msg/msg[@name=current()/@name]"/></span> : <xsl:value-of select="$msg/msg[@name= concat('descript', '_', current()/@name)]"/>
          </div>
        </xsl:if>
      </xsl:for-each>
    </div>
  </xsl:template>

  <!--band-->
  <xsl:template match="band">
    <xsl:param name="pelem"/>

    <xsl:variable name="band" select="."/>
    <xsl:variable name="bandname" select="@name"/>
    <xsl:variable name="bandlevel" select="count(ancestor::band)"/>
    <xsl:choose>
      <!-- showtype TITLE -->
      <!--<xsl:when test="count($band/col) = 1 and $band/band">-->
      <xsl:when test="count($band/col) = 1 and $band/band">
        <xsl:for-each select="$pelem/*[local-name()=$bandname]/*">
          <xsl:variable name="celem" select="."/>

          <h2>
            <xsl:for-each select="$band/col">
              <xsl:if test="position() != 1"><xsl:text> - </xsl:text></xsl:if>
              <xsl:value-of select="$celem/*[local-name()=current()/@name]"/>
            </xsl:for-each>
          </h2>

          <xsl:for-each select="$band/band">
            <xsl:apply-templates select="."><xsl:with-param name="pelem" select="$celem"/></xsl:apply-templates>
          </xsl:for-each>

        </xsl:for-each>
      </xsl:when>

      <!-- showtype TABLE -->
      <xsl:when test="$band/col">
        <div>
          <xsl:attribute name="id">it<xsl:value-of select="generate-id($pelem)"/></xsl:attribute>
          <xsl:variable name="pos">
            <xsl:for-each select="$pelem/*[local-name()=$bandname]/parent::node()">
              <xsl:number count="elem" format="1"/>
            </xsl:for-each>
          </xsl:variable>
          <xsl:variable name="mainid" select="generate-id($pelem/*[local-name()=$bandname])"/>
          <xsl:if test="parent::node()/*[@link='yes']">
            <div id="t{$mainid}">
              <h3 class="band-child-title">
                <xsl:variable select="parent::node()/*[@link='yes']/@name" name="elem"/><xsl:value-of select="$pelem/*[local-name() = $elem]"/>
              </h3>
            </div>
          </xsl:if>
          <xsl:for-each select="$band/diagram">
            <xsl:variable name="num"><xsl:number count="diagram" format="1"/></xsl:variable>
            <xsl:if test="$msg/msg[@name=concat('diagram_', current()/@name)]">
              <div class="diagram_desc"><xsl:value-of select="$msg/msg[@name=concat('diagram_', current()/@name)]"/></div>
            </xsl:if>
            <div id="c{$mainid}{$num}" class="b-diagram"></div>
          </xsl:for-each>

          <div class="band_table" id="bt{$mainid}">
            <xsl:if test="$msg/msg[@name=concat('table_', $band/@name)]">
              <div class="band_table_desc"><xsl:value-of select="$msg/msg[@name=concat('table_', $band/@name)]"/></div>
            </xsl:if>
            <table class="b-table"  id="{$mainid}">
              <!-- Table head -->
              <tbody class="mainHead" id="h{$mainid}">
                <tr class="b-table__row b-table__row_head">
                  <xsl:for-each select="$band/col">
                    <th colname="{@name}" class="b-table__th">
                      <xsl:attribute name="style">width:<xsl:value-of select="@width"/></xsl:attribute>
                      <xsl:if test="position()=last()">
                        <xsl:attribute name="class">b-table__th b-table__th_last</xsl:attribute>
                      </xsl:if>
                      <xsl:if test="position()=1">
                        <xsl:attribute name="class">b-table__th b-table__th_first</xsl:attribute>
                      </xsl:if>
                      <xsl:if test="@sort">
                        <xsl:attribute name="onclick">tb_sort_rep(<xsl:value-of select="position()-1"/>,'<xsl:value-of select="@sort"/>','<xsl:value-of select="$mainid"/>')</xsl:attribute>
                      </xsl:if>

                      <xsl:value-of select="$msg/msg[@name = current()/@name]"/>
                    </th>
                  </xsl:for-each>
                </tr>
              </tbody>

              <!-- Table rows -->
              <tbody class="mainBody" id="m{$mainid}">
                <xsl:if test="count($pelem/*[local-name()=$bandname]) = 0">
                  <tr>
                    <td colspan="{count($band/col)}" style="border-left:0px; border-right:0px;"><xsl:value-of select="$msg/msg[@name='nodata']"/></td>
                  </tr>
                </xsl:if>

                <xsl:for-each select="$pelem/*[local-name()=$bandname]">

                  <xsl:for-each select="./elem">
                    <xsl:variable name="celem" select="."/>
                    <tr class="b-table__row">
                      <xsl:variable name="nestedname" select="$band/col[@nestedreport]/@name"/>
                      <xsl:attribute name="data-param-value"><xsl:value-of select="$celem/*[local-name() = $nestedname]"/></xsl:attribute>
                      <xsl:attribute name="id"><xsl:value-of select="generate-id(./*)"/></xsl:attribute>
                      <xsl:if test="(position() mod 2) = 0">
                        <xsl:attribute name="class">even</xsl:attribute>
                      </xsl:if>

                      <xsl:for-each select="$band/col">
                        <xsl:variable name="cvalue" select="$celem/*[local-name()=current()/@name]"/>

                        <td class="b-table__col">
                          <xsl:if test="@convert">
                            <xsl:attribute name="data-orig"><xsl:value-of select="$cvalue/@orig"/></xsl:attribute> 
                          </xsl:if>
                          <xsl:if test="@align">
                            <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
                          </xsl:if>
                          <xsl:if test="position()=1">
                            <xsl:attribute name="class">b-table__col b-table__col_first</xsl:attribute>
                          </xsl:if>
                          <xsl:if test="position()=last()">
                            <xsl:attribute name="class">b-table__col b-table__col_last</xsl:attribute>
                          </xsl:if>
                          <xsl:variable name="value-td">
                            <xsl:choose>
                              <xsl:when test="@type = 'msg'">
                                <xsl:value-of select="$msg/msg[@name = concat(current()/@name,'_',$cvalue)]"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <!--<xsl:value-of select="$cvalue" disable-output-escaping="yes"/>-->
                                <xsl:value-of select="$cvalue"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:variable>
                          <xsl:value-of select="$value-td"/>
                          <xsl:if test="$value-td = ''">
                            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                          </xsl:if>
                        </td>
                      </xsl:for-each>
                    </tr>
                  </xsl:for-each>

                </xsl:for-each>
              </tbody>

              <!-- Table foot -->
              <tbody class="mainFoot">
                <tr class="b-table__row">
                  <xsl:for-each select="$band/col">
                    <td class="b-table__col">
                      <xsl:if test="position() = last()">
                        <xsl:attribute name="class">b-table__col b-table__col_last</xsl:attribute>
                      </xsl:if>
                      <xsl:if test="@convert">
                        <xsl:attribute name="data-convert"><xsl:value-of select="@convert"/></xsl:attribute>
                      </xsl:if>
                      <xsl:if test="@align">
                        <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
                      </xsl:if>
                      <xsl:if test="@total">
                        <xsl:choose>
                          <xsl:when test="@total = 'count'">
                            <xsl:value-of select="count(/doc/reportdata/*[local-name() = $band/@name]//elem)"/>
                          </xsl:when>
                          <xsl:when test="@total = 'sum'">
                            <xsl:choose>
                              <xsl:when test="@convert">
                                <xsl:value-of select="sum(/doc/reportdata/*[local-name() = $band/@name]//elem/*[local-name() = current()/@name]/@orig)"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:value-of select="sum(/doc/reportdata/*[local-name() = $band/@name]//elem/*[local-name() = current()/@name])"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:when>
                          <xsl:when test="@total = 'avg'">
                            <xsl:choose>
                              <xsl:when test="@convert">
                                <xsl:variable name="sum" select="sum(/doc/reportdata/*[local-name() = $band/@name]//elem/*[local-name() = current()/@name]/@orig)"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:variable name="sum" select="sum(/doc/reportdata/*[local-name() = $band/@name]//elem/*[local-name() = current()/@name])"/>
                              </xsl:otherwise>
                            </xsl:choose>
                            <xsl:variable name="count" select="count(/doc/reportdata/*[local-name() = $band/@name]//elem)"/>
                            <xsl:value-of select="$sum div $count"/>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:if>
                    </td>
                  </xsl:for-each>
                </tr>
              </tbody>
            </table>
            <script type="text/javascript">
             tb_rep_countstat("<xsl:value-of select="$mainid"/>", [<xsl:for-each select="$band/col"><xsl:if test="position()!=1">,</xsl:if>"<xsl:value-of select="@total"/>"</xsl:for-each>], [<xsl:for-each select="$band/col"><xsl:if test="position()!=1">,</xsl:if>"<xsl:value-of select="@convert"/>"</xsl:for-each>]); 
              <xsl:for-each select="$band/diagram">
                var diagram = {
                "hid": "h<xsl:value-of select="$mainid"/>",
                "mid": "m<xsl:value-of select="$mainid"/>",
                "cid": "c<xsl:value-of select="$mainid"/><xsl:value-of select="position()"/>",
                "type": "<xsl:value-of select="@type"/>",
                "label": "<xsl:value-of select="@label"/>",
                "data": []
                }, id = '';
                <xsl:if test="@data">diagram["data"].push("<xsl:value-of select="@data"/>");</xsl:if>
                <xsl:for-each select="line">diagram["data"].push("<xsl:value-of select="@data"/>");</xsl:for-each>
                renderChartArr.push(diagram);
              </xsl:for-each>
            </script>
          </div>
          <!-- Foot js -->

        </div>
        <xsl:for-each select="$pelem/*[local-name()=$bandname]/elem">
          <xsl:variable name="celem" select="."/>
          <xsl:for-each select="$band/band"><xsl:apply-templates select="."><xsl:with-param name="pelem" select="$celem"/></xsl:apply-templates></xsl:for-each>
        </xsl:for-each>
      </xsl:when>

      <!-- showtype NONE -->
      <xsl:otherwise>
        <xsl:for-each select="$pelem/*[local-name()=$bandname]">
          <xsl:variable name="celem" select="."/>
          <xsl:for-each select="$band/band"><xsl:apply-templates select="."><xsl:with-param name="pelem" select="$celem"/></xsl:apply-templates></xsl:for-each>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

  <!--check for empty report-->
  <xsl:template  name="checkempty">
    <xsl:variable name="paramsok" select="//params/ok"/>
    <xsl:variable name="firstrun" select="/doc/metadata/@firstrun"/>
    <xsl:variable name="count" select="count(/doc/reportdata/*)"/>
    <xsl:if test="($count = 0 and  not($firstrun = 'no' and not($paramsok))) or ($count = 0 and /doc/tparams/ok)">
      <table align="center">
        <tr>
          <td><div class="count_reports"><xsl:value-of select="$msg/msg[@name='msg_nodata']"/></div></td>
        </tr>
      </table>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>