How to select distinct values from XML document using XPATH?

前端 未结 3 726
广开言路
广开言路 2021-01-01 17:00

How can I select only distinct elements for the XML document using XPATH?I\'ve tried to use the \'distinct-values\' function but it didn\'t work for some reason..

Th

3条回答
  •  情深已故
    2021-01-01 17:32

    In XPath 2.0:

    distinct-values(/*/*/*/name(.))
    

    In XPath 1.0 this cannot be produced with a single XPath expression.

    Using XSLT 1.0:

    
     
    
     
       
         
       
     
    
    

    When this transformation is applied on the provided XML document, the wanted result is produced:

    size price rating year
    

    A more efficient XSLT 1.0 transformation, using keys:

    
     
    
     
    
     
       
         
       
     
    
    

提交回复
热议问题