+let choose_selection mmlwidget (element : Gdome.element option) =
+ let rec aux element =
+ if element#hasAttributeNS
+ ~namespaceURI:Misc.helmns
+ ~localName:(Gdome.domString "xref")
+ then
+ mmlwidget#set_selection (Some element)
+ else
+ try
+ match element#get_parentNode with
+ | None -> assert false
+ | Some p -> aux (new Gdome.element_of_node p)
+ with GdomeInit.DOMCastException _ ->
+ debug_print "trying to select above the document root"
+ in
+ match element with
+ | Some x -> aux x
+ | None -> mmlwidget#set_selection None
+