How to fold by a tag a group of selected (neighbor) tags with XSLT1?

后端 未结 1 667
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 10:33

I have a set of sequential nodes that must be enclosed into a new element. Example:

  
    cccc
    aaaa<         


        
1条回答
  •  情话喂你
    2021-01-15 11:35

    In XSLT 1.0 the standard technique to handle this sort of thing is called Muenchian grouping, and involves the use of a key that defines how the nodes should be grouped and a trick using generate-id to extract just the first node in each group as a proxy for the group as a whole.

    
      
      
      
    
      
        
      
    
      
      
        
          
            
          
        
      
    
      
      
    
    

    This achieves the grouping you're after, but just like your non-general solution it doesn't preserve the indentation and the whitespace text nodes between the a and b elements, i.e. it will give you

    
      cccc
      
        aaaa
        1111
      
      
        bbbb
        2222
      
    
    

    Note that if you were able to use XSLT 2.0 then the whole thing becomes one for-each-group:

    
      
        
          
          
            
          
          
          
            
          
        
      
    
    

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