Description
The functx:max-depth function returns the maximum level of elements within a document, as an integer. 1 represents the root, 2 is a child of the root, etc. If $root is a document node, it is counted as a level. Text and other kinds of nodes are not counted as a level.
Arguments and Return TypeName | Type | Description |
$root |
node()? |
the root to start from |
return value |
xs:integer? |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:max-depth" as="xs:integer?"
xmlns:functx="http://www.functx.com">
<xsl:param name="root" as="node()?"/>
<xsl:sequence select="
if ($root/*)
then max($root/*/functx:max-depth(.)) + 1
else 1
"/>
</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:max-depth($in-xml) |
3 |
functx:max-depth($in-xml/author[1]) |
2 |
See AlsoHistory |
Recommended Reading:
|