extract_selected_elements function

Extract selected elements from a nested database