General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › XFTReplacement for first instance of element
-
[email protected] January 29, 2014 at 9:07 pm
XFTReplacement for first instance of element
January 29, 2014 at 9:07 pmParticipants 1Replies 2Last Activity 9 years agoHi 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)+Derek Read January 29, 2014 at 10:26 pm
Reply to: XFTReplacement for first instance of element
January 29, 2014 at 10:26 pmThis 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=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;
};[/code]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]
[/code]
myelement
Embedded
Replace
ByScript
JScript
var aipc = Application.ActiveInPlaceControl;
if(aipc.node.previousSibling.nodeName == aipc.node.nodeName) {
aipc.ShouldCreate = false;
};
else {
aipc.ShouldCreate = true;
};
]]>
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.
Derek Read January 29, 2014 at 11:02 pm
Reply to: XFTReplacement for first instance of element
January 29, 2014 at 11:02 pmI 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;
};
}[/code] -
AuthorPosts
- You must be logged in to reply to this topic.