Logo

XQuery Operators and Functions

Find the maximum depth of the document named “partlist.xml”

	define function depth(element $e) returns xsd:integer
	{ 
	  -- An empty element has depth 1
	  -- Otherwise, add 1 to max depth of children 
	  if empty($e/*) then 1
	  else max(depth($e/*)) + 1 
	}
	depth(document("partlist.xml"))

Ivan Herman, W3C Head of Offices16 July, 200213 (17)