<?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 или аналогичных
             Данный файл должен использоваться только для трансформации документа СЭМД (75) Протокол лабораторного исследования (CDA) Редакция 4, v1.3
	         Разработан по заказу Минздрава РФ компанией ООО "Цифромед" 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;
					}

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

					.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: 30pt;
                        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: 10pt;
                        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[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="10">
                                <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="5">
                                <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="5">
                                <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="5">
                                <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>
                                            <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="5">
                                <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="5">
                                <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="5">
                                <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="5">
                                <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="5">
                                <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="10">
                                <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"/>
													<xsl:text> </xsl:text>
				    					        </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="10">
                                        <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">
				    	<tr>
				    	    <td colspan="10">
                                <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='SPECIMENS'][not(@nullFlavor)]">
				    				    <xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='SPECIMENS']/n1:entry/n1:organizer/n1:component/n1:procedure/n1:specimen">
                                           <p class="tableblack">
				    						<xsl:value-of select="./n1:specimenRole/n1:specimenPlayingEntity/n1:code/@displayName"/>
				    						<xsl:choose>
				    						    <xsl:when test="./n1:specimenRole/n1:specimenPlayingEntity/n1:quantity[not(@nullFlavor)]">
				    						        <xsl:text> (</xsl:text>
				    						        <xsl:value-of select="./n1:specimenRole/n1:specimenPlayingEntity/n1:quantity/n1:translation/@value"/>
													<xsl:text> </xsl:text>
				    						        <xsl:value-of select="./n1:specimenRole/n1:specimenPlayingEntity/n1:quantity/n1:translation/@displayName"/>
				    						        <xsl:text>)</xsl:text>
				    						    </xsl:when>
				    						</xsl:choose>
                                            <xsl:text>. </xsl:text>
				    						<xsl:value-of select="./n1:specimenRole/n1:specimenPlayingEntity/n1:desc"/>
				    					</p>
				    					</xsl:for-each>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:text>-</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
				    	</tr>
				    	<tr>
				    	   	<td colspan="10">
                                   <h2 class="tablegray">
                                       <xsl:text>Оборудование и расходные материалы</xsl:text>
                                   </h2>
				    			<p>
				    			    <xsl:choose>
                                        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='ANALYSERS'][not(@nullFlavor)]">
				    			    		<xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='ANALYSERS']/n1:entry/n1:organizer/n1:participant">
				    	   		            <p class="tableblack">
                                                <xsl:value-of select="./n1:participantRole/n1:playingDevice/n1:manufacturerModelName"/>
                                            </p>
				    			    	    </xsl:for-each>
				    			        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>-</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
				    			</p>
                            </td>
                        </tr>
				    </table>
					<xsl:choose>
				        <xsl:when test="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section/n1:code[@code='RESLAB']">
				            <table class="block-form">
                                <tr>
                                    <td colspan="10">
                                        <h2 class="tablegray">
 					             		    <xsl:text>Результаты лабораторных исследований</xsl:text>
                                        </h2>
										<p class="tableblack">
										    <table class="table-break">
												<tr>
					                                <th class="param" colspan="3">Показатель</th>
						                            <th class="param">Значение</th>
										    		<th class="param">Интерпретация</th>
						                            <th class="param">Ед. изм.</th>
									               	<th class="param">Референтный диапазон</th>
									               	<th class="param" colspan="3">Комментарий</th>
						                        </tr>
												<xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESLAB']/n1:entry/n1:organizer[n1:statusCode/@code='completed']/n1:component/n1:organizer[n1:statusCode/@code='completed'][@classCode='BATTERY']">
													<tr>
										    		    <td class="param" colspan="10">
										    		        <p class="tableresult">
						                                		<b><xsl:value-of select="./n1:code/n1:originalText"/></b>
						                                    </p>
										    			</td>
										    		</tr>
										    		<xsl:for-each select="./n1:component/n1:observation">
										    		<tr>
                                                        <td class="param" colspan="3">
                                                            <p class="tableresult">
						                                		<xsl:value-of select="./n1:code/@displayName"/>
						                                	</p>
                                                        </td>
						                            	<td class="param">
                                                            <p class="tableresult">
									                		    <xsl:choose>
					                         	   			     	<xsl:when test="./n1:value[not(@nullFlavor)]">
						                     	   				        <xsl:if test="./n1:value/@xsi:type='ST'">
						                     	   				            <xsl:value-of select="./n1:value"/>
						                     	   				        </xsl:if>
						                     	   				        <xsl:if test="./n1:value/@xsi:type='PQ'">
						                     	   				            <xsl:value-of select="./n1:value/@value"/>
						                     	   				        </xsl:if>
						                     	   				        <xsl:if test="./n1:value/@xsi:type='CD'">
						                     	   				            <xsl:value-of select="./n1:value/@displayName"/>
						                     	   				        </xsl:if>
						                     						    <xsl:if test="./n1:value/@xsi:type='INT'">
						                     	   				            <xsl:value-of select="./n1:value/@value"/>
						                     	   				        </xsl:if>
						                     	   				        <xsl:if test="./n1:value/@xsi:type='BL'">
						                     	   				            <xsl:if test="./n1:value/@value='true'">
						                     	   				                <xsl:text>Да</xsl:text>
						                     	   				            </xsl:if>
						                     	   				        	<xsl:if test="./n1:value/@value='false'">
						                     	   				                <xsl:text>Нет</xsl:text>
						                     	   				            </xsl:if>
						                     	   				        </xsl:if>
						                     						    <xsl:if test="./n1:value/@xsi:type='IVL_TS'">
						                     					            <xsl:call-template name="formatDate">
                                                                                <xsl:with-param name="newdate" select="./n1:value/n1:low/@value"/>
                                                                            </xsl:call-template>
						                     		                        <xsl:choose>
                                                                                <xsl:when test="./n1:value/n1:high">
						                     		                            	<xsl:text> &#8212; </xsl:text>
						                     		                            	<xsl:call-template name="formatDate">
                                                                                        <xsl:with-param name="newdate" select="./n1:value/n1:high/@value"/>
                                                                                    </xsl:call-template>
						                     		                            </xsl:when>
						                                                    </xsl:choose>
						                     					        </xsl:if>
						                     						    <xsl:if test="./n1:value/@xsi:type='TS'">
						                     					            <xsl:call-template name="formatDate">
                                                                                <xsl:with-param name="newdate" select="./n1:value/@value"/>
                                                                            </xsl:call-template>
						                     	       			        </xsl:if>
						                     	   				    </xsl:when>
						                     					    <xsl:when test="./n1:value/@nullFlavor">
						                     					    	<xsl:call-template name="formatNullFlavor">
                                                                            <xsl:with-param name="nullflavor" select="./n1:value/@nullFlavor"/>
                                                                        </xsl:call-template>
						                     	                    </xsl:when>
					                         	   			    </xsl:choose>
						                                	</p>
                                                        </td>
										    			<td class="param">
                                                            <p class="tableresult">
																<xsl:call-template name="formatInterpretationCode">
                                                                    <xsl:with-param name="intercode" select="./n1:interpretationCode/@code"/>
                                                                </xsl:call-template>
						                                	</p>
                                                        </td>
						                            	<td class="param">
                                                            <p class="tableresult">
									                		    <xsl:choose>
									                			    <xsl:when test="./n1:referenceRange/n1:observationRange/n1:value/n1:low[not(@nullFlavor)]">
						                                		        <xsl:value-of select="./n1:referenceRange/n1:observationRange/n1:value/n1:low/n1:translation/@displayName"/>
									                				</xsl:when>
																	<xsl:when test="./n1:value/n1:translation/@displayName">
						                                		        <xsl:value-of select="./n1:value/n1:translation/@displayName"/>
									                				</xsl:when>
									                				<xsl:otherwise>
									                				    <xsl:value-of select="./n1:value/@unit"/>
									                				</xsl:otherwise>
									                			</xsl:choose>
						                                	</p>
                                                        </td>
									                	<td class="param" >
                                                            <p class="tableresult">
									                		    <xsl:choose>
									                			    <xsl:when test="./n1:referenceRange/n1:observationRange/n1:value/n1:low[not(@nullFlavor)]">
						                                		        <xsl:value-of select="./n1:referenceRange/n1:observationRange/n1:value/n1:low/n1:translation/@value"/>
									                			        <xsl:text>-</xsl:text>
									                			        <xsl:value-of select="./n1:referenceRange/n1:observationRange/n1:value/n1:high/n1:translation/@value"/>
									                				</xsl:when>
									                				<xsl:otherwise>
									                				    <xsl:value-of select="./n1:referenceRange/n1:observationRange/n1:text"/>
									                				</xsl:otherwise>
									                			</xsl:choose>
						                                	</p>
                                                        </td>
									                	<td class="param" colspan="3">
                                                            <p class="tableresult">
						                                		<xsl:value-of select="./n1:entryRelationship/n1:act[n1:code/@code='10000']/n1:text"/>
						                                	</p>
                                                        </td>
						                            </tr>
										    		</xsl:for-each>
													<xsl:for-each select="./n1:component/n1:act[n1:code/@code='900']">
													    <tr>
									                        <td  class="param" colspan="10">
                                                                <p class="tableresult">
						                                    		<i><xsl:value-of select="./n1:text"/></i>
						                                    	</p>
                                                            </td>
									                    </tr>
													</xsl:for-each>
											    </xsl:for-each>
											</table>
					                    </p>
                                    </td>
                                </tr>
					        </table>
						</xsl:when>
			        </xsl:choose>
				    <table class="block-form">
					    <tr>
					        <td colspan="10">
                                <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='RESLAB']/n1:entry/n1:organizer[n1:statusCode/@code='completed']/n1:component/n1:act[n1:code/@code='901'][not(@nullFlavor)]">
                                            <xsl:value-of select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:code/@code='RESLAB']/n1:entry/n1:organizer[n1:statusCode/@code='completed']/n1:component/n1:act[n1:code/@code='901']/n1:text"/>
                                        </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='SERVICES']">
			                    <tr>
                                    <td colspan="10">
                                        <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='SERVICES']/n1:entry/n1:act">
                                        <p class="tableblack">
                                            <xsl:value-of select="./n1:code/@code"/>
											<xsl:text> </xsl:text>
						        	    	<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>
                                    </td>
                                </tr>
							</xsl:when>
						</xsl:choose>
				    </table>
				    <table class="end-block-form">
			            <tr>
                            <td colspan="5">
                                <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="5">
                                <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:otherwise>
                <xsl:text>--</xsl:text>
            </xsl:otherwise>
        </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:otherwise>
                <xsl:text>--</xsl:text>
            </xsl:otherwise>
        </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:otherwise>
                <xsl:text>--</xsl:text>
            </xsl:otherwise>
        </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="formatContact">
        <xsl:param name="contact"/>
            <xsl:value-of select="substring-after($contact, ':')"/>
	</xsl:template>
	<xsl:template name="formatInterpretationCode">
        <xsl:param name="intercode"/>
			<xsl:choose>
				<xsl:when test="$intercode='&lt;' or $intercode='&#60;'">
				    <xsl:text>Ниже предела обнаружения</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='E'">
				    <xsl:text>Сомнительный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='EX'">
				    <xsl:text>Вне диапазона</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='EXP'">
				    <xsl:text>Ожидаемый результат/значение</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='H'">
				    <xsl:text>Повышенный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='HH'">
				    <xsl:text>Критически повышенный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='HU'">
				    <xsl:text>Значительно повышенный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='HX'">
				    <xsl:text>Больше верхнего порога</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='I'">
				    <xsl:text>Умеренно-устойчивый</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='IE'">
				    <xsl:text>Непоказательный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='IND'">
				    <xsl:text>Не определенный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='>' or $intercode='&gt;' or $intercode='&#62;'">
				    <xsl:text>Выше предела обнаружения</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='L'">
				    <xsl:text>Пониженный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='LL'">
				    <xsl:text>Критически пониженный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='LU'">
				    <xsl:text>Значительно пониженный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='LX'">
				    <xsl:text>Меньше нижнего порога</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='N'">
				    <xsl:text>Нормальный (в пределах референсного диапазона)</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='ND'">
				    <xsl:text>Не обнаружено</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='NEG'">
				    <xsl:text>Отрицательный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='NR'">
				    <xsl:text>Нет реакции</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='NS'">
				    <xsl:text>Нечувствительный при данных условиях</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='POS'">
				    <xsl:text>Положительный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='A'">
				    <xsl:text>Патологический (вне референсного диапазона)</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='QCF'">
				    <xsl:text>Контроль качества не пройден</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='R'">
				    <xsl:text>Устойчивый</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='RR'">
				    <xsl:text>Есть реакция</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='S'">
				    <xsl:text>Чувствительный</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='SDD'">
				    <xsl:text>Чувствительный-дозозависимый</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='SYN-R'">
				    <xsl:text>Устойчивый к комбинации</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='SYN-S'">
				    <xsl:text>Чувствительный к комбинации</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='TOX'">
				    <xsl:text>Присутствуют цитотоксические субстанции</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='U'">
				    <xsl:text>Значимо повысилось</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='UNE'">
				    <xsl:text>Неожиданный результат/значение</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='AA'">
				    <xsl:text>Критически патологический (критически вне референсного диапазона)</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='W'">
				    <xsl:text>Ухудшилось</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='WR'">
				    <xsl:text>Слабая реакция</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='AC'">
				    <xsl:text>Присутствуют антикомплиментарные субстанции</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='B'">
				    <xsl:text>Улучшилось</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='CAR'">
				    <xsl:text>Носитель</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='D'">
				    <xsl:text>Значимо понизилось</xsl:text>
				</xsl:when>
			    <xsl:when test="$intercode='DET'">
				    <xsl:text>Обнаружено</xsl:text>
				</xsl:when>
			</xsl:choose>
	</xsl:template>
	<xsl:template name="formatNullFlavor">
        <xsl:param name="nullflavor"/>
		    <xsl:choose>
			    <xsl:when test="$nullflavor='INV'">
                    <xsl:text>Недопустимое значение</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='NI'">
                    <xsl:text>Нет информации</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='OTH'">
                    <xsl:text>Другое</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='NINF'">
                    <xsl:text>Минус бесконечность</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='PINF'">
                    <xsl:text>Плюс бесконечность</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='NA'">
                    <xsl:text>Неприменимо</xsl:text>
                </xsl:when>
				<xsl:when test="$nullflavor='UNK'">
                    <xsl:text>Неизвестно</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='ASKU'">
                    <xsl:text>Запрошено, но неизвестно</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='NAV'">
                    <xsl:text>Временно недоступно</xsl:text>
                </xsl:when>
				<xsl:when test="$nullflavor='NASK'">
                    <xsl:text>Не запрашивалось</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='TRC'">
                    <xsl:text>Трудноразличимо</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='MSK'">
                    <xsl:text>Скрыто</xsl:text>
                </xsl:when>
				<xsl:when test="$nullflavor='DER'">
                    <xsl:text>Извлекаемое значение</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='UNC'">
                    <xsl:text>Кодирование не проводилось</xsl:text>
                </xsl:when>
                <xsl:when test="$nullflavor='QS'">
                    <xsl:text>Достаточное количество</xsl:text>
                </xsl:when>
			</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

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

v1.2: Изменен блок style и getAges
      &#160; заменен на другой вид пробела

v1.3: Исправлена ошибка отображения блока "Значение" секции RESLAB -->
