使用XSLT识别并消除XML中的重复项

时间:2017-01-24 07:45:48

标签: xml xslt

我刚开始使用XSLT,所以我真的需要你的帮助 我有一个包含地址分支的列表,如下所示。

<addressList>
        <address>
            <uid>14666</uid>
            <address1>PO Box 11365-171, Ferdowsi Avenue</address1>
            <city>Tehran</city>
            <country>Iran</country>
        </address>
        <address>
            <uid>16967</uid>
            <address1>43 Avenue Montaigne</address1>
            <city>Paris</city>
            <postalCode>75008</postalCode>
            <country>France</country>
        </address>
        <address>
            <uid>16968</uid>
            <address1>Room 704-6, Wheelock Hse, 20 Pedder St, Central</address1>
            <country>Hong Kong</country>
        </address>
        <address>
            <uid>16969</uid>
            <address1>Bank Melli Iran Bldg, 111 St 24, 929 Arasat</address1>
            <city>Baghdad</city>
            <country>Iraq</country>
        </address>
        <address>
            <uid>16970</uid>
            <address1>PO Box 2643, Ruwi</address1>
            <city>Muscat</city>
            <postalCode>112</postalCode>
            <country>Oman</country>
        </address>
        <address>
            <uid>16971</uid>
            <address1>PO Box 2656, Liva Street</address1>
            <city>Abu Dhabi</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16972</uid>
            <address1>PO Box 248, Hamad Bin Abdulla St</address1>
            <city>Fujairah</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16973</uid>
            <address1>PO Box 1888, Clock Tower, Industrial Rd, Al Ain Club Bldg, Al Ain</address1>
            <city>Abu Dhabi</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16974</uid>
            <address1>PO Box 1894, Baniyas St, Deira</address1>
            <city>Dubai City</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16975</uid>
            <address1>PO Box 5270, Oman Street Al Nakheel</address1>
            <city>Ras Al-Khaimah</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16976</uid>
            <address1>PO Box 459, Al Borj St</address1>
            <city>Sharjah</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16977</uid>
            <address1>PO Box 3093, Ahmed Seddiqui Bldg, Khalid Bin El-Walid St, Bur-Dubai</address1>
            <city>Dubai City</city>
            <postalCode>3093</postalCode>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16978</uid>
            <address1>PO Box 1894, Al Wasl Rd, Jumeirah</address1>
            <city>Dubai</city>
            <country>United Arab Emirates</country>
        </address>
        <address>
            <uid>16979</uid>
            <address1>Postfach 112 129, Holzbruecke 2, D-20459</address1>
            <city>Hamburg</city>
            <country>Germany</country>
        </address>
        <address>
            <uid>16980</uid>
            <address1>Nobel Ave. 14</address1>
            <city>Baku</city>
            <country>Azerbaijan</country>
        </address>
        <address>
            <uid>16981</uid>
            <address1>Unit 1703-4, 17th Floor, Hong Kong Club Building, 3 A Chater Road Central</address1>
            <country>Hong Kong</country>
        </address>
        <address>
            <uid>20368</uid>
            <address1>Esteghlal St., Opposite to Otbeh Ibn Ghazvan Hall</address1>
            <city>Basrah</city>
            <country>Iraq</country>
        </address>
    </addressList>

我使用XSLT来更改XML列表的格式,以便将其导入到其他程序中。因此,对于每个地址分支,我想获得一个不同的地址分支 我通过使用这个XSLT部分得到了这个:

