How can I break a table row in xsl after a specified count?

后端 未结 4 389
南笙
南笙 2021-01-20 12:23

I have the following xsl that sorts my xml alphabetically:


  
 



        
4条回答
  •  终归单人心
    2021-01-20 12:45

    This question must be edited in order for anyone to understand what the problem really is. The comment by Tomalak reveals that the OP "wants lists of items in an alphabetically ordered grid. One list for each letter. Four letters horizontally, as much as it takes vertically"

    The following transformation:

    
    
     
     
    
     
    
     
    
      
    
      
        
    
             
               
             
          
        
    
        
    
      
        
            
            
          

    when applied on this XML document:

    
      
        
        
        
        
        
        
        
        
        
        
        
        
        
      
    
    

    produces the wanted result:

    A
    Agenda
    Accrual
    Ads
    Averages
    B
    Bindings
    Budget
    C
    Cars
    Categories
    Costs
    P
    Policy
    Politics
    R
    Reevaluations
    Report

    Do note three things:

    • We are using the (exslt) ext:node-set() extension function to convert an intermediate result from RTF (Result-Tree Fragment) to a temporary tree.

    • The necessary to make the original XML document the current XML document again, so that the key() function will use the index made for this document and not for the temporary tree.

    • Each start letter that must start a new row of (4) starting letters is processed in a special template, in which the is produced. Then this and the remaining (3) starting letters in the row are processed within the body of the in "copy" mode, just creating a each.

    Here we have covered and demonstrated a few advanced XSLT techniques:

    • Using the mod operator for grouping by quantity.
    • Using the key() function for a different document than the current one.
    • Modes
    • Converting an RTF into a temporary tree

    Enjoy :)

提交回复
热议问题