<?xml version="1.0" encoding="windows-1251"?>
<!--CodeRegMask="nwz|cho"-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="MiniEditorSpatial100323.xslt"/>

  <xsl:template name="Encumbrance">
    <Encumbrance>
      <Name>
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'Name'"/>
        </xsl:call-template>
      </Name>
      <Type>
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'Type'"/>
        </xsl:call-template>
      </Type>
      <!-- Заглушка - начало -->
      <!--Owner_Restriction_InFavorem>
        <Person>
          <FIO>
            <Surname>String</Surname>
            <First>String</First>
            <Patronymic>String</Patronymic>
          </FIO>
          <DateBirth>1967-08-13</DateBirth>
          <Place_Birth>String</Place_Birth>
          <Document>
            <Type_Document>008001000000</Type_Document>
            <Name>String</Name>
            <Series>String</Series>
            <Number>String</Number>
            <Date>1967-08-13</Date>
            <IssueOrgan>String</IssueOrgan>
            <Duration>
              <Started>1967-08-13</Started>
              <Stopped>1967-08-13</Stopped>
            </Duration>
            <Images>
              <Image Name="String" URL="String"/>
            </Images>
            <Desc>String</Desc>
          </Document>
          <INN>StringSSSSSS</INN>
          <Location>
            <Code_OKATO>String</Code_OKATO>
            <Code_KLADR>String</Code_KLADR>
            <Postal_Code>String</Postal_Code>
            <Region>01</Region>
            <District Type="String" Name="String"/>
            <City Type="String" Name="String"/>
            <Locality Type="String" Name="String"/>
            <Street Type="String" Name="String"/>
            <House>String</House>
            <Building>String</Building>
            <Structure>String</Structure>
          </Location>
          <FactLocation>
            <Code_OKATO>String</Code_OKATO>
            <Code_KLADR>String</Code_KLADR>
            <Postal_Code>String</Postal_Code>
            <Region>01</Region>
            <District Type="String" Name="String"/>
            <City Type="String" Name="String"/>
            <Locality Type="String" Name="String"/>
            <Street Type="String" Name="String"/>
            <House>String</House>
            <Building>String</Building>
            <Structure>String</Structure>
          </FactLocation>
        </Person>
      </Owner_Restriction_InFavorem>
      <Duration>
        <Started>1967-08-13</Started>
        <Stopped>1967-08-13</Stopped>
      </Duration>
      <Registration>
        <RegNumber>String</RegNumber>
        <RegDate>1967-08-13</RegDate>
        <OrgRegister>String</OrgRegister>
      </Registration>
      <CadastralNumber_Restriction>String</CadastralNumber_Restriction>
      <Documents>
        <Document>
          <Type_Document>008001000000</Type_Document>
          <Name>String</Name>
          <Series>String</Series>
          <Number>String</Number>
          <Date>1967-08-13</Date>
          <IssueOrgan>String</IssueOrgan>
          <Duration>
            <Started>1967-08-13</Started>
            <Stopped>1967-08-13</Stopped>
          </Duration>
          <Images>
            <Image Name="String" URL="String"/>
          </Images>
          <Desc>String</Desc>
        </Document>
      </Documents-->
      <!-- Заглушка - конец -->
    </Encumbrance>
  </xsl:template>

  <xsl:template name="SubParcel">
    <xsl:param name="ZUCadastralNumber"/>
    <xsl:param name="ZUDesignation"/>
    <xsl:param name="Cs_Id"/>
    <xsl:param name="NewSubParcel"/>
    <!--SubParcel-->
    <xsl:for-each select="Page[@Code='SubParcels']/*[@Code='SubParcel']/*[not(@Selected='false')]">
      <xsl:variable name="TestOrd_Num">
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'Ord_Num'"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="TestDesignation">
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'Designation'"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="$NewSubParcel='true'">
          <xsl:attribute name="Definition">
            <xsl:if test="substring($TestDesignation,1,3)='чзу'">
              <xsl:choose>
                <xsl:when test="$ZUCadastralNumber!=''">
                  <xsl:value-of select="$ZUCadastralNumber"/>
                  <xsl:text>/</xsl:text>
                </xsl:when>
                <xsl:when test="$ZUDesignation!=''">
                  <xsl:value-of select="$ZUDesignation"/>
                  <xsl:text>/</xsl:text>
                </xsl:when>
              </xsl:choose>
            </xsl:if>
            <xsl:value-of select="$TestDesignation"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="$TestOrd_Num!=''">
            <xsl:attribute name="Number_PP">
              <xsl:value-of select="$TestOrd_Num"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$TestDesignation!=''">
            <xsl:attribute name="Definition">
              <xsl:if test="substring($TestDesignation,1,3)='чзу'">
                <xsl:choose>
                  <xsl:when test="$ZUCadastralNumber!=''">
                    <xsl:value-of select="$ZUCadastralNumber"/>
                    <xsl:text>/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$ZUDesignation!=''">
                    <xsl:value-of select="$ZUDesignation"/>
                    <xsl:text>/</xsl:text>
                  </xsl:when>
                </xsl:choose>
              </xsl:if>
              <xsl:value-of select="$TestDesignation"/>
            </xsl:attribute>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:for-each>

    <xsl:attribute name="SubParcel_Realty">
      <xsl:for-each select="Page[@Code='SubParcels']/*[@Code='SubParcel_Realty']/*">
        <!-- Заглушка - начало -->
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'SubParcel_Realty'"/>
        </xsl:call-template>
        <!-- Заглушка - конец -->
      </xsl:for-each>
    </xsl:attribute>

    <xsl:if test="$NewSubParcel='true'">
      <CadastralNumber_Parcel>
        <xsl:value-of select="$ZUCadastralNumber"/>
      </CadastralNumber_Parcel>
    </xsl:if>
    <xsl:for-each select="Page[@Code='Areas']/*[@Code='Area' and @Selected='true']/*">
      <Area>
        <Area>
          <xsl:call-template name="Value">
            <xsl:with-param name="x" select="'Area'"/>
          </xsl:call-template>
        </Area>
        <Unit>
          <xsl:call-template name="Value">
            <xsl:with-param name="x" select="'Unit'"/>
          </xsl:call-template>
        </Unit>
        <xsl:variable name="TestMP3">
          <xsl:call-template name="Value">
            <xsl:with-param name="x" select="'Innccuracy'"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:if test="$TestMP3!=''">
          <Innccuracy>
            <xsl:value-of select="$TestMP3"/>
          </Innccuracy>
        </xsl:if>
      </Area>
    </xsl:for-each>
    <xsl:if test="Page[@Code='SubParcels']/*[@Code='Encumbrances' and @Selected='true']">
      <xsl:for-each select="Page[@Code='SubParcels']/*[@Code='Encumbrances']/*">
        <xsl:call-template name="Encumbrance"/>
      </xsl:for-each>
    </xsl:if>
    <xsl:call-template name="Entity_Spatial">
      <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
    </xsl:call-template>
    <!--/SubParcel-->
  </xsl:template>

  <xsl:template name="SpecifyRelatedParcel">
    <SpecifyRelatedParcel>
      <xsl:variable name="ZUCadastralNumber">
        <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
          <xsl:call-template name="Value">
            <xsl:with-param name="x" select="'CadastralNumber'"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:variable>
      <xsl:attribute name="CadastralNumber">
        <xsl:value-of select="$ZUCadastralNumber"/>
      </xsl:attribute>
      <xsl:for-each select="Page[@Code='Entity_Spatial']/*[@Code='Point']/*">
        <ChangeBorder>
          <OldOrdinate>
            <xsl:attribute name="Ord_Nmb">
              <xsl:value-of select="position()"/>
            </xsl:attribute>
            <xsl:variable name="X0">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'X0'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="Y0">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Y0'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$X0!='-' and $Y0!='-'">
              <xsl:attribute name="X">
                <xsl:value-of select="$X0"/>
              </xsl:attribute>
              <xsl:attribute name="Y">
                <xsl:value-of select="$Y0"/>
              </xsl:attribute>
            </xsl:if>
          </OldOrdinate>
          <NewOrdinate>
            <xsl:attribute name="Ord_Nmb">
              <xsl:value-of select="position()"/>
            </xsl:attribute>
            <xsl:variable name="Num_Geopoint">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Num_Geopoint'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$Num_Geopoint!=''">
              <xsl:attribute name="Num_Geopoint">
                <xsl:value-of select="$Num_Geopoint"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:variable name="Point_Pref">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Point_Pref'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:attribute name="Point_Pref">
              <xsl:value-of select="$Point_Pref"/>
            </xsl:attribute>
            <xsl:variable name="X">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'X'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="Y">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Y'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$X!='л' and $Y!='л'">
              <xsl:attribute name="X">
                <xsl:value-of select="$X"/>
              </xsl:attribute>
              <xsl:attribute name="Y">
                <xsl:value-of select="$Y"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:variable name="Delta_Geopoint">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Delta_Geopoint'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$Delta_Geopoint!=''">
              <xsl:attribute name="Delta_Geopoint">
                <xsl:value-of select="$Delta_Geopoint"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:variable name="Geopoint_Zacrep">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Geopoint_Zacrep'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$Geopoint_Zacrep!=''">
              <xsl:attribute name="Geopoint_Zacrep">
                <xsl:value-of select="$Geopoint_Zacrep"/>
              </xsl:attribute>
            </xsl:if>
          </NewOrdinate>
        </ChangeBorder>
      </xsl:for-each>
    </SpecifyRelatedParcel>
  </xsl:template>

  <xsl:template name="MP">
    <xsl:param name="CodeDoc"/>
    <xsl:param name="Method"/>

    <xsl:variable name="ParentID0">
      <xsl:value-of select="@Code"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="@ID"/>
    </xsl:variable>
    <xsl:variable name="BlockCadastralNumber">
      <xsl:for-each select="Page[@Code='Common']/*[@Code='Block']/*">
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'CadastralNumber'"/>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="Cs_Id">
      <xsl:for-each select="Page[@Code='BasicData' or @Code='Coord_System']/*[@Code='Coord_System']/*">
        <xsl:call-template name="Value">
          <xsl:with-param name="x" select="'Cs_Id'"/>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:variable>

    <STD_MP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <xsl:call-template name="EDocument">
        <xsl:with-param name="CodeDoc" select="$CodeDoc"/>
      </xsl:call-template>
      <xsl:choose>
        <xsl:when test="$VersionMP='02'">
          <Package>
            <xsl:if test="$CodeReg='nwz'">
              <FormParcels>
                <xsl:for-each select="../Form[(@Code='NWZ') and @ParentID=$ParentID0 and @Selected='true']">
                  <xsl:variable name="MultiContour" select="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*)"/>
                  <xsl:variable name="ParentID1">
                    <xsl:value-of select="@Code"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="@ID"/>
                  </xsl:variable>
                  <NewParcel>
                    <xsl:variable name="ZUDesignation">
                      <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                        <xsl:call-template name="Value">
                          <xsl:with-param name="x" select="'Designation'"/>
                        </xsl:call-template>
                      </xsl:for-each>
                    </xsl:variable>
                    <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                      <xsl:attribute name="AdditionalName">
                        <xsl:call-template name="Value">
                          <xsl:with-param name="x" select="'AdditionalName'"/>
                        </xsl:call-template>
                      </xsl:attribute>
                      <xsl:attribute name="Method">
                        <xsl:value-of select="$Method"/>
                      </xsl:attribute>
                      <xsl:attribute name="Name">
                        <xsl:choose>
                          <xsl:when test="$MultiContour > 1">
                            <xsl:value-of select="'05'"/>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Name'"/>
                            </xsl:call-template>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:attribute>
                      <xsl:attribute name="Definition">
                        <xsl:value-of select="$ZUDesignation"/>
                      </xsl:attribute>
                    </xsl:for-each>
                    <CadastralBlock>
                      <xsl:value-of select="$BlockCadastralNumber"/>
                    </CadastralBlock>
                    <xsl:if test="../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel' and @Selected='true']">
                      <Prev_CadastralNumbers>
                        <xsl:for-each select="../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Prev_CadastralNumbers>
                    </xsl:if>
                    <xsl:if test="Page/*[@Code='Providing_Pass_CadastralNumbers' and @Selected='true']">
                      <Providing_Pass_CadastralNumbers>
                        <xsl:for-each select="Page/*[@Code='Providing_Pass_CadastralNumbers']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Providing_Pass_CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Providing_Pass_CadastralNumbers>
                    </xsl:if>
                    <xsl:if test="Page/*[@Code='Inner_CadastralNumbers' and @Selected='true']">
                      <Inner_CadastralNumbers>
                        <xsl:for-each select="Page/*[@Code='Inner_CadastralNumbers']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Inner_CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Inner_CadastralNumbers>
                    </xsl:if>
                    <xsl:for-each select="Page[@Code='Areas']/*[@Code='Area' and @Selected='true']/*">
                      <Area>
                        <Area>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Area'"/>
                          </xsl:call-template>
                        </Area>
                        <Unit>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Unit'"/>
                          </xsl:call-template>
                        </Unit>
                        <xsl:variable name="TestMP1">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Innccuracy'"/>
                          </xsl:call-template>
                        </xsl:variable>
                        <xsl:if test="$TestMP1!=''">
                          <Innccuracy>
                            <xsl:value-of select="$TestMP1"/>
                          </Innccuracy>
                        </xsl:if>
                      </Area>
                    </xsl:for-each>
                    <xsl:for-each select="Page[@Code='Parcels']/*[@Code='ParcelAddress' and @Selected='true']/*[@Selected='true']">
                      <Location>
                        <xsl:variable name="TestMPL5">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Address'"/>
                          </xsl:call-template>
                        </xsl:variable>
                        <xsl:if test="$TestMPL5!=''">
                          <Note>
                            <xsl:value-of select="$TestMPL5"/>
                          </Note>
                        </xsl:if>
                      </Location>
                    </xsl:for-each>
                    <xsl:for-each select="Page/*[@Code='Category' and @Selected='true']/*">
                      <Category>
                        <xsl:attribute name="Category">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Category'"/>
                          </xsl:call-template>
                        </xsl:attribute>
                      </Category>
                    </xsl:for-each>
                    <!-- Заглушка - начало -->
                    <xsl:for-each select="Page/*[@Code='NaturalObject' and @Selected='true']/*">
                      <NaturalObject>
                        <Name>033001000000</Name>
                        <ForestUse>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'ForestUse'"/>
                          </xsl:call-template>
                        </ForestUse>
                        <Type_ProtectiveForest>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Type_ProtectiveForest'"/>
                          </xsl:call-template>
                        </Type_ProtectiveForest>
                      </NaturalObject>
                    </xsl:for-each>
                    <xsl:for-each select="Page/*[@Code='Utilization' and @Selected='true']/*">
                      <Utilization>
                        <xsl:attribute name="ByDoc">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'ByDoc'"/>
                          </xsl:call-template>
                        </xsl:attribute>
                        <xsl:attribute name="Kind">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Kind'"/>
                          </xsl:call-template>
                        </xsl:attribute>
                      </Utilization>
                    </xsl:for-each>
                    <xsl:if test="../Form[(@Code='NWZPart') and @ParentID=$ParentID1 and @Selected='true']">
                      <SubParcels>
                        <xsl:for-each select="../Form[(@Code='NWZPart') and @ParentID=$ParentID1 and @Selected='true']">
                          <SubParcel>
                            <xsl:call-template name="SubParcel">
                              <xsl:with-param name="ZUDesignation" select="$ZUDesignation"/>
                              <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                            </xsl:call-template>
                          </SubParcel>
                        </xsl:for-each>
                      </SubParcels>
                    </xsl:if>
                    <xsl:choose>
                      <xsl:when test="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*) > 1">
                        <xsl:call-template name="Contours">
                          <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                        </xsl:call-template>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:call-template name="Entity_Spatial">
                          <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                        </xsl:call-template>
                      </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="Page/*[@Code='Encumbrances' and @Selected='true']">
                      <Encumbrances>
                        <xsl:for-each select="Page/*[@Code='Encumbrances']/*">
                          <xsl:call-template name="Encumbrance"/>
                        </xsl:for-each>
                      </Encumbrances>
                    </xsl:if>
                  </NewParcel>
                </xsl:for-each>
                <xsl:for-each select="../Form[(@Code='MDZ') and @ParentID=$ParentID0 and @Selected='true']">
                  <xsl:variable name="ParentID1">
                    <xsl:value-of select="@Code"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="@ID"/>
                  </xsl:variable>
                  <ChangeParcel>
                    <xsl:variable name="ZUCadastralNumber">
                      <xsl:choose>
                        <xsl:when test="$Method='3' and count(../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true'])>1">
                          <xsl:for-each select="../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel']/*[ParamSelect[@Code='Name']/*[@Selected='true']/@Code='02']">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'CadastralNumber'"/>
                            </xsl:call-template>
                          </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:for-each select="(../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel']/*)[1]">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'CadastralNumber'"/>
                            </xsl:call-template>
                          </xsl:for-each>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:variable>
                    <xsl:attribute name="CadastralNumber">
                      <xsl:value-of select="$ZUCadastralNumber"/>
                    </xsl:attribute>
                    <CadastralBlock>
                      <xsl:value-of select="$BlockCadastralNumber"/>
                    </CadastralBlock>
                    <xsl:if test="Page/*[@Code='Providing_Pass_CadastralNumbers' and @Selected='true']">
                      <Providing_Pass_CadastralNumbers>
                        <xsl:for-each select="Page/*[@Code='Providing_Pass_CadastralNumbers']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Providing_Pass_CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Providing_Pass_CadastralNumbers>
                    </xsl:if>
                    <xsl:if test="Page/*[@Code='Inner_CadastralNumbers' and @Selected='true']">
                      <Inner_CadastralNumbers>
                        <xsl:for-each select="Page/*[@Code='Inner_CadastralNumbers']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Inner_CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Inner_CadastralNumbers>
                    </xsl:if>
                    <xsl:if test="../Form[(@Code='MDZPart') and @ParentID=$ParentID1 and @Selected='true']">
                      <SubParcels>
                        <xsl:for-each select="../Form[(@Code='MDZPart') and @ParentID=$ParentID1 and @Selected='true']">
                          <SubParcel>
                            <xsl:call-template name="SubParcel">
                              <xsl:with-param name="ZUCadastralNumber" select="$ZUCadastralNumber"/>
                              <!--xsl:with-param name="ZUDesignation" select="$ZUDesignation"/-->
                              <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                            </xsl:call-template>
                          </SubParcel>
                        </xsl:for-each>
                      </SubParcels>
                    </xsl:if>

                    <xsl:if test="Page/*[@Code='Delete_CadastralNumbers' and @Selected='true']">
                      <DeleteEntryParcels>
                        <xsl:for-each select="Page/*[@Code='Delete_CadastralNumbers']/*">
                          <DeleteEntryParcel>
                            <xsl:attribute name="CadastralNumber">
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Delete_CadastralNumber'"/>
                              </xsl:call-template>
                            </xsl:attribute>
                          </DeleteEntryParcel>
                        </xsl:for-each>
                      </DeleteEntryParcels>
                    </xsl:if>

                    <xsl:if test="Page/*[@Code='Insert_CadastralNumbers' and @Selected='true']">
                      <InsertEntryParcels>
                        <xsl:for-each select="Page/*[@Code='Insert_CadastralNumbers']/*">
                          <InsertEntryParcel>
                            <xsl:variable name="CN_D">
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Insert_CadastralNumber'"/>
                              </xsl:call-template>
                            </xsl:variable>
                            <xsl:choose>
                              <xsl:when test="$CN_D!=''">
                                <xsl:attribute name="CadastralNumber">
                                  <xsl:call-template name="Value">
                                    <xsl:with-param name="x" select="'Insert_CadastralNumber'"/>
                                  </xsl:call-template>
                                </xsl:attribute>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:variable name="NWZSetID">
                                  <xsl:call-template name="Value">
                                    <xsl:with-param name="x" select="'NWZ'"/>
                                  </xsl:call-template>
                                </xsl:variable>
                                <xsl:attribute name="Definition">
                                  <xsl:for-each select="//Form[@Code='NWZ' and @SetID = $NWZSetID]/Page[@Code='Parcels']/*[@Code='Parcel']/*">
                                    <xsl:call-template name="Value">
                                      <xsl:with-param name="x" select="'Designation'"/>
                                    </xsl:call-template>
                                  </xsl:for-each>
                                </xsl:attribute>
                              </xsl:otherwise>
                            </xsl:choose>
                          </InsertEntryParcel>
                        </xsl:for-each>
                      </InsertEntryParcels>
                    </xsl:if>
                    <xsl:if test="Page/*[@Code='Encumbrances' and @Selected='true']">
                      <Encumbrances>
                        <xsl:for-each select="Page/*[@Code='Encumbrances']/*">
                          <xsl:call-template name="Encumbrance"/>
                        </xsl:for-each>
                      </Encumbrances>
                    </xsl:if>
                  </ChangeParcel>
                </xsl:for-each>
                <xsl:for-each select="../Form[(@Code='NBZ') and @ParentID=$ParentID0 and @Selected='true']">
                  <xsl:variable name="ParentID1">
                    <xsl:value-of select="@Code"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="@ID"/>
                  </xsl:variable>
                  <xsl:call-template name="SpecifyRelatedParcel"/>
                </xsl:for-each>
              </FormParcels>
            </xsl:if>
            <xsl:if test="$CodeReg='chz' and $Method='SP1'">
              <SpecifyParcels>
                <xsl:for-each select="../Form[(@Code='CHZ') and @ParentID=$ParentID0 and @Selected='true']">
                  <xsl:variable name="MultiContour" select="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*)"/>
                  <xsl:variable name="ParentID1">
                    <xsl:value-of select="@Code"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="@ID"/>
                  </xsl:variable>
                  <ExistParcel>
                    <xsl:variable name="ZUCadastralNumber">
                      <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                        <xsl:call-template name="Value">
                          <xsl:with-param name="x" select="'CadastralNumber'"/>
                        </xsl:call-template>
                      </xsl:for-each>
                    </xsl:variable>
                    <xsl:attribute name="CadastralNumber">
                      <xsl:value-of select="$ZUCadastralNumber"/>
                    </xsl:attribute>
                    <CadastralBlock>
                      <xsl:value-of select="$BlockCadastralNumber"/>
                    </CadastralBlock>
                    <xsl:if test="Page/*[@Code='Inner_CadastralNumbers' and @Selected='true']">
                      <Inner_CadastralNumbers>
                        <xsl:for-each select="Page/*[@Code='Inner_CadastralNumbers']/*">
                          <CadastralNumber>
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Inner_CadastralNumber'"/>
                            </xsl:call-template>
                          </CadastralNumber>
                        </xsl:for-each>
                      </Inner_CadastralNumbers>
                    </xsl:if>
                    <xsl:for-each select="Page[@Code='Areas']/*[@Code='Area' and @Selected='true']/*">
                      <Area>
                        <Area>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Area'"/>
                          </xsl:call-template>
                        </Area>
                        <Unit>
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Unit'"/>
                          </xsl:call-template>
                        </Unit>
                        <xsl:variable name="TestMP1">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Innccuracy'"/>
                          </xsl:call-template>
                        </xsl:variable>
                        <xsl:if test="$TestMP1!=''">
                          <Innccuracy>
                            <xsl:value-of select="$TestMP1"/>
                          </Innccuracy>
                        </xsl:if>
                      </Area>
                    </xsl:for-each>
                    <xsl:if test="../Form[(@Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true']">
                      <SubParcels>
                        <xsl:for-each select="../Form[(@Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true']">
                          <SubParcel>
                            <xsl:call-template name="SubParcel">
                              <xsl:with-param name="ZUCadastralNumber" select="$ZUCadastralNumber"/>
                              <!--xsl:with-param name="ZUDesignation" select="$ZUDesignation"/-->
                              <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                            </xsl:call-template>
                          </SubParcel>
                        </xsl:for-each>
                      </SubParcels>
                    </xsl:if>
                    <xsl:choose>
                      <xsl:when test="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*) > 1">
                        <xsl:call-template name="Contours">
                          <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                        </xsl:call-template>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:call-template name="Entity_Spatial">
                          <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                        </xsl:call-template>
                      </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="Page/*[@Code='Encumbrances' and @Selected='true']">
                      <Encumbrances>
                        <xsl:for-each select="Page/*[@Code='Encumbrances']/*">
                          <xsl:call-template name="Encumbrance"/>
                        </xsl:for-each>
                      </Encumbrances>
                    </xsl:if>
                  </ExistParcel>
                </xsl:for-each>
                <xsl:for-each select="../Form[(@Code='NBZ') and @ParentID=$ParentID0 and @Selected='true']">
                  <xsl:variable name="ParentID1">
                    <xsl:value-of select="@Code"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="@ID"/>
                  </xsl:variable>
                  <xsl:call-template name="SpecifyRelatedParcel"/>
                </xsl:for-each>
              </SpecifyParcels>
            </xsl:if>
            <xsl:if test="$CodeReg='chz' and $Method='SP0'">
              <xsl:for-each select="../Form[(@Code='CHZ') and @ParentID=$ParentID0 and @Selected='true']">
                <xsl:variable name="ParentID1">
                  <xsl:value-of select="@Code"/>
                  <xsl:text>_</xsl:text>
                  <xsl:value-of select="@ID"/>
                </xsl:variable>
                <xsl:variable name="ZUCadastralNumber">
                  <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                    <xsl:call-template name="Value">
                      <xsl:with-param name="x" select="'CadastralNumber'"/>
                    </xsl:call-template>
                  </xsl:for-each>
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="count(../Form[(@Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true'])=0">
                    <NewSubParcel SubParcel_Realty="0" Definition="">
                      <CadastralNumber_Parcel>
                        <xsl:value-of select="$ZUCadastralNumber"/>
                      </CadastralNumber_Parcel>
                      <Area>
                        <Area>0</Area>
                        <Unit>055</Unit>
                        <Innccuracy>0</Innccuracy>
                      </Area>
                      <Encumbrance>
                        <Type>022001000000</Type>
                      </Encumbrance>
                      <Entity_Spatial>
                        <Spatial_Element>
                          <Spelement_Unit>
                            <Ordinate Ord_Nmb="0" X="0" Y="0"/>
                          </Spelement_Unit>
                        </Spatial_Element>
                      </Entity_Spatial>
                    </NewSubParcel>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:for-each select="../Form[(@Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true']">
                      <NewSubParcel>
                        <xsl:call-template name="SubParcel">
                          <xsl:with-param name="ZUCadastralNumber" select="$ZUCadastralNumber"/>
                          <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                          <xsl:with-param name="NewSubParcel" select="'true'"/>
                        </xsl:call-template>
                      </NewSubParcel>
                    </xsl:for-each>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>
            </xsl:if>
          </Package>
          <Contractor>
            <xsl:choose>
              <xsl:when test="$JFSender='J'">
                <!--Cadastral_Organization>
                  <Name>
                    <xsl:value-of select="$Organization"/>
                  </Name>
                  <Code_OGRN>
                    <xsl:value-of select="$OGRN"/>
                  </Code_OGRN>
                  <INN>
                    <xsl:value-of select="$INNJ"/>
                  </INN>
                  <Telephone>
                    <xsl:value-of select="$Phone"/>
                  </Telephone>
                  <E_mail>
                    <xsl:value-of select="$Email"/>
                  </E_mail>
                  <Address>
                    <xsl:value-of select="$Address"/>
                  </Address>
                </Cadastral_Organization-->
                <Cadastral_Engineer>
                  <FIO>
                    <Surname>
                      <xsl:value-of select="$FIO1"/>
                    </Surname>
                    <First>
                      <xsl:value-of select="$FIO2"/>
                    </First>
                    <Patronymic>
                      <xsl:value-of select="$FIO3"/>
                    </Patronymic>
                  </FIO>
                  <N_Certificate>
                    <xsl:value-of select="$CertN"/>
                  </N_Certificate>
                  <INN>
                    <xsl:value-of select="$INNF"/>
                  </INN>
                  <Telephone>
                    <xsl:value-of select="$Phone"/>
                  </Telephone>
                  <E_mail>
                    <xsl:value-of select="$Email"/>
                  </E_mail>
                  <Address>
                    <xsl:value-of select="$Address"/>
                  </Address>
                  <Organization>
                    <Name>
                      <xsl:value-of select="$Organization"/>
                    </Name>
                    <Code_OGRN>
                      <xsl:value-of select="$OGRN"/>
                    </Code_OGRN>
                    <INN>
                      <xsl:value-of select="$INNJ"/>
                    </INN>
                    <Telephone>
                      <xsl:value-of select="$Phone"/>
                    </Telephone>
                    <E_mail>
                      <xsl:value-of select="$Email"/>
                    </E_mail>
                    <Address>
                      <xsl:value-of select="$Address"/>
                    </Address>
                  </Organization>
                </Cadastral_Engineer>
              </xsl:when>
              <xsl:when test="$JFSender='F'">
                <Cadastral_Engineer>
                  <FIO>
                    <Surname>
                      <xsl:value-of select="$FIO1"/>
                    </Surname>
                    <First>
                      <xsl:value-of select="$FIO2"/>
                    </First>
                    <Patronymic>
                      <xsl:value-of select="$FIO3"/>
                    </Patronymic>
                  </FIO>
                  <N_Certificate>
                    <xsl:value-of select="$CertN"/>
                  </N_Certificate>
                  <INN>
                    <xsl:value-of select="$INNF"/>
                  </INN>
                  <Telephone>
                    <xsl:value-of select="$Phone"/>
                  </Telephone>
                  <E_mail>
                    <xsl:value-of select="$Email"/>
                  </E_mail>
                  <Address>
                    <xsl:value-of select="$Address"/>
                  </Address>
                </Cadastral_Engineer>
              </xsl:when>
            </xsl:choose>
          </Contractor>
        </xsl:when>
        <xsl:otherwise>
          <Package>
            <Cadastral_Blocks>
              <Cadastral_Block>
                <xsl:attribute name="CadastralNumber">
                  <xsl:value-of select="$BlockCadastralNumber"/>
                </xsl:attribute>
                <Parcels>
                  <xsl:for-each select="../Form[(@Code='NWZ' or @Code='CHZ') and @ParentID=$ParentID0 and @Selected='true']">
                    <xsl:variable name="MultiContour" select="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*)"/>
                    <xsl:variable name="ParentID1">
                      <xsl:value-of select="@Code"/>
                      <xsl:text>_</xsl:text>
                      <xsl:value-of select="@ID"/>
                    </xsl:variable>
                    <Parcel>
                      <xsl:variable name="ZUDesignation">
                        <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'Designation'"/>
                          </xsl:call-template>
                        </xsl:for-each>
                      </xsl:variable>
                      <xsl:variable name="ZUCadastralNumber">
                        <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'CadastralNumber'"/>
                          </xsl:call-template>
                        </xsl:for-each>
                      </xsl:variable>
                      <xsl:for-each select="Page[@Code='Parcels']/*[@Code='Parcel']/*">
                        <xsl:attribute name="AdditionalName">
                          <xsl:call-template name="Value">
                            <xsl:with-param name="x" select="'AdditionalName'"/>
                          </xsl:call-template>
                        </xsl:attribute>
                        <xsl:if test="$CodeReg='nwz'">
                          <xsl:attribute name="Method">
                            <xsl:value-of select="$Method"/>
                          </xsl:attribute>
                          <xsl:attribute name="Name">
                            <xsl:choose>
                              <xsl:when test="$MultiContour > 1">
                                <xsl:value-of select="'05'"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:call-template name="Value">
                                  <xsl:with-param name="x" select="'Name'"/>
                                </xsl:call-template>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:attribute>
                        </xsl:if>
                        <xsl:if test="$ZUCadastralNumber!=''">
                          <xsl:attribute name="CadastralNumber">
                            <xsl:value-of select="$ZUCadastralNumber"/>
                          </xsl:attribute>
                        </xsl:if>
                        <xsl:attribute name="Definition">
                          <xsl:value-of select="$ZUDesignation"/>
                        </xsl:attribute>
                        <xsl:attribute name="GUID">
                          <xsl:value-of select="../../../Page/@SetID"/>
                        </xsl:attribute>
                      </xsl:for-each>
                      <Contactor>
                        <xsl:attribute name="Date">
                          <xsl:value-of select="$Date"/>
                        </xsl:attribute>
                        <xsl:choose>
                          <xsl:when test="$JFSender='J'">
                            <GUID_UL>
                              <xsl:value-of select="$GUID_Contractor"/>
                            </GUID_UL>
                          </xsl:when>
                          <xsl:when test="$JFSender='F'">
                            <GUID_FL>
                              <xsl:value-of select="$GUID_Contractor"/>
                            </GUID_FL>
                          </xsl:when>
                        </xsl:choose>
                      </Contactor>
                      <xsl:if test="../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel' and @Selected='true']">
                        <Prev_CadastralNumbers>
                          <xsl:for-each select="../Form[@Code='OLZ' and @ParentID=$ParentID0 and @Selected='true']/Page[@Code='Parcels']/*[@Code='Parcel']/*">
                            <CadastralNumber>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'CadastralNumber'"/>
                              </xsl:call-template>
                            </CadastralNumber>
                          </xsl:for-each>
                        </Prev_CadastralNumbers>
                      </xsl:if>
                      <xsl:if test="Page/*[@Code='Providing_Pass_CadastralNumbers' and @Selected='true']">
                        <Providing_Pass_CadastralNumbers>
                          <xsl:for-each select="Page/*[@Code='Providing_Pass_CadastralNumbers']/*">
                            <CadastralNumber>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Providing_Pass_CadastralNumber'"/>
                              </xsl:call-template>
                            </CadastralNumber>
                          </xsl:for-each>
                        </Providing_Pass_CadastralNumbers>
                      </xsl:if>
                      <xsl:if test="Page/*[@Code='Inner_CadastralNumbers' and @Selected='true']">
                        <Inner_CadastralNumbers>
                          <xsl:for-each select="Page/*[@Code='Inner_CadastralNumbers']/*">
                            <CadastralNumber>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Inner_CadastralNumber'"/>
                              </xsl:call-template>
                            </CadastralNumber>
                          </xsl:for-each>
                        </Inner_CadastralNumbers>
                      </xsl:if>
                      <Areas>
                        <xsl:for-each select="Page[@Code='Areas']/*[@Code='Area' and @Selected='true']/*">
                          <Area>
                            <AreaCode>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'AreaCode'"/>
                              </xsl:call-template>
                            </AreaCode>
                            <Area>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Area'"/>
                              </xsl:call-template>
                            </Area>
                            <Unit>
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Unit'"/>
                              </xsl:call-template>
                            </Unit>
                            <xsl:variable name="TestMP1">
                              <xsl:call-template name="Value">
                                <xsl:with-param name="x" select="'Innccuracy'"/>
                              </xsl:call-template>
                            </xsl:variable>
                            <xsl:if test="$TestMP1!=''">
                              <Innccuracy>
                                <xsl:value-of select="$TestMP1"/>
                              </Innccuracy>
                            </xsl:if>
                          </Area>
                        </xsl:for-each>
                      </Areas>
                      <xsl:for-each select="Page[@Code='Parcels']/*[@Code='ParcelAddress' and @Selected='true']/*[@Selected='true']">
                        <Location>
                          <xsl:variable name="TestMPL0">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'inBounds'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:if test="TestMPL0">
                            <inBounds>
                              <xsl:value-of select="$TestMPL0"/>
                            </inBounds>
                          </xsl:if>
                          <xsl:variable name="TestMPL1">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Placed'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:if test="$TestMPL1!=''">
                            <Placed>
                              <xsl:value-of select="$TestMPL1"/>
                            </Placed>
                          </xsl:if>
                          <xsl:variable name="TestMPL2">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'ReferenceMark'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:variable name="TestMPL3">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Distance'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:variable name="TestMPL4">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Direction'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:if test="$TestMPL2!='' or $TestMPL3!='' or $TestMPL4!=''">
                            <Elaboration>
                              <ReferenceMark>
                                <xsl:value-of select="$TestMPL2"/>
                              </ReferenceMark>
                              <Distance>
                                <xsl:value-of select="$TestMPL3"/>
                              </Distance>
                              <Direction>
                                <xsl:value-of select="$TestMPL4"/>
                              </Direction>
                            </Elaboration>
                          </xsl:if>
                          <xsl:variable name="TestMPL5">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Address'"/>
                            </xsl:call-template>
                          </xsl:variable>
                          <xsl:if test="$TestMPL5!=''">
                            <Address>
                              <Note>
                                <xsl:value-of select="$TestMPL5"/>
                              </Note>
                            </Address>
                          </xsl:if>
                        </Location>
                      </xsl:for-each>

                      <xsl:for-each select="Page/*[@Code='Category' and @Selected='true']/*">
                        <Category>
                          <xsl:attribute name="Category">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Category'"/>
                            </xsl:call-template>
                          </xsl:attribute>
                        </Category>
                      </xsl:for-each>

                      <xsl:for-each select="Page/*[@Code='Utilization' and @Selected='true']/*">
                        <Utilization>
                          <xsl:attribute name="ByDoc">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'ByDoc'"/>
                            </xsl:call-template>
                          </xsl:attribute>
                          <xsl:attribute name="Kind">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Kind'"/>
                            </xsl:call-template>
                          </xsl:attribute>
                          <xsl:attribute name="Fakt">
                            <xsl:call-template name="Value">
                              <xsl:with-param name="x" select="'Fakt'"/>
                            </xsl:call-template>
                          </xsl:attribute>
                        </Utilization>
                      </xsl:for-each>

                      <xsl:if test="../Form[(@Code='NWZPart' or @Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true']">
                        <SubParcels>
                          <xsl:for-each select="../Form[(@Code='NWZPart' or @Code='CHZPart') and @ParentID=$ParentID1 and @Selected='true']">
                            <SubParcel>
                              <xsl:for-each select="Page[@Code='SubParcels']/*[@Code='SubParcel']/*[not(@Selected='false')]">
                                <xsl:attribute name="Full">
                                  <xsl:value-of select="'false'"/>
                                </xsl:attribute>
                                <xsl:variable name="TestOrd_Num">
                                  <xsl:call-template name="Value">
                                    <xsl:with-param name="x" select="'Ord_Num'"/>
                                  </xsl:call-template>
                                </xsl:variable>
                                <xsl:if test="$TestOrd_Num!=''">
                                  <xsl:attribute name="Number_PP">
                                    <xsl:value-of select="$TestOrd_Num"/>
                                  </xsl:attribute>
                                </xsl:if>
                                <xsl:variable name="TestDesignation">
                                  <xsl:call-template name="Value">
                                    <xsl:with-param name="x" select="'Designation'"/>
                                  </xsl:call-template>
                                </xsl:variable>
                                <xsl:if test="$TestDesignation!=''">
                                  <xsl:attribute name="Definition">
                                    <xsl:if test="substring($TestDesignation,1,3)='чзу'">
                                      <xsl:choose>
                                        <xsl:when test="$ZUCadastralNumber!=''">
                                          <xsl:value-of select="$ZUCadastralNumber"/>
                                          <xsl:text>/</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$ZUDesignation!=''">
                                          <xsl:value-of select="$ZUDesignation"/>
                                          <xsl:text>/</xsl:text>
                                        </xsl:when>
                                      </xsl:choose>
                                    </xsl:if>
                                    <xsl:value-of select="$TestDesignation"/>
                                  </xsl:attribute>
                                </xsl:if>
                              </xsl:for-each>
                              <Areas>
                                <xsl:for-each select="Page[@Code='Areas']/*[@Code='Area' and @Selected='true']/*">
                                  <Area>
                                    <AreaCode>
                                      <xsl:call-template name="Value">
                                        <xsl:with-param name="x" select="'AreaCode'"/>
                                      </xsl:call-template>
                                    </AreaCode>
                                    <Area>
                                      <xsl:call-template name="Value">
                                        <xsl:with-param name="x" select="'Area'"/>
                                      </xsl:call-template>
                                    </Area>
                                    <Unit>
                                      <xsl:call-template name="Value">
                                        <xsl:with-param name="x" select="'Unit'"/>
                                      </xsl:call-template>
                                    </Unit>
                                    <xsl:variable name="TestMP3">
                                      <xsl:call-template name="Value">
                                        <xsl:with-param name="x" select="'Innccuracy'"/>
                                      </xsl:call-template>
                                    </xsl:variable>
                                    <xsl:if test="$TestMP3!=''">
                                      <Innccuracy>
                                        <xsl:value-of select="$TestMP3"/>
                                      </Innccuracy>
                                    </xsl:if>
                                  </Area>
                                </xsl:for-each>
                              </Areas>
                              <xsl:if test="Page[@Code='SubParcels']/*[@Code='Encumbrances' and @Selected='true']">
                                <Encumbrances>
                                  <xsl:for-each select="Page[@Code='SubParcels']/*[@Code='Encumbrances']/*">
                                    <Encumbrance>
                                      <Name>
                                        <xsl:call-template name="Value">
                                          <xsl:with-param name="x" select="'Name'"/>
                                        </xsl:call-template>
                                      </Name>
                                      <Type>
                                        <xsl:call-template name="Value">
                                          <xsl:with-param name="x" select="'Type'"/>
                                        </xsl:call-template>
                                      </Type>
                                    </Encumbrance>
                                  </xsl:for-each>
                                </Encumbrances>
                              </xsl:if>
                              <xsl:call-template name="Entity_Spatial">
                                <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                              </xsl:call-template>
                            </SubParcel>
                          </xsl:for-each>
                        </SubParcels>
                      </xsl:if>
                      <xsl:choose>
                        <xsl:when test="count(Page[@Code='Entity_Spatial']/*[@Code='Square']/*) > 1">
                          <xsl:call-template name="Contours">
                            <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                          </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:call-template name="Entity_Spatial">
                            <xsl:with-param name="Cs_Id" select="$Cs_Id"/>
                          </xsl:call-template>
                        </xsl:otherwise>
                      </xsl:choose>
                    </Parcel>
                  </xsl:for-each>
                </Parcels>
              </Cadastral_Block>
            </Cadastral_Blocks>
          </Package>
          <Reestr_Contractors>
            <Reestr_Contractor>
              <xsl:choose>
                <xsl:when test="$JFSender='J'">
                  <Cadastral_Organization>
                    <Name>
                      <xsl:value-of select="$Organization"/>
                    </Name>
                    <INN>
                      <xsl:value-of select="$INNJ"/>
                    </INN>
                    <GUID_UL>
                      <xsl:value-of select="$GUID_Contractor"/>
                    </GUID_UL>
                  </Cadastral_Organization>
                </xsl:when>
                <xsl:when test="$JFSender='F'">
                  <Cadastral_Engineer>
                    <FIO>
                      <Surname>
                        <xsl:value-of select="$FIO1"/>
                      </Surname>
                      <First>
                        <xsl:value-of select="$FIO2"/>
                      </First>
                      <Patronymic>
                        <xsl:value-of select="$FIO3"/>
                      </Patronymic>
                    </FIO>
                    <GUID_FL>
                      <xsl:value-of select="$GUID_Contractor"/>
                    </GUID_FL>
                    <N_Certificate>
                      <xsl:value-of select="$CertN"/>
                    </N_Certificate>
                  </Cadastral_Engineer>
                </xsl:when>
              </xsl:choose>
            </Reestr_Contractor>
          </Reestr_Contractors>
        </xsl:otherwise>
      </xsl:choose>

      <Coord_Systems>
        <xsl:for-each select="Page[@Code='BasicData' or @Code='Coord_System']/*[@Code='Coord_System']/*">
          <Coord_System>
            <xsl:attribute name="Cs_Id">
              <xsl:value-of select="$Cs_Id"/>
            </xsl:attribute>
            <xsl:attribute name="Name">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Name'"/>
              </xsl:call-template>
            </xsl:attribute>
            <xsl:attribute name="Description">
              <xsl:call-template name="Value">
                <xsl:with-param name="x" select="'Description'"/>
              </xsl:call-template>
            </xsl:attribute>
            <xsl:for-each select="../../*[@Code='X']/*">
              <Dim Name="X">
                <xsl:variable name="TestDX1">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Lowerbound'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDX1!=''">
                  <xsl:attribute name="Lowerbound">
                    <xsl:value-of select="$TestDX1"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:variable name="TestDX2">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Upperbound'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDX2!=''">
                  <xsl:attribute name="Upperbound">
                    <xsl:value-of select="$TestDX2"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:variable name="TestDX3">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Tolerance'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDX3!=''">
                  <xsl:attribute name="Tolerance">
                    <xsl:value-of select="$TestDX3"/>
                  </xsl:attribute>
                </xsl:if>
              </Dim>
            </xsl:for-each>
            <xsl:for-each select="../../*[@Code='Y']/*">
              <Dim Name="Y">
                <xsl:variable name="TestDY1">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Lowerbound'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDY1!=''">
                  <xsl:attribute name="Lowerbound">
                    <xsl:value-of select="$TestDY1"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:variable name="TestDY2">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Upperbound'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDY2!=''">
                  <xsl:attribute name="Upperbound">
                    <xsl:value-of select="$TestDY2"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:variable name="TestDY3">
                  <xsl:call-template name="Value">
                    <xsl:with-param name="x" select="'Tolerance'"/>
                  </xsl:call-template>
                </xsl:variable>
                <xsl:if test="$TestDY3!=''">
                  <xsl:attribute name="Tolerance">
                    <xsl:value-of select="$TestDY3"/>
                  </xsl:attribute>
                </xsl:if>
              </Dim>
            </xsl:for-each>
            <xsl:if test="count(../../*[@Code='X'])=0">
              <Dim />
              <Dim />
            </xsl:if>
          </Coord_System>
        </xsl:for-each>
      </Coord_Systems>
    </STD_MP>
  </xsl:template>

</xsl:stylesheet>
