<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="Common.xslt"/>

  <xsl:variable name="Type" select="State/Regulation/@TypeReg"/>

  <xsl:variable name="MainMember" select="State/@CodeMember"/>

  <xsl:variable name="MainDateNumber">
    <xsl:choose>
      <xsl:when test="contains(State/Regulation/@ConfirmStartA,'T')">
        <xsl:value-of select="translate(substring-before(State/Regulation/@ConfirmStartA,'T'),'-','')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="translate(State/Regulation/@ConfirmStartA,'-','')"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="startA">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'startA'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="startO">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'startO'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="confirmA">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'confirm-startA'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="payment">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'payment'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="confirmO">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'confirm-startO'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="protocolP">
    <xsl:if test="
            State/Regulation/Pack/@CodePack = 'protocol[P]' or 
            State/Regulation/Pack/@CodePack = 'protocol2[P]' or 
            State/Regulation/Pack/@CodePack = 'protocol2P'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="protocolN">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'protocol[N]' or 
            State/Regulation/Pack/@CodePack = 'protocol2[N]' or 
            State/Regulation/Pack/@CodePack = 'protocol2N'">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="protocol">
    <xsl:if test="$protocolP = 1 or $protocolN = 1 or $confirmA = 1 or $payment = 1">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="answerP">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'answer[P]' or 
            State/Regulation/Pack/@CodePack = 'answer1[P]' or 
            State/Regulation/Pack/@CodePack = 'answer1P' or
            State/Regulation/Pack/@CodePack = 'answer2[P]' or 
            State/Regulation/Pack/@CodePack = 'answer2P' or
            State/Regulation/Pack/@CodePack = 'answer'
            ">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="answerN">
    <xsl:if test="State/Regulation/Pack/@CodePack = 'answer[N]' or 
            State/Regulation/Pack/@CodePack = 'answer1[N]' or 
            State/Regulation/Pack/@CodePack = 'answer1N' or
            State/Regulation/Pack/@CodePack = 'answer2[N]' or 
            State/Regulation/Pack/@CodePack = 'answer2N'
            ">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="answer">
    <xsl:if test="$answerP = 1 or $answerN = 1">
      <xsl:value-of select="1"/>
    </xsl:if>
  </xsl:variable>

  <!-- ВАЖНО: все Result и ResultN должны давать разный результат! -->
  <xsl:variable name="Result1">
    <xsl:text>Сеанс завершен успешно</xsl:text>
    <xsl:choose>
      <xsl:when test="($Type = 'AO10' and $MainMember = 'abonent')">
        <!--xsl:text> (положительный протокол контроля)</xsl:text-->
      </xsl:when>
      <xsl:when test="($Type = 'AO10' and $MainMember = 'organ')">
        <xsl:text> (положительный протокол контроля)</xsl:text>
      </xsl:when>
      <xsl:when test="(($Type = 'AO01' or $Type = 'AO11' or $Type = 'AO111') and $MainMember = 'abonent')">
        <!--xsl:text> (ответ положительный)</xsl:text-->
      </xsl:when>
      <xsl:when test="(($Type = 'AO01' or $Type = 'AO11' or $Type = 'AO111') and $MainMember = 'organ')">
        <xsl:text> (ответ положительный)</xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="Result2">
    <xsl:text>Сеанс завершен успешно (но ответ отрицательный)</xsl:text>
  </xsl:variable>
  <xsl:variable name="Result-1">
    <xsl:text>Сеанс завершен неудачно (отрицательный протокол контроля)</xsl:text>
  </xsl:variable>
  <xsl:variable name="Result-2">
    <xsl:text>Сеанс завершен неудачно (ошибки при проверке ЭЦП)</xsl:text>
  </xsl:variable>
  <xsl:variable name="Result">
    <xsl:text>Сеанс не завершен...</xsl:text>
  </xsl:variable>

  <xsl:template name="Member">
    <xsl:param name="Mem"/>
    <xsl:for-each select="State/Member[@CodeMember = $Mem]">
      <xsl:value-of select="translate(MemberName,'&quot;&lt;&gt;«»&amp;','')"/>
      <xsl:if test="position()!=last()">
        <xsl:text>; </xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="ESign">
    <xsl:param name="Mem"/>
    <xsl:param name="Role"/>
    <xsl:param name="CodePack"/>
    <xsl:choose>
      <xsl:when test="ESign[@CodeMember=$Mem]">
        <xsl:for-each select="ESign[@CodeMember=$Mem]">
          <div>
            <xsl:text>ЭЦП</xsl:text>
            <xsl:if test="$Role!=''">
              <xsl:text> </xsl:text>
              <xsl:value-of select="$Role"/>
            </xsl:if>
            <xsl:text>: </xsl:text>
            <xsl:choose>
              <xsl:when test="@CodeResult='true'">
                <span class="green">
                  <xsl:text>корректна</xsl:text>
                </span>
                <xsl:if test="Info != ''">
                  <xsl:variable name="Info1" select="translate(Info,'&quot;&lt;&gt;«»&amp;','')"/>
                  <xsl:text> (</xsl:text>
                  <xsl:if test="contains($Info1,'CN=')">
                    <xsl:variable name="ESign1" select="substring-before(substring-after($Info1,'CN='),',')"/>
                    <xsl:if test="not(contains($ESign1,'technokad.ru'))">
                      <xsl:value-of select="$ESign1"/>
                      <xsl:text>; </xsl:text>
                    </xsl:if>
                  </xsl:if>
                  <xsl:if test="contains($Info1,'O=')">
                    <xsl:value-of select="substring-before(substring-after($Info1,'O='),',')"/>
                    <xsl:text>; </xsl:text>
                  </xsl:if>
                  <xsl:value-of select="substring-after($Info1,'; ')"/>
                  <xsl:text>)</xsl:text>
                </xsl:if>
              </xsl:when>
              <xsl:otherwise>
                <span class="red">
                  <xsl:text>не корректна</xsl:text>
                </span>
                <xsl:if test="Info != ''">
                  <xsl:variable name="Info2" select="translate(Info,'&quot;&lt;&gt;«»&amp;','')"/>
                  <xsl:text> (</xsl:text>
                  <xsl:value-of select="$Info2"/>
                  <xsl:text>)</xsl:text>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>
          </div>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$CodePack='startA'">
        <xsl:if test="$Role!=''">
          <div>
            <xsl:text>ЭЦП </xsl:text>
            <xsl:value-of select="$Role"/>
            <xsl:text>: </xsl:text>
            <span class="black">
              <xsl:text>отсутствует</xsl:text>
            </span>
          </div>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="$Role!=''">
          <div>
            <xsl:text> </xsl:text>
          </div>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="ShowDoc">
    <xsl:param name="CodePack"/>
    <xsl:param name="Sender"/>
    <xsl:param name="Recipient"/>
    <xsl:param name="Col"/>

    <xsl:variable name="SenderDoc">
      <xsl:choose>
        <xsl:when test="$CodePack='confirm-startA' or $CodePack='payment'">
          <xsl:value-of select="'operator'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$Sender"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="RecipientDoc">
      <xsl:choose>
        <xsl:when test="$CodePack='confirm-startA' or $CodePack='payment'">
          <xsl:value-of select="$MainMember"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$Recipient"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:if test="not (File)">
      <div>
        <xsl:attribute name="class">
          <xsl:value-of select="$Col"/>
        </xsl:attribute>
        <xsl:text>Документ "</xsl:text>
        <xsl:call-template name="Pack">
          <xsl:with-param name="code" select="$CodePack"/>
        </xsl:call-template>
        <xsl:text>" не соответствует описанию (возможно, не расшифрован или поврежден)</xsl:text>
      </div>
    </xsl:if>
    <xsl:for-each select="File">
      <div>
        <xsl:attribute name="class">
          <xsl:value-of select="$Col"/>
        </xsl:attribute>
        <xsl:text>Документ "</xsl:text>
        <xsl:call-template name="Doc">
          <xsl:with-param name="code" select="@CodeDoc"/>
        </xsl:call-template>
        <xsl:text>"</xsl:text>
      </div>
      <div style="margin-left:10px;">
        <xsl:call-template name="ESign">
          <xsl:with-param name="Mem" select="$SenderDoc"/>
          <xsl:with-param name="Role" select="'отправителя'"/>
          <xsl:with-param name="CodePack" select="$CodePack"/>
        </xsl:call-template>
        <xsl:call-template name="ESign">
          <xsl:with-param name="Mem" select="$RecipientDoc"/>
          <xsl:with-param name="Role" select="'получателя'"/>
          <xsl:with-param name="CodePack" select="$CodePack"/>
        </xsl:call-template>
        <xsl:call-template name="ESign">
          <xsl:with-param name="Mem" select="'other'"/>
          <xsl:with-param name="Role" select="''"/>
          <xsl:with-param name="CodePack" select="$CodePack"/>
        </xsl:call-template>
      </div>
      <xsl:for-each select="AddFiles/AddFile">
        <xsl:if test="ESign/@CodeResult != 'true' or ../../../@CodePack='answer1[P]' or ../../../@CodePack='answer1[N]'">
          <div style="margin-left:20px;">
            <div style="font-weight:bold;">
              <xsl:text>Приложение "</xsl:text>
              <xsl:call-template name="Doc">
                <xsl:with-param name="code" select="@CodeDoc"/>
              </xsl:call-template>
              <xsl:text>"</xsl:text>
            </div>
            <div style="margin-left:10px;">
              <xsl:call-template name="ESign">
                <xsl:with-param name="Mem" select="$SenderDoc"/>
                <xsl:with-param name="Role" select="'отправителя'"/>
              </xsl:call-template>
              <xsl:call-template name="ESign">
                <xsl:with-param name="Mem" select="$RecipientDoc"/>
                <xsl:with-param name="Role" select="'получателя'"/>
              </xsl:call-template>
              <xsl:call-template name="ESign">
                <xsl:with-param name="Mem" select="'other'"/>
                <xsl:with-param name="Role" select="''"/>
              </xsl:call-template>
            </div>
          </div>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="ShowPack">
    <xsl:param name="Var"/>
    <xsl:param name="Code"/>
    <xsl:param name="Sender"/>
    <xsl:param name="Recipient"/>
    <xsl:variable name="S">
      <xsl:call-template name="Member">
        <xsl:with-param name="Mem" select="$Sender"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="R">
      <xsl:call-template name="Member">
        <xsl:with-param name="Mem" select="$Recipient"/>
      </xsl:call-template>
    </xsl:variable>
    <p />
    <table align="center">
      <xsl:attribute name="width">
        <xsl:value-of select="$TableWidth"/>
      </xsl:attribute>
      <xsl:call-template name="Table4"/>
      <tr>
        <td colspan="2">
          <div style="font-weight:bold">
            <xsl:text>Пакет "</xsl:text>
            <xsl:call-template name="Pack">
              <xsl:with-param name="code" select="$Code"/>
            </xsl:call-template>
            <xsl:text>"</xsl:text>
          </div>
        </td>
      </tr>
      <xsl:if test="$S!=''">
        <tr>
          <td>
            <div>
              <xsl:text>Отправитель</xsl:text>
            </div>
          </td>
          <td colspan="3">
            <xsl:call-template name="TextBox">
              <xsl:with-param name="siz" select="75"/>
              <xsl:with-param name="val" select="$S">
              </xsl:with-param>
            </xsl:call-template>
          </td>
        </tr>
      </xsl:if>
      <xsl:if test="$R!=''">
        <tr>
          <td>
            <div>
              <xsl:text>Получатель</xsl:text>
            </div>
          </td>
          <td colspan="3">
            <xsl:call-template name="TextBox">
              <xsl:with-param name="siz" select="75"/>
              <xsl:with-param name="val" select="$R">
              </xsl:with-param>
            </xsl:call-template>
          </td>
        </tr>
      </xsl:if>
      <tr>
        <td colspan="4">
          <table class="input">
            <tr>
              <td class="input">
                <xsl:choose>
                  <xsl:when test="$Var = 1">
                    <xsl:for-each select="State/Regulation/Pack[
                                  @CodePack=$Code or 
                                  @CodePack=concat($Code,'[P]') or @CodePack=concat($Code,'[N]') or 
                                  @CodePack=concat($Code,'1[P]') or @CodePack=concat($Code,'1[N]') or 
                                  @CodePack=concat($Code,'1P') or @CodePack=concat($Code,'1N') or
                                  @CodePack=concat($Code,'2[P]') or @CodePack=concat($Code,'2[N]') or 
                                  @CodePack=concat($Code,'2P') or @CodePack=concat($Code,'2N') or 
                                  ((@CodePack='confirm-startA' or @CodePack='payment') and $Code='protocol')
                                  ]">
                      <xsl:variable name="Col">
                        <xsl:choose>
                          <xsl:when test="contains(@CodePack,'[N]') or contains(@CodePack,'1N') or contains(@CodePack,'2N')">
                            <xsl:value-of select="'red'"/>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:value-of select="'black'"/>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:variable>
                      <xsl:call-template name="ShowDoc">
                        <xsl:with-param name="CodePack" select="@CodePack"/>
                        <xsl:with-param name="Sender" select="$Sender"/>
                        <xsl:with-param name="Recipient" select="$Recipient"/>
                        <xsl:with-param name="Col" select="$Col"/>
                      </xsl:call-template>
                    </xsl:for-each>
                  </xsl:when>
                  <xsl:otherwise>
                    <div>
                      <xsl:choose>
                        <xsl:when test="$Recipient = $MainMember">
                          <span class="black">
                            <xsl:text>Пакет не получен ...</xsl:text>
                          </span>
                        </xsl:when>
                        <xsl:when test="$Sender = $MainMember and $Code = 'startA'" >
                          <span class="red">
                            <xsl:text>Пакет отсутствует: был отправлен другим экземпляром "ТехноКад-Экспресс" или экспортирован ...</xsl:text>
                          </span>
                        </xsl:when>
                        <xsl:otherwise>
                          <span class="red">
                            <xsl:text>Пакет не отправлен</xsl:text>
                          </span>
                        </xsl:otherwise>
                      </xsl:choose>
                    </div>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="ShowPacks">
    <xsl:if test="contains($Type,'AO11') or contains($Type,'AO111')">
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$startA"/>
        <xsl:with-param name="Code" select="'startA'"/>
        <xsl:with-param name="Sender" select="'abonent'"/>
        <xsl:with-param name="Recipient" select="'organ'"/>
      </xsl:call-template>
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$protocol"/>
        <xsl:with-param name="Code" select="'protocol'"/>
        <xsl:with-param name="Sender" select="'organ'"/>
        <xsl:with-param name="Recipient" select="'abonent'"/>
      </xsl:call-template>
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$answer"/>
        <xsl:with-param name="Code" select="'answer'"/>
        <xsl:with-param name="Sender" select="'organ'"/>
        <xsl:with-param name="Recipient" select="'abonent'"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:if test="contains($Type,'AO10')">
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$startA"/>
        <xsl:with-param name="Code" select="'startA'"/>
        <xsl:with-param name="Sender" select="'abonent'"/>
        <xsl:with-param name="Recipient" select="'organ'"/>
      </xsl:call-template>
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$protocol"/>
        <xsl:with-param name="Code" select="'protocol'"/>
        <xsl:with-param name="Sender" select="'organ'"/>
        <xsl:with-param name="Recipient" select="'abonent'"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:if test="contains($Type,'AO01')">
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$startA"/>
        <xsl:with-param name="Code" select="'startA'"/>
        <xsl:with-param name="Sender" select="'abonent'"/>
        <xsl:with-param name="Recipient" select="'organ'"/>
      </xsl:call-template>
      <xsl:call-template name="ShowPack">
        <xsl:with-param name="Var" select="$answer"/>
        <xsl:with-param name="Code" select="'answer'"/>
        <xsl:with-param name="Sender" select="'organ'"/>
        <xsl:with-param name="Recipient" select="'abonent'"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="State">
    <xsl:variable name="Packs">
      <xsl:call-template name="ShowPacks"/>
    </xsl:variable>
    <xsl:variable name="ESignsF" select="not(contains($Packs,'ЭЦП отправителя: не корректна') or contains($Packs,'ЭЦП получателя: не корректна'))"/>
    <!--xsl:variable name="ESignsN" select="not(contains($Packs,'ЭЦП отправителя: отсутствует') or contains($Packs,'ЭЦП получателя: отсутствует'))"/-->
    <xsl:variable name="ESignsN" select="'true'"/>
    <xsl:variable name="State">
      <xsl:choose>
        <!--xsl:when test="$ESignsF and $ESignsN and $Type = 'AO01' and $startA = 1 and $confirmA = 1 and $answerP = 1">
          <xsl:value-of select="$Result1"/>
        </xsl:when-->
        <xsl:when test="$Type = 'AO01' and $startA = 1 and $answerP = 1 and $ESignsF = 'true'">
          <xsl:value-of select="$Result1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO01' and $startA = 1 and $answerP = 1 and $ESignsF != 'true'">
          <xsl:value-of select="$Result-2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO01' and $startA = 1 and $answerN = 1 and $answerP != 1">
          <xsl:value-of select="$Result2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO10' and $startA = 1 and $protocolP = 1 and $protocolN != 1 and $ESignsF = 'true'">
          <xsl:value-of select="$Result1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO10' and $startA = 1 and $protocolP = 1 and $protocolN != 1 and $ESignsF != 'true'">
          <xsl:value-of select="$Result-2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO10' and $startA = 1 and $protocolN = 1">
          <xsl:value-of select="$Result-1"/>
        </xsl:when>
        <!--xsl:when test="$Type = 'AO11' and $startA = 1 and $protocolN != 1 and $answerP = 1 and $ESignsF = 'true'">
          <xsl:value-of select="$Result1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO11' and $startA = 1 and $protocolN != 1 and $answerP = 1 and $ESignsF != 'true'">
          <xsl:value-of select="$Result-2"/>
        </xsl:when-->
        <xsl:when test="$Type = 'AO11' and $startA = 1 and $answerP = 1 and $ESignsF = 'true'">
          <xsl:value-of select="$Result1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO11' and $startA = 1 and $answerP = 1 and $ESignsF != 'true'">
          <xsl:value-of select="$Result-2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO11' and $startA = 1 and $protocolN = 1">
          <xsl:value-of select="$Result-1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO11' and $startA = 1 and $answerN = 1 and $answerP != 1">
          <xsl:value-of select="$Result2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO111' and $startA = 1 and $answerP = 1 and ($payment = 1 or (20101017 >= $MainDateNumber )) and $ESignsF = 'true'">
          <xsl:value-of select="$Result1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO111' and $startA = 1 and $answerP = 1 and ($payment = 1 or (20101017 >= $MainDateNumber )) and $ESignsF != 'true'">
          <xsl:value-of select="$Result-2"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO111' and $startA = 1 and $protocolN = 1">
          <xsl:value-of select="$Result-1"/>
        </xsl:when>
        <xsl:when test="$Type = 'AO111' and $startA = 1 and $answerN = 1 and $answerP != 1 and $payment = 1">
          <xsl:value-of select="$Result2"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$Result"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="$State"/>
  </xsl:template>

  <xsl:template name="Result">
    <xsl:variable name="Res">
      <xsl:call-template name="State"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$Res = $Result-1">
        <xsl:text>-1</xsl:text>
      </xsl:when>
      <xsl:when test="$Res = $Result-2">
        <xsl:text>-2</xsl:text>
      </xsl:when>
      <xsl:when test="$Res = $Result1">
        <xsl:text>1</xsl:text>
      </xsl:when>
      <xsl:when test="$Res = $Result2">
        <xsl:text>2</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>0</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="Numbers">
    <xsl:value-of select="State/Regulation/@CodeOut1"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="State/Regulation/@CodeOut2"/>
    <xsl:text> </xsl:text>
  </xsl:template>

  <xsl:template name="Titul">
    <xsl:variable name="State">
      <xsl:call-template name="State"/>
    </xsl:variable>
    <p/>
    <table align="center">
      <xsl:attribute name="width">
        <xsl:value-of select="$TableWidth"/>
      </xsl:attribute>
      <xsl:call-template name="Table4"/>
      <tr>
        <td>
          <div>
            <xsl:text>Вид регламента</xsl:text>
          </div>
        </td>
        <td colspan="3">
          <xsl:call-template name="RegBox">
            <xsl:with-param name="siz" select="75"/>
            <xsl:with-param name="code" select="State/Regulation/@CodeReg"/>
          </xsl:call-template>
        </td>
      </tr>
      <tr>
        <td>
          <div>
            <xsl:text>Идентификатор сеанса регламента</xsl:text>
          </div>
        </td>
        <td colspan="3">
          <xsl:call-template name="TextBox">
            <xsl:with-param name="siz" select="75"/>
            <xsl:with-param name="val" select="State/Regulation/@SessionID"/>
          </xsl:call-template>
        </td>
      </tr>
      <tr>
        <td>
          <div>
            <xsl:text>Пакет "Запрос" отправлен</xsl:text>
          </div>
        </td>
        <td>
          <xsl:call-template name="DateBox">
            <xsl:with-param name="siz" select="25"/>
            <xsl:with-param name="val" select="State/Regulation/@ConfirmStartA"/>

          </xsl:call-template>

        </td>
        <td>
          <div>
            <xsl:text>Номер заявления в ОКУ</xsl:text>
          </div>
        </td>
        <td>
          <xsl:call-template name="TextBox">
            <xsl:with-param name="siz" select="25"/>
            <xsl:with-param name="val">
              <xsl:call-template name="Numbers"/>
            </xsl:with-param>
          </xsl:call-template>
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <table class="input">
            <tr>
              <td class="input">
                <div>
                  <xsl:attribute name="class">
                    <xsl:choose>
                      <xsl:when test="$State = $Result1">
                        <xsl:value-of select="'green'"/>
                      </xsl:when>
                      <xsl:when test="$State = $Result2">
                        <xsl:value-of select="'red'"/>
                      </xsl:when>
                      <xsl:when test="$State = $Result-1">
                        <xsl:value-of select="'red'"/>
                      </xsl:when>
                      <xsl:when test="$State = $Result-2">
                        <xsl:value-of select="'red'"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="'black'"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:attribute>
                  <xsl:value-of select="$State"/>
                </div>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="Main_State">
    <xsl:call-template name="Titul"/>
    <xsl:call-template name="ShowPacks"/>
  </xsl:template>

  <xsl:template name="Main">
    <p align="center" style="font-weight:bold">
      <xsl:text>Состояние сеанса регламента</xsl:text>
    </p>
    <xsl:call-template name="Main_State"/>
  </xsl:template>

</xsl:stylesheet>
