首页 > 解决方案 > XSLT:如何删除具有相同属性值的重复元素,并且元素具有相同的名称和值

问题描述

我们在这个输入 XML 中得到了重复的标签。我们想使用 XSLT 模板指令删除这个重复。但我是 XSLT 的新手,请帮助我。

输入 XML:

    <?xml version="1.0" encoding="UTF-8"?>
<Document>
   <TRU_SALESFORCECATALOGIMPORTENTITY>
      <ITEMID>239917</ITEMID>
      <BRAND/>
      <custom-attributes attribute-id="Manufacturer Min Age">No</custom-attributes>
      <custom-attributes attribute-id="Manufacturer Min Age">No</custom-attributes>
      <custom-attributes attribute-id="Age Range">3 Years</custom-attributes>
      <DESCRIPTION>Hasbro Gaming - Jenga - styles may vary</DESCRIPTION>
      <DESCRIPTION>tieng fr CA - Hasbro Gaming - Jenga - styles may vary</DESCRIPTION>
      <DESCRIPTION>tieng fr CA - Hasbro Gaming - Jenga - styles may vary</DESCRIPTION>
   </TRU_SALESFORCECATALOGIMPORTENTITY>
</Document>

在那个带有标签的 XML 中,如果具有相同的属性 ID 值,我想删除重复项。使用标签说明,如果具有相同的值,我想删除重复项:

预期的xml:

    <?xml version="1.0" encoding="UTF-8"?>
<Document>
   <TRU_SALESFORCECATALOGIMPORTENTITY>
      <ITEMID>239917</ITEMID>
      <BRAND/>
      <custom-attributes attribute-id="Manufacturer Min Age">No</custom-attributes>
      <custom-attributes attribute-id="Age Range">3 Years</custom-attributes>
      <DESCRIPTION>Hasbro Gaming - Jenga - styles may vary</DESCRIPTION>
      <DESCRIPTION>tieng fr CA - Hasbro Gaming - Jenga - styles may vary</DESCRIPTION>
   </TRU_SALESFORCECATALOGIMPORTENTITY>
</Document>

任何帮助将不胜感激!谢谢你们!

标签: xmlxsltxslt-2.0xslt-3.0

解决方案


推荐阅读