(Q22) Find the maximum depth of the document named "partlist.xml."

NAMESPACE xsd = "http://www.w3.org/2000/10/XMLSchema-datatypes"

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"))
  • This query uses a recursive function definition to compute the depth of a node-set passed to it.
<<<  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    >>>