[2.0] node-name()

Returns an expanded QName for nodes that can have names.


xs:QName? node-name(node()?)


A node.


For nodes that are allowed to have names, returns the node name. For other kinds of nodes (comment nodes, for example), node-name() returns the empty sequence. If the argument to node-name() is the empty sequence, the function returns the empty sequence, as you’d expect.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 2, “Accessors.”


We’ll use this stylesheet to illustrate how the node-name() function works with different kinds of nodes:

<?xml version="1.0"?>
<!-- node-name.xsl -->
<xsl:stylesheet version="2.0"

  <xsl:output method="text"/>

  <xsl:template match="/">

    <xsl:text>&#xA;Here's a test of the node-name() </xsl:text>

  <xsl:template match="*">
    <xsl:text>  Element node: node-name(.) = '</xsl:text>
    <xsl:value-of select="node-name(.)"/>
    <xsl:if test="prefix-from-QName(node-name(.))">
      <xsl:text>'&#xA;    Prefix: '</xsl:text>
      <xsl:value-of select="prefix-from-QName(node-name(.))"/>
    <xsl:text>'&#xA;    Local name: '</xsl:text>
    <xsl:value-of select="local-name-from-QName(node-name(.))"/>
    <xsl:if test="namespace-uri-from-QName(node-name(.))">
      <xsl:text>'&#xA;    Namespace URI: '</xsl:text>
 <xsl:value-of select="namespace-uri-from-QName(node-name(.))"/> ...

Get XSLT, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.