Name

local-name()

Returns the local part of the first node in the argument node-set.

Syntax

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

Inputs

A node-set. If the node-set is empty, the function returns an empty string. If the node-set is omitted, the function uses a node-set with the context node as its only member.

Output

A string corresponding to the local name of the first element in the argument node-set. If the node-set is empty, the local-name() function returns an empty string.

[2.0] In XSLT 2.0, it is a fatal error if the argument contains more than one node.

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

We’ll use our Shakespearean sonnet to test the local-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 sonnet? They're sometimes named after the first line. --> <title>Sonnet 130</title> <lines> <line>My mistress' eyes are nothing like the sun,</line> <line>Coral is far more red than her lips red.</line> <line>If snow be white, why then her breasts are dun,</line> <line>If hairs be wires, black ...

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.