DITA and XMetaL Discussion

XMetaL Community Forum DITA and XMetaL Discussion Modify xref target on save?

  • jperkins

    Modify xref target on save?

    Participants 1
    Replies 2
    Last Activity 14 years, 1 month ago

    We have some authors developing content offline, which is then imported into Documentum when complete. If the content contains an xref to something else in the same document, it will break on import. If the document is named MyDocument.xml, XMetaL will write the links like href=”MyDocument.xml#my_element_id”. When the document gets imported, Documentum assigns it a random, temporary filename. At that point MyDocument.xml can no longer be resolved and the import fails.

    We need to get these xrefs formatted like href=”#my_element_id” (no filename) instead.

    This doesn't seem like a bug, necessarily, so I haven't sent it to support, but I thought I would mention it. And if you happen to know how to fix it and can save me a couple of hours digging through the documentation, that would be great, too 😉




    Reply to: Modify xref target on save?

    On_Before_Set_Attribute_From_AI is an event macro that fires when you set an attribute value from the attribute inspector, so you could add some code to On_Before_Set_Attribute_From_AI so that if the element is an xref and the attribute is href and the substring before # is the same as the document name, it sets the attribute value to the #my_element_id part.




    Reply to: Modify xref target on save?

    Thanks for assist, David. Since there are a couple of ways a user can insert an xref, I decided to check them all at validation time instead, and modify the the href if needed. Here is what I came up with, which seems to work on all my tests so far:

          for (var i = 0; i < xrefs.length; ++i) {
        var href  = xrefs.item(i).nodeValue;
        var split = href.indexOf(“#”)
        var fname = href.substr(0, split);
        if (fname == ActiveDocument.name) {
          xrefs.item(i).nodeValue = href.substr(split);


  • You must be logged in to reply to this topic.

Lost Your Password?