The following works with a free-form XML document I used for testing.
It uses the "editfilehook" to catch a document just before it is displayed
for editing and enumerates the style sheet associations in the document,
looking for one that is set for editor display and whose path ends with a
particular string. It then deletes this association (leaving the document
in "modified" state) and selects the default free-form FOSI, instead.
You may want to use doc_set_stylesheet_association to replace the PI with a
different one, though I think you'll still need to do the stylesheet_select
call, as PI processing has already finished, by this point. The
"editfilehook1" function just provides a wrapper around the function that
does the work, passing the result of current_doc to it, to give you a
little flexibility for testing and such.
function fixStylesheetAssociation(doc)
{
local ssTarget = "test1.style";
local ssNew = $aptpath . '\doctypes\freeform\freeform.fos';
local ssCount, ssInfo[], i, ss, len = length(ssTarget) - 1;
ssCount = doc_num_stylesheet_associations(doc);
if (ssCount < 0) { return; }
for (i = 1; i <= ssCount; i++) {
if (!doc_get_stylesheet_association(doc, i, ssInfo)) { return; }
ss = substr(ssInfo["href"], length(ssInfo["href"]) - len);
if (ssInfo["media"] == "editor" && ss == ssTarget) {
doc_delete_stylesheet_association(doc, i);
stylesheet_select(ssNew, 0, doc);
return;
}
}
}
function editfilehook1(code) { fixStylesheetAssociation(current_doc()); }
add_hook("editfilehook", editfilehook1);
-Brandon 🙂