convert xml to jsonx using xslt

后端 未结 1 674
长发绾君心
长发绾君心 2020-12-20 04:11

Can anyone help me out in getting the below with an array..I have to generate the generalised xsl.. Input XML:


    
        

        
1条回答
  •  执念已碎
    2020-12-20 04:37

    More generalized solution. Requires XSLT 2.0

    
        
    
        
            
                    
            
        
    
        
            
            
    
            
                
                    
                
                
                    
                        
                            
    
                            
                                
                            
                        
                    
                    
                        
                    
                
            
        
    
        
            
                
                    
                
                
            
         
    
    

    Applied to the provided sample XML, produces following output:

    
    
        
            
                
                    
                        john
                        
                    
                    
                        john
                        
                    
                
            
        
    
    

    The above solution was tested on this site: http://xslttest.appspot.com/

    EDIT:

    every $x in */name() satisfies $x=$firstNodeName is XPATH 2.0 construction that checks if all the elements in */name() sequence are equal to $firstNodeName. So this whole condition actually means checking if a node has more than one child with the same name - this is a condition for checking if we're dealing with json:array case.

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