Description
The functx:depth-of-node function returns the level of a node within a document, as an integer. 1 represents the root node, 2 is a child of the root, etc. If $node is a document node, the document node itself counts as the first level.
Arguments and Return TypeName | Type | Description |
$node |
node()? |
the node to check |
return value |
xs:integer |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:depth-of-node" as="xs:integer"
xmlns:functx="http://www.functx.com">
<xsl:param name="node" as="node()?"/>
<xsl:sequence select="
count($node/ancestor-or-self::node())
"/>
</xsl:function>
|
Examples<xsl:variable name="in-xml" as="item()*"> | | <authors>
<author>
<fName>Kate</fName>
<lName>Jones</lName>
</author>
<author>
<fName>John</fName>
<lName>Doe</lName>
</author>
</authors> |
| </xsl:variable> |
XPath Example | Results |
---|
functx:depth-of-node($in-xml) |
1 |
functx:depth-of-node($in-xml/author[1]) |
2 |
functx:depth-of-node(
$in-xml/author[1]/fName/text()) |
4 |
See AlsoHistory |
Recommended Reading:
|