XPath/XQuery has-children function


Returns true if the supplied node has one or more child nodes (of any kind).


) as xs:boolean
$node as node()?
) as xs:boolean


The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.
The one-argument form of this function is deterministic, context-independent, and focus-independent.


If the argument is omitted, it defaults to the context item (.). The behavior of the function if the argument is omitted is exactly the same as if the context item had been passed as the argument.

Provided that the supplied argument $node matches the expected type node()?, the result of the function call fn:has-children($node) is defined to be the same as the result of the expression fn:exists($node/child::node()).

Error Conditions

The following errors may be raised when $node is omitted:

If the context item is absent, dynamic error

If the context item is not a node, type error .


If $node is an empty sequence the result is false.

The motivation for this function is to support streamed evaluation. According to the streaming rules in , the following construct is not streamable:

<xsl:if test="exists(row)"> <ul> <xsl:for-each select="row"> <li><xsl:value-of select="."/></li> </xsl:for-each> </ul> </xsl:if>

This is because it makes two downward selections to read the child row elements. The use of fn:has-children in the xsl:if conditional is intended to circumvent this restriction.

Although the function was introduced to support streaming use cases, it has general utility as a convenience function.