<xsl:for-each select="addressList/address">
    <Country>
        <CountryCode>
            <xsl:choose>
                <xsl:when test="country='Afghanistan'">AF</xsl:when>
                <xsl:when test="country='Åland Islands'">AX</xsl:when>
                <xsl:when test="country='Albania'">AL</xsl:when>
                <xsl:when test="country='Algeria'">DZ</xsl:when>
                <xsl:when test="country='American Samoa'">AS</xsl:when>
                <xsl:when test="country='Andorra'">AD</xsl:when>
                <xsl:when test="country='Angola'">AO</xsl:when>
                <xsl:when test="country='Anguilla'">AI</xsl:when>
                <xsl:when test="country='Antarctica'">AQ</xsl:when>
                <xsl:when test="country='Antigua and Barbuda'">AG</xsl:when>
                <xsl:when test="country='Argentina'">AR</xsl:when>
                <xsl:when test="country='Armenia'">AM</xsl:when>
                <xsl:when test="country='Aruba'">AW</xsl:when>
                <xsl:when test="country='Australia'">AU</xsl:when>
                <xsl:when test="country='Austria'">AT</xsl:when>
                <xsl:when test="country='Azerbaijan'">AZ</xsl:when>
                <xsl:when test="country='Bahamas'">BS</xsl:when>
                <xsl:when test="country='Bahrain'">BH</xsl:when>
                <xsl:when test="country='Bangladesh'">BD</xsl:when>
                <xsl:when test="country='Barbados'">BB</xsl:when>
                <xsl:when test="country='Belarus'">BY</xsl:when>
                <xsl:when test="country='Belgium'">BE</xsl:when>
                <xsl:when test="country='Belize'">BZ</xsl:when>
                <xsl:when test="country='Benin'">BJ</xsl:when>
                <xsl:when test="country='Bermuda'">BM</xsl:when>
                <xsl:when test="country='Bhutan'">BT</xsl:when>
                <xsl:when test="country='Bolivia, Plurinational State of'">BO</xsl:when>
                <xsl:when test="country='Bonaire, Sint Eustatius and Saba'">BQ</xsl:when>
                <xsl:when test="country='Bosnia and Herzegovina'">BA</xsl:when>
                <xsl:when test="country='Botswana'">BW</xsl:when>
                <xsl:when test="country='Bouvet Island'">BV</xsl:when>
                <xsl:when test="country='Brazil'">BR</xsl:when>
                <xsl:when test="country='British Indian Ocean Territory'">IO</xsl:when>
                <xsl:when test="country='Brunei Darussalam'">BN</xsl:when>
                <xsl:when test="country='Bulgaria'">BG</xsl:when>
                <xsl:when test="country='Burkina Faso'">BF</xsl:when>
                <xsl:when test="country='Burundi'">BI</xsl:when>
                <xsl:when test="country='Cambodia'">KH</xsl:when>
                <xsl:when test="country='Cameroon'">CM</xsl:when>
                <xsl:when test="country='Canada'">CA</xsl:when>
                <xsl:when test="country='Cape Verde'">CV</xsl:when>
                <xsl:when test="country='Cayman Islands'">KY</xsl:when>
                <xsl:when test="country='Central African Republic'">CF</xsl:when>
                <xsl:when test="country='Chad'">TD</xsl:when>
                <xsl:when test="country='Chile'">CL</xsl:when>
                <xsl:when test="country='China'">CN</xsl:when>
                <xsl:when test="country='Christmas Island'">CX</xsl:when>
                <xsl:when test="country='Cocos (Keeling) Islands'">CC</xsl:when>
                <xsl:when test="country='Colombia'">CO</xsl:when>
                <xsl:when test="country='Comoros'">KM</xsl:when>
                <xsl:when test="country='Congo'">CG</xsl:when>
                <xsl:when test="country='Congo, the Democratic Republic of the'">CD</xsl:when>
                <xsl:when test="country='Cook Islands'">CK</xsl:when>
                <xsl:when test="country='Costa Rica'">CR</xsl:when>
                <xsl:when test="country='Côte d Ivoire'">CI</xsl:when>
                <xsl:when test="country='Croatia'">HR</xsl:when>
                <xsl:when test="country='Cuba'">CU</xsl:when>
                <xsl:when test="country='Curaçao'">CW</xsl:when>
                <xsl:when test="country='Cyprus'">CY</xsl:when>
                <xsl:when test="country='Czech Republic'">CZ</xsl:when>
                <xsl:when test="country='Denmark'">DK</xsl:when>
                <xsl:when test="country='Djibouti'">DJ</xsl:when>
                <xsl:when test="country='Dominica'">DM</xsl:when>
                <xsl:when test="country='Dominican Republic'">DO</xsl:when>
                <xsl:when test="country='Ecuador'">EC</xsl:when>
                <xsl:when test="country='Egypt'">EG</xsl:when>
                <xsl:when test="country='El Salvador'">SV</xsl:when>
                <xsl:when test="country='Equatorial Guinea'">GQ</xsl:when>
                <xsl:when test="country='Eritrea'">ER</xsl:when>
                <xsl:when test="country='Estonia'">EE</xsl:when>
                <xsl:when test="country='Ethiopia'">ET</xsl:when>
                <xsl:when test="country='Falkland Islands (Malvinas)'">FK</xsl:when>
                <xsl:when test="country='Faroe Islands'">FO</xsl:when>
                <xsl:when test="country='Fiji'">FJ</xsl:when>
                <xsl:when test="country='Finland'">FI</xsl:when>
                <xsl:when test="country='France'">FR</xsl:when>
                <xsl:when test="country='French Guiana'">GF</xsl:when>
                <xsl:when test="country='French Polynesia'">PF</xsl:when>
                <xsl:when test="country='French Southern Territories'">TF</xsl:when>
                <xsl:when test="country='Gabon'">GA</xsl:when>
                <xsl:when test="country='Gambia'">GM</xsl:when>
                <xsl:when test="country='Georgia'">GE</xsl:when>
                <xsl:when test="country='Germany'">DE</xsl:when>
                <xsl:when test="country='Ghana'">GH</xsl:when>
                <xsl:when test="country='Gibraltar'">GI</xsl:when>
                <xsl:when test="country='Greece'">GR</xsl:when>
                <xsl:when test="country='Greenland'">GL</xsl:when>
                <xsl:when test="country='Grenada'">GD</xsl:when>
                <xsl:when test="country='Guadeloupe'">GP</xsl:when>
                <xsl:when test="country='Guam'">GU</xsl:when>
                <xsl:when test="country='Guatemala'">GT</xsl:when>
                <xsl:when test="country='Guernsey'">GG</xsl:when>
                <xsl:when test="country='Guinea'">GN</xsl:when>
                <xsl:when test="country='Guinea-Bissau'">GW</xsl:when>
                <xsl:when test="country='Guyana'">GY</xsl:when>
                <xsl:when test="country='Haiti'">HT</xsl:when>
                <xsl:when test="country='Heard Island and McDonald Islands'">HM</xsl:when>
                <xsl:when test="country='Holy See (Vatican City State)'">VA</xsl:when>
                <xsl:when test="country='Honduras'">HN</xsl:when>
                <xsl:when test="country='Hong Kong'">HK</xsl:when>
                <xsl:when test="country='Hungary'">HU</xsl:when>
                <xsl:when test="country='Iceland'">IS</xsl:when>
                <xsl:when test="country='India'">IN</xsl:when>
                <xsl:when test="country='Indonesia'">ID</xsl:when>
                <xsl:when test="country='Iran, Islamic Republic of'">IR</xsl:when>
                <xsl:when test="country='Iran'">IR</xsl:when>
                <xsl:when test="country='Iraq'">IQ</xsl:when>
                <xsl:when test="country='Ireland'">IE</xsl:when>
                <xsl:when test="country='Isle of Man'">IM</xsl:when>
                <xsl:when test="country='Israel'">IL</xsl:when>
                <xsl:when test="country='Italy'">IT</xsl:when>
                <xsl:when test="country='Jamaica'">JM</xsl:when>
                <xsl:when test="country='Japan'">JP</xsl:when>
                <xsl:when test="country='Jersey'">JE</xsl:when>
                <xsl:when test="country='Jordan'">JO</xsl:when>
                <xsl:when test="country='Kazakhstan'">KZ</xsl:when>
                <xsl:when test="country='Kenya'">KE</xsl:when>
                <xsl:when test="country='Kiribati'">KI</xsl:when>
                <xsl:when test="country='Korea, Democratic Peoples Republic of'">KP</xsl:when>
                <xsl:when test="country='Korea, Republic of'">KR</xsl:when>
                <xsl:when test="country='Kuwait'">KW</xsl:when>
                <xsl:when test="country='Kyrgyzstan'">KG</xsl:when>
                <xsl:when test="country='Lao Peoples Democratic Republic'">LA</xsl:when>
                <xsl:when test="country='Latvia'">LV</xsl:when>
                <xsl:when test="country='Lebanon'">LB</xsl:when>
                <xsl:when test="country='Lesotho'">LS</xsl:when>
                <xsl:when test="country='Liberia'">LR</xsl:when>
                <xsl:when test="country='Libya'">LY</xsl:when>
                <xsl:when test="country='Liechtenstein'">LI</xsl:when>
                <xsl:when test="country='Lithuania'">LT</xsl:when>
                <xsl:when test="country='Luxembourg'">LU</xsl:when>
                <xsl:when test="country='Macao'">MO</xsl:when>
                <xsl:when test="country='Macedonia, the Former Yugoslav Republic of'">MK</xsl:when>
                <xsl:when test="country='Madagascar'">MG</xsl:when>
                <xsl:when test="country='Malawi'">MW</xsl:when>
                <xsl:when test="country='Malaysia'">MY</xsl:when>
                <xsl:when test="country='Maldives'">MV</xsl:when>
                <xsl:when test="country='Mali'">ML</xsl:when>
                <xsl:when test="country='Malta'">MT</xsl:when>
                <xsl:when test="country='Marshall Islands'">MH</xsl:when>
                <xsl:when test="country='Martinique'">MQ</xsl:when>
                <xsl:when test="country='Mauritania'">MR</xsl:when>
                <xsl:when test="country='Mauritius'">MU</xsl:when>
                <xsl:when test="country='Mayotte'">YT</xsl:when>
                <xsl:when test="country='Mexico'">MX</xsl:when>
                <xsl:when test="country='Micronesia, Federated States of'">FM</xsl:when>
                <xsl:when test="country='Moldova, Republic of'">MD</xsl:when>
                <xsl:when test="country='Monaco'">MC</xsl:when>
                <xsl:when test="country='Mongolia'">MN</xsl:when>
                <xsl:when test="country='Montenegro'">ME</xsl:when>
                <xsl:when test="country='Montserrat'">MS</xsl:when>
                <xsl:when test="country='Morocco'">MA</xsl:when>
                <xsl:when test="country='Mozambique'">MZ</xsl:when>
                <xsl:when test="country='Myanmar'">MM</xsl:when>
                <xsl:when test="country='Namibia'">NA</xsl:when>
                <xsl:when test="country='Nauru'">NR</xsl:when>
                <xsl:when test="country='Nepal'">NP</xsl:when>
                <xsl:when test="country='Netherlands'">NL</xsl:when>
                <xsl:when test="country='New Caledonia'">NC</xsl:when>
                <xsl:when test="country='New Zealand'">NZ</xsl:when>
                <xsl:when test="country='Nicaragua'">NI</xsl:when>
                <xsl:when test="country='Niger'">NE</xsl:when>
                <xsl:when test="country='Nigeria'">NG</xsl:when>
                <xsl:when test="country='Niue'">NU</xsl:when>
                <xsl:when test="country='Norfolk Island'">NF</xsl:when>
                <xsl:when test="country='Northern Mariana Islands'">MP</xsl:when>
                <xsl:when test="country='Norway'">NO</xsl:when>
                <xsl:when test="country='Oman'">OM</xsl:when>
                <xsl:when test="country='Pakistan'">PK</xsl:when>
                <xsl:when test="country='Palau'">PW</xsl:when>
                <xsl:when test="country='Palestine, State of'">PS</xsl:when>
                <xsl:when test="country='Palestinian'">PS</xsl:when>
                <xsl:when test="country='Panama'">PA</xsl:when>
                <xsl:when test="country='Papua New Guinea'">PG</xsl:when>
                <xsl:when test="country='Paraguay'">PY</xsl:when>
                <xsl:when test="country='Peru'">PE</xsl:when>
                <xsl:when test="country='Philippines'">PH</xsl:when>
                <xsl:when test="country='Pitcairn'">PN</xsl:when>
                <xsl:when test="country='Poland'">PL</xsl:when>
                <xsl:when test="country='Portugal'">PT</xsl:when>
                <xsl:when test="country='Puerto Rico'">PR</xsl:when>
                <xsl:when test="country='Qatar'">QA</xsl:when>
                <xsl:when test="country='Réunion'">RE</xsl:when>
                <xsl:when test="country='Romania'">RO</xsl:when>
                <xsl:when test="country='Russia'">RU</xsl:when>
                <xsl:when test="country='Rwanda'">RW</xsl:when>
                <xsl:when test="country='Saint Barthélemy'">BL</xsl:when>
                <xsl:when test="country='Saint Helena, Ascension and Tristan da Cunha'">SH</xsl:when>
                <xsl:when test="country='Saint Kitts and Nevis'">KN</xsl:when>
                <xsl:when test="country='Saint Lucia'">LC</xsl:when>
                <xsl:when test="country='Saint Martin (French part)'">MF</xsl:when>
                <xsl:when test="country='Saint Pierre and Miquelon'">PM</xsl:when>
                <xsl:when test="country='Saint Vincent and the Grenadines'">VC</xsl:when>
                <xsl:when test="country='Samoa'">WS</xsl:when>
                <xsl:when test="country='San Marino'">SM</xsl:when>
                <xsl:when test="country='Sao Tome and Principe'">ST</xsl:when>
                <xsl:when test="country='Saudi Arabia'">SA</xsl:when>
                <xsl:when test="country='Senegal'">SN</xsl:when>
                <xsl:when test="country='Serbia'">RS</xsl:when>
                <xsl:when test="country='Seychelles'">SC</xsl:when>
                <xsl:when test="country='Sierra Leone'">SL</xsl:when>
                <xsl:when test="country='Singapore'">SG</xsl:when>
                <xsl:when test="country='Sint Maarten (Dutch part)'">SX</xsl:when>
                <xsl:when test="country='Slovakia'">SK</xsl:when>
                <xsl:when test="country='Slovenia'">SI</xsl:when>
                <xsl:when test="country='Solomon Islands'">SB</xsl:when>
                <xsl:when test="country='Somalia'">SO</xsl:when>
                <xsl:when test="country='South Africa'">ZA</xsl:when>
                <xsl:when test="country='South Georgia and the South Sandwich Islands'">GS</xsl:when>
                <xsl:when test="country='South Sudan'">SS</xsl:when>
                <xsl:when test="country='Spain'">ES</xsl:when>
                <xsl:when test="country='Sri Lanka'">LK</xsl:when>
                <xsl:when test="country='Sudan'">SD</xsl:when>
                <xsl:when test="country='Suriname'">SR</xsl:when>
                <xsl:when test="country='Svalbard and Jan Mayen'">SJ</xsl:when>
                <xsl:when test="country='Swaziland'">SZ</xsl:when>
                <xsl:when test="country='Sweden'">SE</xsl:when>
                <xsl:when test="country='Switzerland'">CH</xsl:when>
                <xsl:when test="country='Syrian Arab Republic'">SY</xsl:when>
                <xsl:when test="country='Taiwan, Province of China'">TW</xsl:when>
                <xsl:when test="country='Tajikistan'">TJ</xsl:when>
                <xsl:when test="country='Tanzania, United Republic of'">TZ</xsl:when>
                <xsl:when test="country='Thailand'">TH</xsl:when>
                <xsl:when test="country='Timor-Leste'">TL</xsl:when>
                <xsl:when test="country='Togo'">TG</xsl:when>
                <xsl:when test="country='Tokelau'">TK</xsl:when>
                <xsl:when test="country='Tonga'">TO</xsl:when>
                <xsl:when test="country='Trinidad and Tobago'">TT</xsl:when>
                <xsl:when test="country='Tunisia'">TN</xsl:when>
                <xsl:when test="country='Turkey'">TR</xsl:when>
                <xsl:when test="country='Turkmenistan'">TM</xsl:when>
                <xsl:when test="country='Turks and Caicos Islands'">TC</xsl:when>
                <xsl:when test="country='Tuvalu'">TV</xsl:when>
                <xsl:when test="country='Uganda'">UG</xsl:when>
                <xsl:when test="country='Ukraine'">UA</xsl:when>
                <xsl:when test="country='United Arab Emirates'">AE</xsl:when>
                <xsl:when test="country='United Kingdom'">GB</xsl:when>
                <xsl:when test="country='United States'">US</xsl:when>
                <xsl:when test="country='United States Minor Outlying Islands'">UM</xsl:when>
                <xsl:when test="country='Uruguay'">UY</xsl:when>
                <xsl:when test="country='Uzbekistan'">UZ</xsl:when>
                <xsl:when test="country='Vanuatu'">VU</xsl:when>
                <xsl:when test="country='Venezuela. Bolivarian Republic of'">VE</xsl:when>
                <xsl:when test="country='Viet Nam'">VN</xsl:when>
                <xsl:when test="country='Virgin Islands, British'">VG</xsl:when>
                <xsl:when test="country='Virgin Islands, U.S.'">VI</xsl:when>
                <xsl:when test="country='Wallis and Futuna'">WF</xsl:when>
                <xsl:when test="country='Western Sahara'">EH</xsl:when>
                <xsl:when test="country='Yemen'">YE</xsl:when>
                <xsl:when test="country='Zambia'">ZM</xsl:when>
                <xsl:when test="country='Zimbabwe'">ZW</xsl:when>
                <xsl:otherwise>CU</xsl:otherwise>
            </xsl:choose>
        </CountryCode>
        <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
    </Country>
