How do you output the current element path in XSLT?

前端 未结 5 837
名媛妹妹
名媛妹妹 2020-11-30 02:18

In XSLT, is there a way to determine where you are in an XML document when processing an element?

Example: Given the following XML Doc Fragment...

&l         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 02:45

    Don't think this is built into XPath, you probably need a recursive template, like the one here, which I've based this example on. It will walk every element in an XML document and output the path to that element in a style similar to the one you've described.

    
    
    
        
            
                
            
        
    
        
            
            
                
            
            
            
        
    
        
            /
            
            [
            
            ]
        
    
    
    

    There are a few complications; consider this tree:

    
      
      
    
    

    How do you tell the difference between the two child nodes? So you need some index into your item-sequence, child1 and child[2], for example.

提交回复
热议问题