需要使用XSLT 1.0从XML输出中基于2个条件删除重复元素

时间:2018-10-29 19:45:49

标签: xslt-1.0 muenchian-grouping

我在这里已经查看了几个答案,我无法将头缠在键上并删除重复的元素。在我的用例中,我有一个随机排列的附件列表。对于我的输出,如果文件名和文件大小都不相同,则仅需要输出附件

这是我的输入内容:

 <Attachments NR="1">
    <objID>351890194</objID>
    <ID>351890194</ID>    
    <ShortName />
    <Name />
    <SeqNr>1</SeqNr>
    <AttachmentType />
    <bpo_objid>351802594</bpo_objid>
    <cal_id>351890107</cal_id> 
    <cal_objid>351890196</cal_objid>
    <Description />
    <edi_objid>351803168</edi_objid>
    <EditTimeUTC>2018-10-11 12:32:01.0</EditTimeUTC>
    <ema_objid>351890195</ema_objid>
    <FileName>autoframeworkIncident.txt</FileName>
    <FilePath>/mnt/nfs/attachmentstore/2018/10/11/351890194/</FilePath>
    <FileSizeKB>200</FileSizeKB>
    <IsPartOfDashboard>N</IsPartOfDashboard>
    <rgr_objid />
    <sol_objid />
</Attachments>
<Attachments NR="2">
    <objID>351890176</objID>
    <ID>351890176</ID>
    <ShortName />
    <Name />
    <SeqNr>1</SeqNr>
    <AttachmentType />
    <bpo_objid>351802594</bpo_objid>
    <cal_id>351890107</cal_id>
    <cal_objid>351890178</cal_objid>
    <Description />
    <edi_objid>351803168</edi_objid>
    <EditTimeUTC>2018-10-11 12:30:17.0</EditTimeUTC>
    <ema_objid>351890177</ema_objid>
    <FileName>autoframeworkIncident.txt</FileName>
    <FilePath>/mnt/nfs/attachmentstore/2018/10/11/351890176/</FilePath>
    <FileSizeKB>0</FileSizeKB>
    <IsPartOfDashboard>N</IsPartOfDashboard>
    <rgr_objid />
    <sol_objid />
</Attachments>
<Attachments NR="3">
    <objID>351891151</objID>
    <ID>351891151</ID>
    <ShortName />
    <Name />
    <SeqNr>10</SeqNr>
    <AttachmentType />
    <bpo_objid>351781152</bpo_objid>
    <cal_id>351890107</cal_id>
    <cal_objid>351891153</cal_objid>
    <Description />
    <edi_objid>1000005000</edi_objid>
    <EditTimeUTC>2018-10-11 20:28:20.0</EditTimeUTC> 
    <ema_objid>351891152</ema_objid> 
    <FileName>Test Attachment 1.txt</FileName>
    <FilePath>/mnt/nfs/attachmentstore/2018/10/11/351891151/</FilePath>
    <FileSizeKB>0</FileSizeKB>
    <IsPartOfDashboard>N</IsPartOfDashboard>
    <rgr_objid />
    <sol_objid />
</Attachments>
<Attachments NR="4">
    <objID>351890230</objID>
    <ID>351890230</ID>
    <ShortName />
    <Name /> 
    <SeqNr>10</SeqNr> 
    <AttachmentType /> 
    <bpo_objid>351781152</bpo_objid>
    <cal_id>351890107</cal_id>   
    <cal_objid>351890232</cal_objid>
    <Description />   
    <edi_objid>1000005000</edi_objid>
    <EditTimeUTC>2018-10-11 12:35:20.0</EditTimeUTC> 
    <ema_objid>351890231</ema_objid>
    <FileName>autoframeworkIncident.txt</FileName>
    <FilePath>/mnt/nfs/attachmentstore/2018/10/11/351890230/</FilePath>  
    <FileSizeKB>0</FileSizeKB> 
    <IsPartOfDashboard>N</IsPartOfDashboard>   
    <rgr_objid /> 
    <sol_objid />
</Attachments>
<Attachments NR="5">
    <objID>351890199</objID>
    <ID>351890199</ID>
    <ShortName /> 
    <Name />  
    <SeqNr>10</SeqNr> 
    <AttachmentType />  
    <bpo_objid>351781152</bpo_objid> 
    <cal_id>351890107</cal_id>  
    <cal_objid>351890201</cal_objid>    
    <Description /> 
    <edi_objid>1000005000</edi_objid>
    <EditTimeUTC>2018-10-11 12:33:20.0</EditTimeUTC> 
    <ema_objid>351890200</ema_objid>
    <FileName>autoframeworkIncident.txt</FileName>
    <FilePath>/mnt/nfs/attachmentstore/2018/10/11/351890199/</FilePath>
    <FileSizeKB>0</FileSizeKB>
    <IsPartOfDashboard>N</IsPartOfDashboard>
    <rgr_objid />
    <sol_objid />
</Attachments>

在我的输出中,我需要删除具有相同FileName和FileSizeKB的元素。我知道使用键和分组可能是实现此目的的方法,但到目前为止我还没有运气。

到目前为止,这是我的XSLT模板中的内容:

<xsl:key name="kAttachmentByFileName" match="//Attachments" use="FileName"/>

 <xsl:for-each select="//Attachments">
    <xsl:copy-of select="//Attachments[generate-id()=generate-id(key('kAttachmentByFileName', .)[1])]"/>
   <vbo:Attachments>
       <vbo:Attachment>
          <cmn:Name xmlns:cmn="xxxxxx">
              <xsl:value-of select="FileName" />
          </cmn:Name>
          <cmn:BinaryObject xmlns:cmn="xxxx">
              <xsl:value-of select="DataBase64" />
          </cmn:BinaryObject>
       </vbo:Attachment>
    </vbo:Attachments>
</xsl:for-each>

0 个答案:

没有答案