</xsl:for-each>

输出如下:

<Country>
            <CountryCode>IR</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>FR</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>HK</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>IQ</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>OM</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>DE</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>AZ</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>HK</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>
        <Country>
            <CountryCode>IQ</CountryCode>
            <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
        </Country>

我遇到的问题是我在<CountryCode>部分有重复项。是否有可能识别这些副本并将其删除,因此它只显示一次?

如果你们中的一些人可以帮助我,我将非常感激!

1 个答案:

答案 0 :(得分:-1)

您可以在xslt 2.0中执行此操作的一种方法是将您的国家/地区名称映射到代码映射到变量,使用它来创建返回给定国家/地区名称的代码的函数,然后在组中使用该函数 - 在xsl:for-each-group中的by子句,按代码分组 - 因为它们是分组键 - 按照定义是唯一的:

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"

                xmlns:set="http://exslt.org/sets"

                xmlns:w="whatever"

                exclude-result-prefixes="xsl xs set w">

    <xsl:output method="xml"
                omit-xml-declaration="yes"
                indent="yes"/>

    <xsl:variable name="countryCodes">
        <country name="Afghanistan" code="AF"/>
        <country name="Åland Islands" code="AX"/>
        <country name="Albania" code="AL"/>
        <country name="Algeria" code="DZ"/>
        <country name="American Samoa" code="AS"/>
        <country name="Andorra" code="AD"/>
        <country name="Angola" code="AO"/>
        <country name="Anguilla" code="AI"/>
        <country name="Antarctica" code="AQ"/>
        <country name="Antigua and Barbuda" code="AG"/>
        <country name="Argentina" code="AR"/>
        <country name="Armenia" code="AM"/>
        <country name="Aruba" code="AW"/>
        <country name="Australia" code="AU"/>
        <country name="Austria" code="AT"/>
        <country name="Azerbaijan" code="AZ"/>
        <country name="Bahamas" code="BS"/>
        <country name="Bahrain" code="BH"/>
        <country name="Bangladesh" code="BD"/>
        <country name="Barbados" code="BB"/>
        <country name="Belarus" code="BY"/>
        <country name="Belgium" code="BE"/>
        <country name="Belize" code="BZ"/>
        <country name="Benin" code="BJ"/>
        <country name="Bermuda" code="BM"/>
        <country name="Bhutan" code="BT"/>
        <country name="Bolivia, Plurinational State of" code="BO"/>
        <country name="Bonaire, Sint Eustatius and Saba" code="BQ"/>
        <country name="Bosnia and Herzegovina" code="BA"/>
        <country name="Botswana" code="BW"/>
        <country name="Bouvet Island" code="BV"/>
        <country name="Brazil" code="BR"/>
        <country name="British Indian Ocean Territory" code="IO"/>
        <country name="Brunei Darussalam" code="BN"/>
        <country name="Bulgaria" code="BG"/>
        <country name="Burkina Faso" code="BF"/>
        <country name="Burundi" code="BI"/>
        <country name="Cambodia" code="KH"/>
        <country name="Cameroon" code="CM"/>
        <country name="Canada" code="CA"/>
        <country name="Cape Verde" code="CV"/>
        <country name="Cayman Islands" code="KY"/>
        <country name="Central African Republic" code="CF"/>
        <country name="Chad" code="TD"/>
        <country name="Chile" code="CL"/>
        <country name="China" code="CN"/>
        <country name="Christmas Island" code="CX"/>
        <country name="Cocos (Keeling) Islands" code="CC"/>
        <country name="Colombia" code="CO"/>
        <country name="Comoros" code="KM"/>
        <country name="Congo" code="CG"/>
        <country name="Congo, the Democratic Republic of the" code="CD"/>
        <country name="Cook Islands" code="CK"/>
        <country name="Costa Rica" code="CR"/>
        <country name="Côte d Ivoire" code="CI"/>
        <country name="Croatia" code="HR"/>
        <country name="Cuba" code="CU"/>
        <country name="Curaçao" code="CW"/>
        <country name="Cyprus" code="CY"/>
        <country name="Czech Republic" code="CZ"/>
        <country name="Denmark" code="DK"/>
        <country name="Djibouti" code="DJ"/>
        <country name="Dominica" code="DM"/>
        <country name="Dominican Republic" code="DO"/>
        <country name="Ecuador" code="EC"/>
        <country name="Egypt" code="EG"/>
        <country name="El Salvador" code="SV"/>
        <country name="Equatorial Guinea" code="GQ"/>
        <country name="Eritrea" code="ER"/>
        <country name="Estonia" code="EE"/>
        <country name="Ethiopia" code="ET"/>
        <country name="Falkland Islands (Malvinas)" code="FK"/>
        <country name="Faroe Islands" code="FO"/>
        <country name="Fiji" code="FJ"/>
        <country name="Finland" code="FI"/>
        <country name="France" code="FR"/>
        <country name="French Guiana" code="GF"/>
        <country name="French Polynesia" code="PF"/>
        <country name="French Southern Territories" code="TF"/>
        <country name="Gabon" code="GA"/>
        <country name="Gambia" code="GM"/>
        <country name="Georgia" code="GE"/>
        <country name="Germany" code="DE"/>
        <country name="Ghana" code="GH"/>
        <country name="Gibraltar" code="GI"/>
        <country name="Greece" code="GR"/>
        <country name="Greenland" code="GL"/>
        <country name="Grenada" code="GD"/>
        <country name="Guadeloupe" code="GP"/>
        <country name="Guam" code="GU"/>
        <country name="Guatemala" code="GT"/>
        <country name="Guernsey" code="GG"/>
        <country name="Guinea" code="GN"/>
        <country name="Guinea-Bissau" code="GW"/>
        <country name="Guyana" code="GY"/>
        <country name="Haiti" code="HT"/>
        <country name="Heard Island and McDonald Islands" code="HM"/>
        <country name="Holy See (Vatican City State)" code="VA"/>
        <country name="Honduras" code="HN"/>
        <country name="Hong Kong" code="HK"/>
        <country name="Hungary" code="HU"/>
        <country name="Iceland" code="IS"/>
        <country name="India" code="IN"/>
        <country name="Indonesia" code="ID"/>
        <country name="Iran, Islamic Republic of" code="IR"/>
        <country name="Iran" code="IR"/>
        <country name="Iraq" code="IQ"/>
        <country name="Ireland" code="IE"/>
        <country name="Isle of Man" code="IM"/>
        <country name="Israel" code="IL"/>
        <country name="Italy" code="IT"/>
        <country name="Jamaica" code="JM"/>
        <country name="Japan" code="JP"/>
        <country name="Jersey" code="JE"/>
        <country name="Jordan" code="JO"/>
        <country name="Kazakhstan" code="KZ"/>
        <country name="Kenya" code="KE"/>
        <country name="Kiribati" code="KI"/>
        <country name="Korea, Democratic Peoples Republic of" code="KP"/>
        <country name="Korea, Republic of" code="KR"/>
        <country name="Kuwait" code="KW"/>
        <country name="Kyrgyzstan" code="KG"/>
        <country name="Lao Peoples Democratic Republic" code="LA"/>
        <country name="Latvia" code="LV"/>
        <country name="Lebanon" code="LB"/>
        <country name="Lesotho" code="LS"/>
        <country name="Liberia" code="LR"/>
        <country name="Libya" code="LY"/>
        <country name="Liechtenstein" code="LI"/>
        <country name="Lithuania" code="LT"/>
        <country name="Luxembourg" code="LU"/>
        <country name="Macao" code="MO"/>
        <country name="Macedonia, the Former Yugoslav Republic of" code="MK"/>
        <country name="Madagascar" code="MG"/>
        <country name="Malawi" code="MW"/>
        <country name="Malaysia" code="MY"/>
        <country name="Maldives" code="MV"/>
        <country name="Mali" code="ML"/>
        <country name="Malta" code="MT"/>
        <country name="Marshall Islands" code="MH"/>
        <country name="Martinique" code="MQ"/>
        <country name="Mauritania" code="MR"/>
        <country name="Mauritius" code="MU"/>
        <country name="Mayotte" code="YT"/>
        <country name="Mexico" code="MX"/>
        <country name="Micronesia, Federated States of" code="FM"/>
        <country name="Moldova, Republic of" code="MD"/>
        <country name="Monaco" code="MC"/>
        <country name="Mongolia" code="MN"/>
        <country name="Montenegro" code="ME"/>
        <country name="Montserrat" code="MS"/>
        <country name="Morocco" code="MA"/>
        <country name="Mozambique" code="MZ"/>
        <country name="Myanmar" code="MM"/>
        <country name="Namibia" code="NA"/>
        <country name="Nauru" code="NR"/>
        <country name="Nepal" code="NP"/>
        <country name="Netherlands" code="NL"/>
        <country name="New Caledonia" code="NC"/>
        <country name="New Zealand" code="NZ"/>
        <country name="Nicaragua" code="NI"/>
        <country name="Niger" code="NE"/>
        <country name="Nigeria" code="NG"/>
        <country name="Niue" code="NU"/>
        <country name="Norfolk Island" code="NF"/>
        <country name="Northern Mariana Islands" code="MP"/>
        <country name="Norway" code="NO"/>
        <country name="Oman" code="OM"/>
        <country name="Pakistan" code="PK"/>
        <country name="Palau" code="PW"/>
        <country name="Palestine, State of" code="PS"/>
        <country name="Palestinian" code="PS"/>
        <country name="Panama" code="PA"/>
        <country name="Papua New Guinea" code="PG"/>
        <country name="Paraguay" code="PY"/>
        <country name="Peru" code="PE"/>
        <country name="Philippines" code="PH"/>
        <country name="Pitcairn" code="PN"/>
        <country name="Poland" code="PL"/>
        <country name="Portugal" code="PT"/>
        <country name="Puerto Rico" code="PR"/>
        <country name="Qatar" code="QA"/>
        <country name="Réunion" code="RE"/>
        <country name="Romania" code="RO"/>
        <country name="Russia" code="RU"/>
        <country name="Rwanda" code="RW"/>
        <country name="Saint Barthélemy" code="BL"/>
        <country name="Saint Helena, Ascension and Tristan da Cunha" code="SH"/>
        <country name="Saint Kitts and Nevis" code="KN"/>
        <country name="Saint Lucia" code="LC"/>
        <country name="Saint Martin (French part)" code="MF"/>
        <country name="Saint Pierre and Miquelon" code="PM"/>
        <country name="Saint Vincent and the Grenadines" code="VC"/>
        <country name="Samoa" code="WS"/>
        <country name="San Marino" code="SM"/>
        <country name="Sao Tome and Principe" code="ST"/>
        <country name="Saudi Arabia" code="SA"/>
        <country name="Senegal" code="SN"/>
        <country name="Serbia" code="RS"/>
        <country name="Seychelles" code="SC"/>
        <country name="Sierra Leone" code="SL"/>
        <country name="Singapore" code="SG"/>
        <country name="Sint Maarten (Dutch part)" code="SX"/>
        <country name="Slovakia" code="SK"/>
        <country name="Slovenia" code="SI"/>
        <country name="Solomon Islands" code="SB"/>
        <country name="Somalia" code="SO"/>
        <country name="South Africa" code="ZA"/>
        <country name="South Georgia and the South Sandwich Islands" code="GS"/>
        <country name="South Sudan" code="SS"/>
        <country name="Spain" code="ES"/>
        <country name="Sri Lanka" code="LK"/>
        <country name="Sudan" code="SD"/>
        <country name="Suriname" code="SR"/>
        <country name="Svalbard and Jan Mayen" code="SJ"/>
        <country name="Swaziland" code="SZ"/>
        <country name="Sweden" code="SE"/>
        <country name="Switzerland" code="CH"/>
        <country name="Syrian Arab Republic" code="SY"/>
        <country name="Taiwan, Province of China" code="TW"/>
        <country name="Tajikistan" code="TJ"/>
        <country name="Tanzania, United Republic of" code="TZ"/>
        <country name="Thailand" code="TH"/>
        <country name="Timor-Leste" code="TL"/>
        <country name="Togo" code="TG"/>
        <country name="Tokelau" code="TK"/>
        <country name="Tonga" code="TO"/>
        <country name="Trinidad and Tobago" code="TT"/>
        <country name="Tunisia" code="TN"/>
        <country name="Turkey" code="TR"/>
        <country name="Turkmenistan" code="TM"/>
        <country name="Turks and Caicos Islands" code="TC"/>
        <country name="Tuvalu" code="TV"/>
        <country name="Uganda" code="UG"/>
        <country name="Ukraine" code="UA"/>
        <country name="United Arab Emirates" code="AE"/>
        <country name="United Kingdom" code="GB"/>
        <country name="United States" code="US"/>
        <country name="United States Minor Outlying Islands" code="UM"/>
        <country name="Uruguay" code="UY"/>
        <country name="Uzbekistan" code="UZ"/>
        <country name="Vanuatu" code="VU"/>
        <country name="Venezuela. Bolivarian Republic of" code="VE"/>
        <country name="Viet Nam" code="VN"/>
        <country name="Virgin Islands, British" code="VG"/>
        <country name="Virgin Islands, U.S." code="VI"/>
        <country name="Wallis and Futuna" code="WF"/>
        <country name="Western Sahara" code="EH"/>
        <country name="Yemen" code="YE"/>
        <country name="Zambia" code="ZM"/>
        <country name="Zimbabwe" code="ZW"/>
    </xsl:variable>

    <xsl:function name="w:country-code">
        <xsl:param name="name"/>
        <xsl:variable name="countryCode" select="$countryCodes/*[@name = $name][1]/@code"/>
        <xsl:value-of select="if ($countryCode) then $countryCode else 'CU'"/>
    </xsl:function>

    <xsl:template match="/">

        <xsl:for-each-group select="addressList/address" group-by="w:country-code(country)">
            <Country>
                <CountryCode>
                    <xsl:value-of select="current-grouping-key()"/>
                </CountryCode>
                <CountryTypeCode>COUNTRY_OF_REGISTRATION</CountryTypeCode>
            </Country>
        </xsl:for-each-group>

    </xsl:template>

</xsl:stylesheet>