How to open an XInclude target when double-clicking

Submitted by: Eliot Kimber Last Updated: 2006-08-04

The main code that what I've got for supporting open-on-double-click of XInclude-style references in one of our internal-use document types is shown below. The key is creating your link callback. You must also configure the relevant elements as links in the DCF file. In this case I treat both xi:xinclude elements and elements with an attribute named "xinclude" with a value of "xi:include" as XIncludes. The elemIsXinclude function used in the link callback simply checks this condition as there may be other element types that are also links but not XIncludes. (This is also why I can't use Epic 5's built-in support for XInclude. That and the fact that my use of XInclude supports XInclude of elements within documents, which Epic does not as yet support.) Also, there may be a better way to do what the get_real_nearest_element function does, I don't know.

In instance.acl:

doc_add_callback(current_doc, 'link', 'isoreport_hooks::link_callback'); doc_add_callback(current_doc, 'linkuri', 'isoreport_hooks::link_callback');

In isoreport_hooks.acl:

function link_callback(doc, oid, pos, op) { local realoid = utils::get_nearest_real_element(oid); if (op == 2) { if (xinclude::elemIsXinclude(realoid)) { xinclude::open_xinclude_target(realoid); return -1; }    }     return 0; }

In xinclude.acl:

function open_xinclude_target(oid) { oid = utils::get_nearest_real_element(oid); local href = oid_attr(oid, "href"); if (href != "") { local targetFn = get_fn_for_href(href); if (file_size(targetFn) == -1) { response("Error: referenced target '" . href . "' does not exist.\n" . \                     "UBR reference may be out of date or you may not have a\n" . \                      "local copy of the file. Try updating the relevant modules\n" .\                      "from CVS."); } else { execute("edit -newwindow " . targetFn); }    } }; function get_fn_for_href(href, curdoc = current_doc) { if ((substr(href, 1, 1) != "/") && \        (substr(href, 1, 1) != "\\")) { return dirname(doc_path(curdoc)). href; } else { return href; } }

In utils.acl:

function get_nearest_real_element(oid) { local roid = oid while (oid_is_gentext(roid)) { roid = oid_parent(roid); if (roid == oid_null) { return oid_null; }  }   return roid; }
 * 1) Looks up through fake elements (e.g., "_subchars") to find nearest real element.