SPFE Documentation | Collections > SPFE Function Reference > path-depth
Function: path-depth
path-depth(path as item()*) as xs:integer
- Description
-
The path-depth calculates the depth of an XPath by counting the number of elements in the path. It uses tokenize to count but throws away the empty string item that would be created by a leading or trailing slash. Thus foo/bar, /foo/bar, and /foo/bar/, are all counted as having a path depth of 2. Will count a concluding attribute on a path as part of the depth. Presumably works for file paths as well, as long as they are in UNIX form, but it won't distinguish path elements from drive letters or the protocol parts of a URI.
- Return value
-
Return type: xs:integer
The number of elements in an XPath expression.
- Source file
-
$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl
Parameters
- path
-
Type: item()*
The path expression.
Definition
<xsl:function name="sf:path-depth" as="xs:integer"> <xsl:param name="path"/> <xsl:value-of select="count(tokenize($path, '/')[. ne ''])"/> </xsl:function>