XSLT combine multiple nodes into single node

前端 未结 3 1646
無奈伤痛
無奈伤痛 2021-01-06 09:43

 
  Sydney Office
  SYDNEY
  

        
3条回答
  •  甜味超标
    2021-01-06 10:18

    This transformation:

    
     
     
    
     
         
           
         
     
    
     
      
        
          
        
        
          
        
          
      
     
    
     
       
      
    
    
     
    
    

    when applied on the provided source XML document:

    
     
      Sydney Office
      SYDNEY
      Peak Night
      PEANIG
      30849.3
      9
      16.35
      19
     
    
    

    produces the wanted, correct result:

    
       
          Sydney Office
          SYDNEY
          Peak Night
          PEANIG
          
             20050703
             30849.3
             9
          
          
             20050710
             16.35
             19
          
       
    
    

    when applied on the second provided XML document, requested in an Update by the OP:

    
     
      Sydney Office
      SYDNEY
      Peak Night
      PEANIG
      30849.3
      16.35
      19
     
    
    

    again the wanted, correct result (No element is generated if the immediate sibling isn't a W_nnnnnnnn_Spots) is produced:

    
       
          Sydney Office
          SYDNEY
          Peak Night
          PEANIG
          
             20050703
             30849.3
          
          
             20050710
             16.35
             19
          
       
    
    

    Do note:

    1. The use of the identity rule to copy any node "as-is".

    2. The overriding of the identity template only for W_nnnnnnnn_Dlr elements.

    3. The overriding of the identity template with an empty template matching W_nnnnnnnn_Spots elements.

    4. The use of the standard XPath functions: name(), starts-with() and substring-after()

    5. The function ends-with() is only available in XPath 2.0 (XSLT 2.0) and isn't used in this XSLT 1.0 solution.

提交回复
热议问题