fn:local-name function
The fn:local-name function returns the local name property of a node.
Syntax
- node
- The node for which the local name is to be retrieved. If node is not specified, fn:local-name is evaluated for the current context node.
Returned value
The returned value is an
xs:string value. The value depends on whether node is
specified, and the value of node:
- If node is not specified, the local name of the context node is returned.
- If node meets any of the following conditions,
a string of length 0 is returned:
- node is the empty sequence.
- node is a document node, a comment, or a text node. These nodes have no name.
- In the following cases, an error is returned:
- The context node is undefined.
- The context item is not a node.
- node is a sequence of more than one node.
- Otherwise, an xs:string value is returned that contains the local name part of the expanded name for node.
Examples
The following example returns the
local name for node b.
SELECT XMLQUERY (
'declare default element namespace "http://posample.org";
fn:local-name($d/x/b)'
PASSING XMLPARSE(DOCUMENT
'<x xmlns="http://posample.org"><b><c></c></b></x>')
AS "d")
FROM SYSIBM.SYSDUMMY1
The returned value is "b".
The following example demonstrates that fn:localname() with no argument returns the context node.
In the sample CUSTOMER table, the customer document for customer 1001 looks like this:
<customerinfo xmlns="http:⁄⁄posample.org" Cid="1001">
<name>Kathy Smith<⁄name>
<addr country="Canada">
<street>25 EastCreek<⁄street>
<city>Markham<⁄city>
<prov-state>Ontario<⁄prov-state>
<pcode-zip>N9C 3T6<⁄pcode-zip>
<⁄addr>
<phone type="work">905-555-7258<⁄phone>
<⁄customerinfo>
The following example returns the local name for the context node.
SELECT
XMLSERIALIZE(
XMLQUERY('declare default element namespace "http://posample.org";
$X/customerinfo/phone/fn:local-name()'
PASSING INFO AS "X")
AS CLOB(1K))
FROM CUSTOMER WHERE CID=1001
The returned value is "phone".