Pages: 1
Print
Author Topic: Modify xref target on save?  (Read 2322 times)
jperkins
Member

Posts: 11


« on: December 23, 2008, 09:59:36 AM »

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 ;)

Thanks!
Logged
dcramer
Member

Posts: 120


« Reply #1 on: December 23, 2008, 10:33:37 AM »

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.

David
Logged

David Cramer
Technical Writer
Motive, an Alcatel-Lucent Company
jperkins
Member

Posts: 11


« Reply #2 on: December 23, 2008, 11:35:29 AM »

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:

 <MACRO name="On_Application_Before_Document_Validate" lang="JScript" hide="false">
    <![CDATA[

  var xrefs = ActiveDocument.getNodesByXPath("//xref/@href");
  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);
    }
  }
   
  ]]></MACRO>
Logged
Pages: 1
Print
Jump to:  

email us