Selecting unique records in XSLT/XPath

后端 未结 2 1793
陌清茗
陌清茗 2021-01-13 06:42

I have to select only unique records from an XML document, in the context of an loop. I am limited by Visual Studio to usi

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 07:04

    I. As a single XPath expression:

    /*/item[normalize-space() and not(. = preceding-sibling::item)]
    

    II. More efficient (XSLT) implementation, using keys:

    
     
     
    
     
    
     
      
     
    
    

    Both I and II, when applied on the provided XML document correctly select/copy the following nodes:

    2010-06-2410:00:0013:00:00
    2010-06-2510:00:0012:00:00
    2010-06-2613:00:0014:00:00
    2010-06-2610:00:0012:00:00
    

    Update: In case has other children, then this transformation:

    
        
    
        
    
     
           
     
    
    

    produces the wanted result.

提交回复
热议问题