(Q23) In the document "company.xml", find all the elements that are reachable from the employee with serial number 12345 by child or reference connections.

FUNCTION connected(ELEMENT $e) RETURNS LIST(ELEMENT)
{ 
    $e/* UNION $e/@*->* 
}

FUNCTION reachable(ELEMENT $e) RETURNS LIST(ELEMENT)
{ 
    $e UNION reachable(connected($e)) 
}

reachable(document("company.xml")/emp[serial="12345"])
  • This query defines another recursive function.
  • The UNION operator acts the same as XPath's | operator.
<<<  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    >>>