XSLT + Replacing double quotes with escape sequence

前端 未结 1 1519
梦如初夏
梦如初夏 2020-12-17 15:36

I have the following xslt to transform data into a JQuery-accepted format. However, because JSON doesn\'t accept double quotes in the data string, I need to replace \" with

1条回答
  •  死守一世寂寞
    2020-12-17 16:35

    Add this template to your code:

        
          
    
          
           
    
           
            \"
    
            
              
            
           
          
        
    

    Then change:

    
    

    to:

    
    

    Your complete transformation now becomes:

    
            
            ],
            ]
            [
            { 
            "aaData": [
            ] }
            ,
            "
            yyyy-MM-dd HH:mm:ss
    
    
            
    
                
    
                    
                    
                    
                        
                        
                            
    
                                
    
                                
                            
    
                        
                        
                        
                            
                                
                                    
                                
                                
                                    
                                
                                
                                    
                                        
                                    
                                    
                                        
                                        
                                            
                                                
                                                    
                                                        
                                                    
                                                    
                                                                                                
                                                
                                            
                                            
                                            
                                                
                                                    Y
                                                
                                                
                                                    N
                                                
                                                
                                                  
                                                    
                                                
                                                
                                            
                                        
                                        
                                    
                                
                                
                                    
                                
                            
                                    
                                    
                                
                                    
                                    
                                
    
                        
                        
                    
                
            
    
            
              
    
              
               
    
               
                \"
    
                
                  
                
               
              
            
    
    
    

    when this transformation is applied on the provided XML document:

    
        
            
                
                
                
            
            
                test_data
                test_quo"te
                test_data
            
        
    
    

    the wanted, correct result is produced:

    { "aaData": [["test_data","test_quo\"te","test_data"]] }
    

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