Is there an XSLT name-of element ?

Is there an XSLT name-of element ?

Asked on January 2, 2019 in XML.
Add Comment


  • 3 Answer(s)

    It could provide the current element name (tag name),

    <xsl:value-of select ="name(.)"/>
    

    OP-Edit:

    <xsl:value-of select ="local-name()"/>
    
    Answered on January 2, 2019.
    Add Comment

    The difference in the definition of the functions name() and local-name().

    • name(someNode) will return the full name of the node that includes the prefix and colon in case the node is an element or an attribute.
    • local-name(someNode) will returns only the local name of the node which will not include the prefix and colon in case the node is an element or an attribute.

         So, in some situations where a name belongs to two different namespaces, one should use the name() function in order for these names to be still distinguished.

    BTW is possible to specify both functions without any argument:

    • name() is an abbreviation for name(.)
    • local-name() is an abbreviation for local-name(.)

         Remember that not only the attributes and elements have names, these two functions will also be used on PIs and on these they are identical.

    Answered on January 2, 2019.
    Add Comment

    Try the below code: 

    <xsl:for-each select="person">
      <xsl:for-each select="*">
        <xsl:value-of select="local-name()"/> : <xsl:value-of select="."/>
      </xsl:for-each>
    </xsl:for-each>
    
    Answered on January 2, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.