XSLT and XPath function reference in alphabetical order

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

fn:root

Category:

Node names, identifiers and URI information

Origin:

XPath 2.0

Return value:

document node; the document element of the tree in which the node passed on is located or, if no node is passed on, the document element of the tree of the context node.

Call/Arguments:

fn:root($node)

$node:

Optional. A node whose related document element is searched for.

Purpose of use:

The function returns the root node of the tree in which the node passed on is located (this root node is often, but not necessarily always a document node). If the node passed on itself is a document node, it is returned by the function unchanged. If the argument is the empty sequence, fn:root() returns an empty result sequence.

If no argument is passed on to the function, it refers to the context item as default argument and returns the document node of the current tree. However, at the moment of the function call firstly, a context item must exist and secondly, it must be a node. In case of violation, in the first case a runtime error (err:XPDY0002) is reported, in the second case a type error (err:XPTY0004) which can already be noticed during the static evaluation.

Example – function call without argument:

Source document:

<?xml version="1.0" encoding="UTF-8"?>
<example>
<test>This is an example content.</test>
<test>This is a further example content.</test>
</example>

XSLT stylesheet (excerpt):

<xsl:template match="/">
<result>
<xsl:value-of select="fn:root()"/> 
</result>

The context item during the call of the function is the document node of the source document.

Result:

<?xml version="1.0" encoding="UTF-8"?>
<result>
This is an example content. This is a further example content.
</result>

The xsl:value-of instruction outputs the string value of the document node of the source document.

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:root() as node()

fn:root($arg as node()?) as node()?

   

<< back next >>

 

 

 


Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.


Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany