Name

name()

Returns the qualified name of a node. The qualified name includes the appropriate namespace prefix. For information on the namespace URI (not the prefix), XPath provides the namespace-uri() function.

Syntax

[1.0] string name(node-set?)
[2.0] xs:string name(node()?)

Inputs

[1.0] An optional node-set. If the node-set is present, the XSLT 1.0 processor invokes the name() function against the first node in the node-set. If no node-set is given, the name() function applies to the context node.

[2.0] An optional node sequence. In XSLT 2.0, it is an error to call the name() function with a sequence containing more than one node. If the node sequence is not present, the name() function applies to the context node.

Output

The qualified name of the node. If the argument to the name() function is empty (say we use select="item" where there are no <item> elements, for example), name() returns an empty string.

Defined in

[1.0] XPath section 4.1, “Node Set Functions.”

[2.0] XQuery 1.0 and XPath 2.0 Functions and Operators section 14, “Functions and Operators on Nodes.”

Example

Here is the XML document we’ll use to demonstrate the name() function:

<?xml version="1.0"?>
<!-- sonnet.xml --> <sonnet type='Shakespearean'> <auth:author xmlns:auth="http://www.authors.com/"> <last-name>Shakespeare</last-name> <first-name>William</first-name> <nationality>British</nationality> <year-of-birth>1564</year-of-birth> <year-of-death>1616</year-of-death> </auth:author> <!-- Is there an official title for this ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.