XSLT grouping and summing

前端 未结 1 1865
臣服心动
臣服心动 2021-01-28 20:28

I am new to XSLT and need to sum the total price (Quantity * UnitPrice) of items based on ID from each orders, and print it at the end of each Item\'s group using XSLT 1.0. Here

1条回答
  •  青春惊慌失措
    2021-01-28 20:57

    There are two problems here: (1) group the items by order and by item ID, and (2) calculate the subtotal for each such group.

    The first problem is relatively easy and can be solved using the Muenchian grouping method. The second problem is more difficult, since XSLT 1.0 does not allow summing the result of a calculation.

    The following stylesheet starts by pre-calculating the extended price of each item and storing the results in a variable. Then it operates on the variable, grouping the items and subtotaling each group.

    XSLT 1.0

    
    
    
    
    
    
        
        
            
                
                    
                    
                        
                            
                        
                    
                
            
        
        
        
            
                
                    
                    
                    
                        
                        
                            
                                
                                
                                
                                    
                                        
                                    
                                
                            
                        
                    
                
             
        
    
    
    
    

    Demo: http://xsltransform.net/jz1PuPz

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