Pages: 1
Print
Author Topic: XFTReplacement for first instance of element  (Read 2017 times)
jan.kostelansky@aerosofts
Member

Posts: 5


« on: January 29, 2014, 03:07:18 PM »

Hi all,

is it possible to define different XFTReplacement for
first occurrence of element
subsequence occurrence of element.

I need to add additional GUI components to form bound to first occurrence of element

I have this DTD
ELEMENT aa (bb)+

but I cannot change it to because it is customer DTD.
ELEMENT aa (bbs)
ELEMENT bbs (bb)+
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: January 29, 2014, 04:26:00 PM »

This will require some scripting to be added for the element you wish to display using XFT (which is configured in the CTM file). This is described in the XMetaL Developer help in the section that discusses CTM file settings...

Quote from: Customization Guide "Display As" topic
If you select Dynamic Script, you must create a script for XMetaL to call before it displays the form. Use this script to create business rules that determine whether or not to display the form at run-time.

It goes on to provide an example, however, I think this is probably closer to what you are asking for:
Code:
var aipc = Application.ActiveInPlaceControl;
if(aipc.node.previousSibling.nodeName == aipc.node.nodeName) {
aipc.ShouldCreate = false;
};
else {
aipc.ShouldCreate = true;
};

After you have built the project with XMetaL Developer (after hooking up your element using the XFT Form Wizard including setting up the "Dynamic Script" option) you will end up with something like the following in the CTM file.

Code:
 <XFTReplacements>
    <XFTReplacement>
      <SelectorName ns="">myelement</SelectorName>
      <FormFileName><![CDATA[form1.xft]]></FormFileName>
      <RunMode>Embedded</RunMode>
      <DisplayStyle>Replace</DisplayStyle>
      <OverrideRule>ByScript</OverrideRule>
      <Lang>JScript</Lang>
      <OverrideScript><![CDATA[
var aipc = Application.ActiveInPlaceControl;
if(aipc.node.previousSibling.nodeName == aipc.node.nodeName) {
aipc.ShouldCreate = false;
};
else {
aipc.ShouldCreate = true;
};
 ]]></OverrideScript>
    </XFTReplacement>
  </XFTReplacements>

Of course "myelement" would be the element you are displaying the XFT for (not sure in your case if that is "aa", "bb" or "bbs").

The logic here might not be exactly what you need. It checks to see if the element in question has a sibling element of the same name immediately preceding it. If it does then the form is not displayed. If it doesn't then the form is displayed.

So, it does what your post's title asks for. However, I'm not sure that's exactly what you need since your description throws me off a little bit. Hopefully you can work out your own logic based on this example.

Note that the ShouldCreate property is similar to that used when displaying ActiveX controls in place of elements.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #2 on: January 29, 2014, 05:02:47 PM »

I did not take into account the fact that a particular node might not have a previousSibling. You could wrap everything in a try...catch or code specifically for that case:

Code:
var aipc = Application.ActiveInPlaceControl;
if(aipc.node.previousSibling) {
if(aipc.node.previousSibling.nodeName == aipc.node.nodeName) {
aipc.ShouldCreate = false;
};
else {
aipc.ShouldCreate = true;
};
}
Logged
Pages: 1
Print
Jump to: