如果存在多个标签,如何删除

How to remove Multiple tags if present

我有一个 xml,它可能会或可能不会产生多个系统编号。如果系统号和外部ID相同,应该只保留一个值。

输入:

<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:updatePersonCrossReference_Input xmlns:ns0="http://xmlns.oracle.com/apps/mdm/customer">
   <xsdLocal3:ListOfSwiPersonPublishIO xmlns:xsdLocal3="http://www.siebel.com/xml/SwiPersonPublishIO">
      <xsdLocal3:Contact>
         <xsdLocal3:IntegrationId>0100004568</xsdLocal3:IntegrationId>
         <xsdLocal3:ListOfCIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>GCIS</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>GCIS</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>1016</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>GCIS</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>GCIS</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>1016</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>HOG</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>HOG</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>2002</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>HOG</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>HOG</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>2002</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>OCR</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>OCR</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>3003</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>OCR</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>OCR</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>3003</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>
         </xsdLocal3:ListOfCIFContactReference>
      </xsdLocal3:Contact>
   </xsdLocal3:ListOfSwiPersonPublishIO>
</ns0:updatePersonCrossReference_Input>

输出应该是:

<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:updatePersonCrossReference_Input xmlns:ns0="http://xmlns.oracle.com/apps/mdm/customer">
   <xsdLocal3:ListOfSwiPersonPublishIO xmlns:xsdLocal3="http://www.siebel.com/xml/SwiPersonPublishIO">
      <xsdLocal3:Contact>
         <xsdLocal3:IntegrationId>0100004568</xsdLocal3:IntegrationId>
         <xsdLocal3:ListOfCIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>GCIS</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>GCIS</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>1016</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>HOG</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>HOG</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>2002</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>OCR</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>OCR</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>3003</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
         </xsdLocal3:ListOfCIFContactReference>
      </xsdLocal3:Contact>
   </xsdLocal3:ListOfSwiPersonPublishIO>
</ns0:updatePersonCrossReference_Input>

如果输入是:

<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:updatePersonCrossReference_Input xmlns:ns0="http://xmlns.oracle.com/apps/mdm/customer">
   <xsdLocal3:ListOfSwiPersonPublishIO xmlns:xsdLocal3="http://www.siebel.com/xml/SwiPersonPublishIO">
      <xsdLocal3:Contact>
         <xsdLocal3:IntegrationId>0100004568</xsdLocal3:IntegrationId>
         <xsdLocal3:ListOfCIFContactReference>
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>GCIS</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>GCIS</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>1016</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>HOG</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>HOG</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>2002</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
            <xsdLocal3:CIFContactReference>
               <xsdLocal3:SystemNumber>OCR</xsdLocal3:SystemNumber>
               <xsdLocal3:SystemName>OCR</xsdLocal3:SystemName>
               <xsdLocal3:ExternalId>3003</xsdLocal3:ExternalId>
            </xsdLocal3:CIFContactReference>            
         </xsdLocal3:ListOfCIFContactReference>
      </xsdLocal3:Contact>
   </xsdLocal3:ListOfSwiPersonPublishIO>
</ns0:updatePersonCrossReference_Input>

然后输出应该显示相同。

感谢任何意见。我正在使用 XSL 1.0。

谢谢, M S

Muenchian 分组,即

(只是输入,没有语法检查,但应该这样。)

  1. 为 CIFContactReference 创建复合索引,等等。喜欢

(我曾经添加一个外来字符,比如'_',用于分隔键,当no.和id是可变长度并且合并可能重复时。)

  1. 然后在 xsdLocal3:ListOfCIFContactReference,
  2. 中进行 for-each 清理

检查具有相同键的第一个节点(即key('ref',$keyValue)[1])是否与实际节点具有相同的id(那么这是列表中的第一个).

在大多数情况下,这比 following-sibling::xsdLocal3:CIFContactReference[...]) 检查快得多;但是,如果您的列表仅由 1-2 个元素组成,则后续兄弟可能仍然会更快一些。