General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion XFTReplacement for first instance of element

  • [email protected]

    XFTReplacement for first instance of element

    Participants 1
    Replies 2
    Last Activity 8 years, 8 months ago

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

    Reply

    Derek Read

    Reply to: XFTReplacement for first instance of element

    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=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]  
       
         myelement
               Embedded
         Replace
         ByScript
         JScript
          var aipc = Application.ActiveInPlaceControl;
    if(aipc.node.previousSibling.nodeName == aipc.node.nodeName) {
    aipc.ShouldCreate = false;
    };
    else {
    aipc.ShouldCreate = true;
    };
     ]]>

       

     
    [/code]

    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.

    Reply

    Derek Read

    Reply to: XFTReplacement for first instance of element

    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;
    };
    }[/code]

    Reply

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

Lost Your Password?

Products
Downloads
Support