How to edit specific xml using xpath

后端 未结 1 929
北恋
北恋 2021-01-24 19:31

I have got below xml which is genrated using xslt function json-to-xml(). I need to update this xml as shown in Result xml using given xpaths. I need the solution in java or xs

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-24 20:21

    One approach given XSLT 3 might be to transform those paths you have into XSLT 3 match templates and then create a stylesheet you can execute with the transform function (https://www.w3.org/TR/xpath-functions/#func-transform):

    
    
    
        
    
        
    
        /Response/Payload/root/cars[2]/strength=999
            /Response/Payload/root/bikes[1]/model=2019
            /Response/Headers/server=WebSphere
            /Response/Headers/Content-Type=text
            /Response/Payload/root/cars[2]/Capacity=555
            /Response/Payload/root/cars[1]/model=mmm1
            /Response/Payload/root/bikes[1]/company=xyz
            /Response/Payload/root/cars[1]/company=ccc1
            /Response/Headers/Status-Code=400
    
        
    
        
            
                
    
                
                    
                    
                        
                            
                        
                        
                            
                            
                                           
                    
                
    
            
        
    
        
            /
            
        
    
        
            /
            
        
    
        
            /
            
        
    
        
            
        
    
     
    

    At https://xsltfiddle.liberty-development.net/jyyiVhv/1 I get the wanted result

    
    
        
            
                WebSphere
                400
                text
            
            
                
                    
                        
                            ccc1
                            mmm1
                        
                        
                            999
                            555
                        
                    
                    
                        
                            xyz
                            2019
                        
                    
                
            
        
    
    

    that way although I had to adapt the paths including bikes to bikes[1].

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