Two phase processing: Do not output empty tags from phase-1 XSLT 2.0 processing

前端 未结 1 1611
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 19:19

I have some complex XSLT 2.0 transformations. I\'m trying to find out if there is general purpose way to ensure that no empty tags are output. So... conceptually, a final st

1条回答
  •  盖世英雄少女心
    2020-12-01 19:58

    This XSLT 2.0 transformation illustrates how multi-pass (in this case 2-pass) processing can be done:

    
        
        
    
     
         
           
         
     
    
     
       
         
       
    
       
     
    
     
    
     
    
    

    when applied on this XML document:

    
      01
      02
      03
      04
      05
      06
      07
      08
      09
      10
    
    

    It creates a result document in the first pass (which is captured in the $vPass1 variable), in which all elements with contents even integer are stripped off their content and are empty. Then, in the second pass, applied in a specific mode, all empty elements are removed.

    The result of the transformation is:

    
       01
       03
       05
       07
       09
    
    

    Do note the use of modes, and the special modes #all and #current.

    Update: The OP now wants in a comment to delete "recursively" "all nodes that have no non-empty descendant".

    This can be implemented simpler using no explicit recursion. Just change:

     
    

    to:

     
    

    0 讨论(0)
提交回复
热议问题