MENU
Node Functions
Node functions return information about nodes in the XDM tree — their names, namespace, base URI, string value, structural path, and other properties. The examples below evaluate against this sample document, an extended version of the <menu> example used in Path Expressions, here with an added xml:lang attribute, an ns namespace prefix, and an xml:id on the first <dish>:|
<?xml version="1.0"?> <menu restaurant="Golden Outlet" xmlns:ns="http://example.com" xml:lang="en"> <dish xml:id="1">Satay <i>Cooked</i></dish> <drink id="2">Cola</drink> <dish id="3">Curry Chicken</dish> <dish id="4" xmlns="http://example.com">Sweet and Sour Pork</dish> </menu> |
Each of the following returns the string dish:
| name(menu/ns:dish) |
| menu/dish[1]/name() |
| node-name(menu/ns:dish) |
| local-name(menu/ns:dish) |
| id("1")/name() |
| element-with-id("1")/name() |
| idref("1")/name() |
namespace-uri(menu/ns:dish) returns http://example.com.
Each of the following returns the base URI in effect for the evaluation context (e.g. /home/project-web/videlibri/cgi-bin/ for the online evaluator referenced in XPath):
| base-uri(menu/ns:dish) |
| base-uri() |
| static-base-uri() |
Each of the following returns an empty sequence, since the document was not loaded with doc() and therefore has no document URI:
| document-uri() |
| document-uri(menu) |
Each of the following returns the same string — the concatenated string value of every descendant text node of the document, including the whitespace between elements: Satay Cooked Cola Curry Chicken Sweet and Sour Pork
| string() |
| string(menu) |
| data(menu) |
Each of the following returns /, the structural path of the current node from the document root:
| path() |
| path(.) |
innermost(menu) returns the nodes in a node sequence that have no descendant node also present in that sequence — for the sample document: <i>Cooked</i>, <drink id="2">Cola</drink>, <dish id="3">Curry Chicken</dish>, and <dish id="4" xmlns="http://example.com">Sweet and Sour Pork</dish>.
outermost(menu/dish/i) returns the nodes in a node sequence that are not descendants of any other node in that sequence:
|
<?xml version="1.0"?> <menu restaurant="Golden Outlet" xmlns:ns="http://example.com"> <dish id="1">Satay <i>Cooked</i></dish> <drink id="2">Cola</drink> <dish id="3">Curry Chicken</dish> <dish id="4" xmlns="http://example.com">Sweet and Sour Pork</dish> </menu> |
nilled(menu) returns false, since the element has content and is not marked xsi:nil="true".
Each of the following returns true:
| has-children() |
| has-children(menu) |
| lang("en") |
| lang("en",menu/dish) |
generate-id() returns an implementation-dependent unique identifier string for the current node; the exact value is not standardized and differs between XPath processors.
ch03-node-functions-menu.xml:
<?xml version="1.0"?>
<menu restaurant="Golden Outlet" xmlns:ns="http://example.com" xml:lang="en">
<dish xml:id="1">Satay <i>Cooked</i></dish>
<drink id="2">Cola</drink>
<dish id="3">Curry Chicken</dish>
<dish id="4" xmlns="http://example.com">Sweet and Sour Pork</dish>
</menu>ch03-node-functions.xpath.txt:
namespace-uri(menu/ns:dish)http://example.com