<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:n1="urn:hl7-org:v3"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:n2="urn:hl7-org:v3/meta/voc"
    xmlns:voc="urn:hl7-org:v3/voc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:fias="urn:hl7-ru:fias"
    xmlns:identity="urn:hl7-ru:identity"
    xmlns:address="urn:hl7-ru:address">
    <xsl:output method="html" indent="yes" encoding="utf-8"/>
    <xsl:template match="/">
        <xsl:apply-templates select="n1:ClinicalDocument"/>
    </xsl:template>
    <xsl:template match="n1:ClinicalDocument">
	    <html>
		<!-- Файл для трансформации XML->HTML->PDF при помощи библиотек iText Core, iText XMLWorker или аналогичных
             Данный файл должен использоваться только для трансформации документа СЭМД (110) Протокол инструментального исследования (CDA) Редакция 3, v1.2
	         Разработан по заказу Минздрава РФ компанией ООО "Цифромед" 11.07.2023
	         Замечания по данному файлу можно направить на почту egisz@stp-egisz.ru
			 Тема сообщения: замечания и вопросы по файлам визуализации -->
            <head>
                <style>
                    @page {
                        size: A4 portrait;
					    margin-top: 20pt;
					    margin-bottom: 156pt;
					    margin-left: 10pt;
					    margin-right: 20pt;
                    }

                    table {
                        table-layout: fixed;
                        width: 98%;
                        border-collapse: collapse;

                        font-family: Arial, sans-serif;
                        word-wrap: break-word;
					    margin-top: 0;
                        margin-bottom: 10pt;
					    margin-left: 20pt;
                    }

                    td {
					    vertical-align: top;
					    padding: 2;
                    }

					.table-break {
					    margin-left: 0;
						border-collapse: collapse;
					}

					.param {
					    font-size: 15px;
					    border: 1pt solid gray;

						word-wrap: none;
					}

					.created {
					    vertical-align: middle;
					}

                    .medorg {
                        text-align: left;
                        font-size: 15px;
                        font-weight: 400;
                        color: #000000;
                        margin-top: 5pt;
                        margin-bottom: 5pt;
                        white-space: normal;
                    }

                    .address {
                        text-align: left;
                        font-size: 15px;
                        font-weight: 100;
                        color: #000000;
                        margin-top: 5pt;
                        margin-bottom: 5pt;
                        white-space: normal;
                    }

                    .emd {
                        text-align: center;
                        font-size: 18px;
                        font-weight: 400;
                        color: #000000;
                        margin-top: 25pt;
                        margin-bottom: 25pt;
                        white-space: normal;
                    }

                    .date {
                        text-align: center;
                        font-size: 15px;
                        font-weight: 400;
                        color: #000000;
                        margin-top: 5pt;
                        margin-bottom: 5pt;
                        white-space: normal;
                    }

					.tablegray {
                        text-align: left;
                        font-size: 15px;
                        font-weight: 100;
                        color: #aaaaaa;
                        margin-top: 5pt;
                        margin-bottom: 5pt;
                    }

					.tableblack {
                        text-align: left;
                        font-size: 15px;
                        font-weight: 100;
                        color: #000000;
                        margin-top: 0;
                        margin-bottom: 3pt;
                        white-space: normal;
                    }

					.createdate {
                        text-align: right;
                        font-size: 15px;
                        font-weight: 100;
                        color: #aaaaaa;
					    margin-right: 10pt;
                    }

					.pagenumber {
                        text-align: center;
					    valign: center;
                        font-size: 15px;
                        font-weight: 100;
                        color: #aaaaaa;
					    margin-right: 10pt;
                    }

					h2+p {
                        page-break-inside: avoid;
                    }

					th {
					    text-align: left;
					    font-size: 15px;
						padding: 5pt;
						background-color: #D9D9D6;
					}

					.first-block-form {
					    margin-top: -10pt;
					}

					.block-form {
					    border-collapse: collapse;
						margin-top: 0;
						margin-bottom: 0;
					    border-bottom: 1pt solid #e0e0e0;
					}

					.end-block-form {
					}
                </style>
            </head>
			<body>
			        <table class="first-block-form">
			            <tr>
                            <td colspan="8">
                                <p class="medorg">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:custodian/n1:assignedCustodian/n1:representedCustodianOrganization[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:custodian/n1:assignedCustodian/n1:representedCustodianOrganization/n1:name"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text> </xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
						    	<p class="medorg">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:custodian/n1:assignedCustodian/n1:representedCustodianOrganization/n1:addr[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:custodian/n1:assignedCustodian/n1:representedCustodianOrganization/n1:addr/n1:streetAddressLine"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text> </xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
								<xsl:choose>
                                    <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:providerOrganization/identity:Props/identity:Ogrn[not(@nullFlavor)]">
                                        <p class="medorg">
										    <xsl:text>ОГРН: </xsl:text>
											<xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:providerOrganization/identity:Props/identity:Ogrn"/>
										</p>
                                    </xsl:when>
                                </xsl:choose>
								<xsl:choose>
                                    <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:providerOrganization/n1:telecom[1][not(@nullFlavor)]">
                                        <p class="medorg">
										    <xsl:text>Контакты: </xsl:text>
						    	        	<xsl:call-template name="formatContact">
                                                <xsl:with-param name="contact" select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:providerOrganization/n1:telecom[1]/@value"/>
                                            </xsl:call-template>
                                        </p>
                                    </xsl:when>
                                </xsl:choose>
						    </td>
                        </tr>
					</table>
					<table class="block-form">
				        <tr>
                            <td colspan="8">
                                <h1 class="emd">
                                    <b>
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:code[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:code/@displayName"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>[Название вида медицинского документа]</xsl:text>
                                        </xsl:otherwise>
                                     </xsl:choose>
                                    </b>
                                </h1>
                             </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Пациент</xsl:text>
                                </h2>
						    	<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:name[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:name"/>
                                        </xsl:when>
                                    </xsl:choose>
                                </p>
                            </td>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Полис ОМС</xsl:text>
                                </h2>
						    	<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:InsurancePolicy[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:InsurancePolicy/identity:Series"/>
						    				<xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:InsurancePolicy/identity:Number"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Дата рождения (возраст)</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:birthTime[not(@nullFlavor)]">
                                            <xsl:call-template name="formatDate">
                                                <xsl:with-param name="newdate" select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:birthTime/@value"/>
                                            </xsl:call-template>&#160;
                                            <xsl:text> (</xsl:text>
					    					<xsl:call-template name="getAge">
                                                <xsl:with-param name="birthdate" select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:birthTime/@value"/>
					    						<xsl:with-param name="deathdate" select="/n1:ClinicalDocument/n1:effectiveTime/@value"/>
					    						<xsl:with-param name="withtext" select="1"/>
                                            </xsl:call-template>
					    					<xsl:text>)</xsl:text>
					    				</xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>СНИЛС</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:id[2]/@extension[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:id[2]/@extension"/>
                                        </xsl:when>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Пол</xsl:text>
                                </h2>
						    	<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:administrativeGenderCode[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:patient/n1:administrativeGenderCode/@displayName"/>
                                        </xsl:when>
						    			<xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Номер карты</xsl:text>
                                </h2>
						    	<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:componentOf/n1:encompassingEncounter/n1:id[2]/@extension[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:componentOf/n1:encompassingEncounter/n1:id[2]/@extension"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
					        <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Адрес постоянной регистрации</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:addr[address:Type/@code='1']/n1:streetAddressLine[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:addr[address:Type/@code='1']/n1:streetAddressLine"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Адрес фактического проживания</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:addr[address:Type/@code='3']/n1:streetAddressLine[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:addr[address:Type/@code='3']/n1:streetAddressLine"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
                            <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Документ, удостоверяющий личность</xsl:text>
                                </h2>
                                <p class="tableblack">
					    		    <xsl:choose>
					    			    <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc[not(@nullFlavor)]">
					    				    <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IdentityCardType/@displayName"/>&#160;
					    				    <xsl:choose>
					    			            <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:Series[not(@nullFlavor)]">
                                                    <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:Series"/>&#160;
					    				        </xsl:when>
					    				    </xsl:choose>
					    				    <xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:Number"/>&#160;
					    				    <xsl:choose>
					    			            <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IssueOrgName[not(@nullFlavor)]">
					    				        	<xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IssueOrgName"/>&#160;
					    				        </xsl:when>
					    				    </xsl:choose>
					    				    <xsl:choose>
					    			            <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IssueOrgCode[not(@nullFlavor)]">
					    				        	<xsl:value-of select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IssueOrgCode"/>&#160;
					    				        </xsl:when>
					    				    </xsl:choose>
					    				    <xsl:text>Дата выдачи: </xsl:text>
					    				    <xsl:call-template name="formatDate">
                                                <xsl:with-param name="newdate" select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/identity:IdentityDoc/identity:IssueDate/@value"/>
                                            </xsl:call-template>
                                        </xsl:when>
					    				<xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
					    </tr>
					    <xsl:choose>
					        <xsl:when test="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:telecom[not(@nullFlavor)]">
					            <tr>
                                    <td colspan="8">
                                        <h2 class="tablegray">
                                            <xsl:text>Контактные данные</xsl:text>
                                        </h2>
					                    <xsl:for-each select="/n1:ClinicalDocument/n1:recordTarget/n1:patientRole/n1:telecom">
                                        <p class="tableblack">
						    	        	<xsl:call-template name="formatContact">
                                                <xsl:with-param name="contact" select="./@value"/>
                                            </xsl:call-template>
                                        </p>
						    	        </xsl:for-each>
                                    </td>
				                </tr>
			                </xsl:when>
			            </xsl:choose>
					</table>
					<table class="block-form">
					    <xsl:choose>
				            <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:act/n1:reference[@typeCode='REFR']/n1:externalDocument/n1:text[not(@nullFlavor)]">
                                <tr>
                                    <td colspan="8">
                                        <h2 class="tablegray">
 					        		        <xsl:text>Сведение о направлении</xsl:text>
                                        </h2>
                                        <p class="tableblack">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:act/n1:reference[@typeCode='REFR']/n1:externalDocument/n1:text"/>
                                        </p>
                                    </td>
                                </tr>
				            </xsl:when>
			            </xsl:choose>
					    <tr>
					        <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Порядок обращения</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section/n1:entry/n1:observation[n1:code/@code='800']/n1:value[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section/n1:entry/n1:observation[n1:code/@code='800']/n1:value/@displayName"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
					    	<td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Место проведения</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section/n1:entry/n1:observation[n1:code/@code='801']/n1:value[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section/n1:entry/n1:observation[n1:code/@code='801']/n1:value/@displayName"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
					        <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Дата проведения</xsl:text>
                                </h2>
                                <p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:effectiveTime/n1:low/@value[not(@nullFlavor)]">
                                            <xsl:call-template name="formatDatewithTime">
                                                <xsl:with-param name="newdate" select="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:effectiveTime/n1:low/@value"/>
                                            </xsl:call-template>
                                        </xsl:when>
										<xsl:when test="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:effectiveTime/n1:high/@value[not(@nullFlavor)]">
                                            <xsl:text> &#8212; </xsl:text>
											<xsl:call-template name="formatDatewithTime">
                                                <xsl:with-param name="newdate" select="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:effectiveTime/n1:high/@value"/>
                                            </xsl:call-template>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
					    			</xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
                            <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Диагноз</xsl:text>
                                </h2>
                                <p class="tableblack">
					    		    <xsl:if test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:observation[n1:code/@code='838']/n1:value[not(@code)]">
                                        <xsl:text>-</xsl:text>
                                    </xsl:if>
					    			<xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:observation[n1:code/@code='838']/n1:value/@code"/>&#160;
					    			<xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:observation[n1:code/@code='838']/n1:value/@displayName"/>
									<xsl:choose>
									    <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:observation[n1:code/@code='838']/n1:text">
										    <br/><xsl:text>Врачебное описание нозологической единицы: </xsl:text>
											<xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:observation[n1:code/@code='838']/n1:text"/>
									    </xsl:when>
									</xsl:choose>
                                </p>
							</td>
					    </tr>
					    <tr>
                            <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Исследование</xsl:text>
                                </h2>
					            <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='DOCINFO']/n1:entry/n1:act[n1:code/@codeSystem='1.2.643.5.1.13.13.11.1471'][n1:statusCode/@code='completed']">
                                <p class="tableblack">
								    <xsl:choose>
					    			    <xsl:when test="./n1:effectiveTime/n1:low/@value">
					    			        <xsl:call-template name="formatDatewithTime">
                                                <xsl:with-param name="newdate" select="./n1:effectiveTime/n1:low/@value"/>
                                            </xsl:call-template>&#160;
					    			    </xsl:when>
					    			</xsl:choose>
									<xsl:value-of select="./n1:code/@displayName"/>
					    			<xsl:choose>
					    			    <xsl:when test="./n1:entryRelationship/n1:observation[n1:code/@code='4159'][not(@nullFlavor)]">
										    <xsl:text> (</xsl:text>
					    			        <xsl:value-of select="./n1:entryRelationship/n1:observation/n1:code[@code='4159']/@displayName"/>:&#160;
					    			        <xsl:value-of select="./n1:entryRelationship/n1:observation/n1:value/n1:translation/@value"/>&#160;
					    			        <xsl:value-of select="./n1:entryRelationship/n1:observation/n1:value/n1:translation/@displayName"/>
					    			        <xsl:text>)</xsl:text>
					    			    </xsl:when>
					    			</xsl:choose>
                                </p>
					    		</xsl:for-each>
                            </td>
					    </tr>
					</table>
					<xsl:choose>
				        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='VITALPARAM']">
					        <table class="block-form">
                                <tr>
                                    <td colspan="8">
                                        <h2 class="tablegray">
 					             		    <xsl:text>Витальные параметры</xsl:text>
                                        </h2>
					                    <tr>
					                        <th class="param" colspan="4">Параметр</th>
						                    <th class="param">Значение</th>
						                    <th class="param">Ед. изм.</th>
						                </tr>
						                <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='VITALPARAM']/n1:entry/n1:organizer[n1:statusCode/@code='completed']/n1:component/n1:observation">
						                    <tr>
                                                <td class="param" colspan="4">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:code/@displayName"/>
						                        	</p>
                                                </td>
						                    	<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:value/n1:translation/@value"/>
						                        	</p>
                                                </td>
						                    	<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:value/n1:translation/@displayName"/>
						                        	</p>
                                                </td>
						                    </tr>
						                </xsl:for-each>
									</td>
								</tr>
					        </table>
					    </xsl:when>
			        </xsl:choose>
					<xsl:choose>
				        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='SCORES']">
					        <table class="block-form">
                                <tr>
                                    <td colspan="8">
                                        <h2 class="tablegray">
 					             		    <xsl:text>Объективизированная оценка состояния больного (Сведения о результатах расчета прогностических шкал)</xsl:text>
                                        </h2>
					                    <tr>
					                        <th class="param">Дата</th>
						                    <th class="param">Название шкалы</th>
						                    <th class="param">Результат расчета</th>
								        	<th class="param">Ед. изм.</th>
								        	<th class="param">Интерпретация результата</th>
								        	<th class="param">ФИО мед. работника</th>
						                </tr>
						                <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='SCORES']/n1:entry/n1:observation">
						                    <tr>
                                                <td class="param">
                                                    <p class="tableblack">
						                        		<xsl:call-template name="formatDatewithTime">
                                                            <xsl:with-param name="newdate" select="./n1:effectiveTime/@value"/>
                                                        </xsl:call-template>
						                        	</p>
                                                </td>
						                    	<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:code/@displayName"/>
						                        	</p>
                                                </td>
								        		<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:value/n1:translation/@value"/>
						                        	</p>
                                                </td>
								        		<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:value/n1:translation/@displayName"/>
						                        	</p>
                                                </td>
								        		<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:text"/>
						                        	</p>
                                                </td>
						                    	<td class="param">
                                                    <p class="tableblack">
						                        		<xsl:value-of select="./n1:performer/n1:assignedEntity/n1:assignedPerson/n1:name"/>
						                        	</p>
                                                </td>
						                    </tr>
						                </xsl:for-each>
									</td>
								</tr>
					        </table>
					    </xsl:when>
			        </xsl:choose>
					<table class="block-form">
			            <tr>
					        <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Протокол исследования</xsl:text>
                                </h2>
                                <p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='1805']/n1:value[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='1805']/n1:value"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <tr>
					        <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Заключение</xsl:text>
                                </h2>
                                <p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='1806']/n1:value[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='1806']/n1:value"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					</table>
					<table class="block-form">
					    <tr>
					        <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Рекомендации</xsl:text>
                                </h2>
                                <p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='807']/n1:value[not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='807']/n1:value"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
					    <xsl:choose>
				            <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='808'][not(@nullFlavor)]">
                                <tr>
                                    <td colspan="8">
                                        <h2 class="tablegray">
 					        		        <xsl:text>Выявленные патологии</xsl:text>
                                        </h2>
					                    <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESINFO']/n1:entry/n1:observation[n1:code/@code='808']">
                                        <p class="tableblack">
                                            <xsl:value-of select="./n1:value/@displayName"/>
                                        </p>
					        		    </xsl:for-each>
                                    </td>
                                </tr>
				            </xsl:when>
			            </xsl:choose>
			            <tr>
                            <td colspan="8">
                                <h2 class="tablegray">
                                    <xsl:text>Оказанные услуги</xsl:text>
                                </h2>
					            <xsl:choose>
					                <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='SERVICES']">
					                    <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='SERVICES']/n1:entry/n1:act">
                                        <p class="tableblack">
                                            <xsl:value-of select="./n1:code/@code"/>&#160;
							            	<xsl:value-of select="./n1:code/@displayName"/>
							            	<xsl:text> от </xsl:text>
							            	<xsl:call-template name="formatDate">
                                                <xsl:with-param name="newdate" select="./n1:effectiveTime/@value"/>
                                            </xsl:call-template><br/>
                                        </p>
							            </xsl:for-each>
					                </xsl:when>
					                <xsl:otherwise>
                                        <xsl:text>-</xsl:text>
                                    </xsl:otherwise>
					            </xsl:choose>
                            </td>
                        </tr>
					</table>
					<table class="end-block-form">
			            <tr>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Медицинские работники, проводившие исследование</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:performer/n1:assignedEntity/n1:code[not(@nullFlavor)]">
                                            <xsl:for-each select="/n1:ClinicalDocument/n1:documentationOf/n1:serviceEvent/n1:performer/n1:assignedEntity">
                                            <p class="tableblack">
												<xsl:value-of select="./n1:assignedPerson/n1:name"/><br/>
					    					    <xsl:value-of select="./n1:code/@displayName"/>
											</p>
											</xsl:for-each>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                            <td colspan="4">
                                <h2 class="tablegray">
                                    <xsl:text>Дата составления</xsl:text>
                                </h2>
					    		<p class="tableblack">
                                    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:effectiveTime[not(@nullFlavor)]">
                                            <xsl:call-template name="formatDate">
                                                <xsl:with-param name="newdate" select="/n1:ClinicalDocument/n1:effectiveTime/@value"/>
                                            </xsl:call-template>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </p>
                            </td>
                        </tr>
                    </table>
            </body>
		</html>
	</xsl:template>
	<xsl:template name="getR">
        <xsl:param name="templateId"/>
        <xsl:variable name="templateIdLength" select="string-length($templateId)"/>
        <xsl:value-of select="substring ($templateId, $templateIdLength, 1)"/>
    </xsl:template>
    <xsl:template name="getYear">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
                <xsl:value-of select="substring ($date, 1, 4)"/>
    </xsl:template>
    <xsl:template name="getMonth">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:variable name="month" select="substring ($date, 5, 2)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=6">
            <xsl:value-of select="substring ($date, 5, 2)"/>
			</xsl:when>
        </xsl:choose>
    </xsl:template>
	<xsl:template name="getTextMonth">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:variable name="month" select="substring ($date, 5, 2)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=6">
                <xsl:choose>
                    <xsl:when test="$month='01'">
                        <xsl:text>января</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='02'">
                        <xsl:text>Февраля</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='03'">
                        <xsl:text>марта</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='04'">
                        <xsl:text>апреля</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='05'">
                        <xsl:text>мая</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='06'">
                        <xsl:text>июня</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='07'">
                        <xsl:text>июля</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='08'">
                        <xsl:text>августа</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='09'">
                        <xsl:text>сентября</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='10'">
                        <xsl:text>октября</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='11'">
                        <xsl:text>ноября</xsl:text>
                    </xsl:when>
                    <xsl:when test="$month='12'">
                        <xsl:text>декабря</xsl:text>
                    </xsl:when>
                </xsl:choose>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getDay">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=8">
                <xsl:value-of select="substring ($date, 7, 2)"/>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getName">
        <xsl:param name="name"/>
        <xsl:choose>
            <xsl:when test="$name/n1:family">
                <xsl:if test="$name/n1:prefix">
                    <xsl:value-of select="$name/n1:prefix"/>
                    <xsl:text></xsl:text>
                </xsl:if>
                <xsl:value-of select="$name/n1:family"/>
                <xsl:text></xsl:text>
                <xsl:value-of select="$name/n1:given[1]"/>
                <xsl:text></xsl:text>
                <xsl:value-of select="$name/n1:given[2]"/>
                <xsl:text></xsl:text>
                <xsl:if test="$name/n1:suffix">
                    <xsl:value-of select="$name/n1:suffix"/>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$name"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getHour">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=10">
                <xsl:choose>
                    <xsl:when test="substring ($date, 9, 1)='0'">
                        <xsl:value-of select="substring ($date, 10, 1)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="substring ($date, 9, 2)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getMinute">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=12">
                <xsl:choose>
                    <xsl:when test="substring ($date, 9, 1)='0'">
                        <xsl:value-of select="substring ($date, 11, 2)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="substring ($date, 11, 2)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getSecond">
        <xsl:param name="date"/>
        <xsl:variable name="dateLength" select="string-length($date)"/>
        <xsl:choose>
            <xsl:when test="$dateLength>=14">
                <xsl:value-of select="substring ($date, 13, 5)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>--</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getMKB">
        <xsl:param name="code"/>
        <xsl:param name="pos"/>
        <xsl:value-of select="substring ($code, $pos, 1)"/>
    </xsl:template>
	<xsl:template name="getAges">
	    <xsl:param name="age"/>
		<xsl:variable name="agestr" select="string($age)"/>
        <xsl:variable name="agebefore100" select="substring($agestr, 2, 1)"/>
		<xsl:variable name="ageafter100" select="substring($agestr, 3, 1)"/>
		<xsl:variable name="age1234" select="substring($agestr, 1, 1)"/>
            <xsl:if test="string-length($agestr)=2">
                <xsl:choose>
                    <xsl:when test="($agebefore100='1') and (number($agestr)&gt;20)">
                        <xsl:text> год</xsl:text>
                    </xsl:when>
					<xsl:when test="(($agebefore100='2') or ($agebefore100='3') or ($agebefore100='4')) and (number($agestr)&gt;20)">
                        <xsl:text> года</xsl:text>
                    </xsl:when>
			        <xsl:otherwise>
                        <xsl:text> лет</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
			</xsl:if>
			<xsl:if test="string-length($agestr)=1">
                <xsl:choose>
                    <xsl:when test="$age1234='1'">
                        <xsl:text> год</xsl:text>
                    </xsl:when>
					<xsl:when test="($age1234='2') or ($age1234='3') or ($age1234='4')">
                        <xsl:text> года</xsl:text>
                    </xsl:when>
			        <xsl:otherwise>
                        <xsl:text> лет</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
			</xsl:if>
			<xsl:if test="(number($agestr)&gt;100) and (number($agestr)&lt;110)">
                 <xsl:choose>
                     <xsl:when test="($ageafter100='1')">
                         <xsl:text> год</xsl:text>
                     </xsl:when>
					 <xsl:when test="($ageafter100='2') or ($ageafter100='3') or ($ageafter100='4')">
                         <xsl:text> года</xsl:text>
                     </xsl:when>
			        <xsl:otherwise>
                        <xsl:text> лет</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
			<xsl:if test="(number($agestr)&gt;120)">
                 <xsl:choose>
				 <xsl:when test="($ageafter100='1')">
                         <xsl:text> год</xsl:text>
                     </xsl:when>
					 <xsl:when test="($ageafter100='2') or ($ageafter100='3') or ($ageafter100='4')">
                        <xsl:text> года</xsl:text>
                     </xsl:when>
			        <xsl:otherwise>
                        <xsl:text> лет</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
	</xsl:template>
    <xsl:template name="getAge">
        <xsl:param name="birthdate"/>
        <xsl:param name="deathdate"/>
        <xsl:param name="withtext"/>
        <xsl:variable name="bDay" select="substring ($birthdate, 7, 2)"/>
        <xsl:variable name="dDay" select="substring ($deathdate, 7, 2)"/>
        <xsl:variable name="bMonth" select="substring ($birthdate, 5, 2)"/>
        <xsl:variable name="dMonth" select="substring ($deathdate, 5, 2)"/>
        <xsl:variable name="bYear" select="substring ($birthdate, 1, 4)"/>
        <xsl:variable name="dYear" select="substring ($deathdate, 1, 4)"/>
		<xsl:variable name="age1" select="number($dYear)-number($bYear)"/>
		<xsl:variable name="age2" select="number($dYear)-number($bYear)-1"/>
        <xsl:choose>
            <xsl:when test="number($dDay)-number($bDay)&gt;=0">
                <xsl:choose>
                    <xsl:when test="number($dMonth)-number($bMonth)&gt;=0">
                        <xsl:value-of select="$age1"/>
						<xsl:if test="$withtext=1">
						    <xsl:call-template name="getAges">
                                <xsl:with-param name="age" select="$age1"/>
                            </xsl:call-template>
						</xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$age2"/>
						<xsl:if test="$withtext=1">
							<xsl:call-template name="getAges">
                                <xsl:with-param name="age" select="$age2"/>
                            </xsl:call-template>
						</xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="number($dMonth)-number($bMonth)-1&gt;=0">
                        <xsl:value-of select="$age1"/>
						<xsl:if test="$withtext=1">
							<xsl:call-template name="getAges">
                                <xsl:with-param name="age" select="$age1"/>
                            </xsl:call-template>
						</xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$age2"/>
						<xsl:if test="$withtext=1">
							<xsl:call-template name="getAges">
                                <xsl:with-param name="age" select="$age2"/>
                            </xsl:call-template>
						</xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getMonths">
        <xsl:param name="birthdate"/>
        <xsl:param name="deathdate"/>
        <xsl:variable name="bDay" select="substring ($birthdate, 7, 2)"/>
        <xsl:variable name="dDay" select="substring ($deathdate, 7, 2)"/>
        <xsl:variable name="bMonth" select="substring ($birthdate, 5, 2)"/>
        <xsl:variable name="dMonth" select="substring ($deathdate, 5, 2)"/>
        <xsl:variable name="bYear" select="substring ($birthdate, 1, 4)"/>
        <xsl:variable name="dYear" select="substring ($deathdate, 1, 4)"/>
        <xsl:choose>
            <xsl:when test="number($dYear)=number($bYear)">
                <xsl:choose>
                    <xsl:when test="(string-length($birthdate)>=8) and (string-length($deathdate)>=8)">
                        <xsl:choose>
                            <xsl:when test="number($dDay)&gt;=number($bDay)">
                                <xsl:value-of select="number($dMonth)-number($bMonth)"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="number($dMonth)-number($bMonth)-1"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="(string-length($birthdate)&lt;6) or (string-length($deathdate)&lt;6)">
                                <xsl:value-of select="0"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="number($dMonth)-number($bMonth)"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="(string-length($birthdate)>=8) and (string-length($deathdate)>=8)">
                        <xsl:choose>
                            <xsl:when test="number($dDay)&gt;=number($bDay)">
                                <xsl:value-of select="number($dMonth)+12-number($bMonth)"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="number($dMonth)+12-number($bMonth)-1"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="(string-length($birthdate)&lt;6) or (string-length($deathdate)&lt;6)">
                                <xsl:value-of select="12"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="number($dMonth)+12-number($bMonth)"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getDays">
        <xsl:param name="birthdate"/>
        <xsl:param name="deathdate"/>
        <xsl:variable name="bDay" select="substring ($birthdate, 7, 2)"/>
        <xsl:variable name="dDay" select="substring ($deathdate, 7, 2)"/>
        <xsl:variable name="bMonth" select="substring ($birthdate, 5, 2)"/>
        <xsl:variable name="dMonth" select="substring ($deathdate, 5, 2)"/>
        <xsl:variable name="dYear" select="substring ($deathdate, 1, 4)"/>
        <xsl:choose>
            <xsl:when test="(string-length($birthdate)>=8) and (string-length($deathdate)>=8)">
                <xsl:choose>
                    <xsl:when test="number($dDay)&gt;=number($bDay)">
                        <xsl:value-of select="number($dDay)-number($bDay)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="number($dMonth)=1">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=2">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=3">
                                <xsl:choose>
                                    <xsl:when test="number($dYear) mod 4=0">
                                        <xsl:choose>
                                            <xsl:when test="(number($dYear) mod 100)=0">
                                                <xsl:choose>
                                                    <xsl:when test="(number($dYear) mod 400)=0">
                                                        <xsl:value-of select="number($dDay)+28-number($bDay)"/>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:value-of select="number($dDay)+29-number($bDay)"/>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="number($dDay)+29-number($bDay)"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="number($dDay)+28-number($bDay)"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=4">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=5">
                                <xsl:value-of select="number($dDay)+30-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=6">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=7">
                                <xsl:value-of select="number($dDay)+30-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=8">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=9">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=10">
                                <xsl:value-of select="number($dDay)+30-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=11">
                                <xsl:value-of select="number($dDay)+31-number($bDay)"/>
                            </xsl:when>
                            <xsl:when test="number($dMonth)=12">
                                <xsl:value-of select="number($dDay)+30-number($bDay)"/>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="0"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="formatDate">
        <xsl:param name="newdate"/>
			<xsl:call-template name="getDay">
                <xsl:with-param name="date" select="$newdate"/>
            </xsl:call-template>
			<xsl:text>&#46;</xsl:text>
			<xsl:call-template name="getMonth">
                <xsl:with-param name="date" select="$newdate"/>
            </xsl:call-template>
			<xsl:text>&#46;</xsl:text>
			<xsl:call-template name="getYear">
                <xsl:with-param name="date" select="$newdate"/>
            </xsl:call-template>
	</xsl:template>
	<xsl:template name="formatDatewithTime">
        <xsl:param name="newdate"/>
		<xsl:call-template name="getDay">
            <xsl:with-param name="date" select="$newdate"/>
        </xsl:call-template>
		<xsl:text>&#46;</xsl:text>
		<xsl:call-template name="getMonth">
            <xsl:with-param name="date" select="$newdate"/>
        </xsl:call-template>
		<xsl:text>&#46;</xsl:text>
		<xsl:call-template name="getYear">
            <xsl:with-param name="date" select="$newdate"/>
        </xsl:call-template>&#160;
		<xsl:call-template name="getHour">
            <xsl:with-param name="date" select="$newdate"/>
        </xsl:call-template>
		<xsl:text>&#58;</xsl:text>
		<xsl:call-template name="getMinute">
            <xsl:with-param name="date" select="$newdate"/>
        </xsl:call-template>
	</xsl:template>
	<xsl:template name="formatContact">
        <xsl:param name="contact"/>
            <xsl:value-of select="substring-after($contact, ':')"/>
	</xsl:template>
</xsl:stylesheet>

<!-- Список изменений:

v1.2: Изменен блок style и getAges -->
