xsl: transforming a list into a 2-D table

前端 未结 4 1180
星月不相逢
星月不相逢 2021-01-12 16:32

Let\'s say I have this XML node:


    ...
    ...
    ...
    

        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 17:13

    That's my working solution.

    As you didn't provide a desired output, this particular one may be uncomplete for your needs.

    
        
    
        
            
                    
                

    Test input:

    
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
    
    

    Output:

    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    17 18 19 20
    21 22 23 24
    25 26 27

    Do note: you can pass columns number dynamically.

    Additional requirements and edit.

    
        
    
        
            
            
            
            
        
    
        
            
                    
                

    It can be applied to the previous sample or to this concise XML:

    
        1
    
    

    Result will be:

    1

    Do note:

    1. Hardcoded data to add elements, when there are less item elements than number of columns is.
    2. Extra hardcoded elements, if number of columns will ever change.

    If there won't ever be less elements than number of columns, you can just apply to the item elements with the same predicate and a different mode.

    And last edit. With a counted loop.

    
        
    
        
            
                    
                

提交回复
热议问题