How to get tag name of root element in an XML document w/ XSLT?

前端 未结 4 1029
遇见更好的自我
遇见更好的自我 2020-12-16 10:27

I\'m interested in assigning the tag name of the root element in an xml document to an xslt variable. For instance, if the document looked like (minus the DTD):

<         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-16 11:12

    I think you want to retrieve the name of the outermost XML element. This can be done like in the following XSL sample:

    
    
    
      
    
      
        
      
    
    

    Please note that there is a slight difference in XPath terminology:

    The top of the tree is a root node (1.0 terminology) or document node (2.0). This is what "/" refers to. It's not an element: it's the parent of the outermost element (and any comments and processing instructions that precede or follow the outermost element). The root node has no name.

    See http://www.dpawson.co.uk/xsl/sect2/root.html#d9799e301

提交回复
热议问题