General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Collapsing tags containging specific nodes

  • russurquhart1

    Collapsing tags containging specific nodes

    Participants 1
    Replies 2
    Last Activity 13 years, 5 months ago

    Me again,

    With the code you gave me yesterday:

    var nodelist = ActiveDocument.getNodesByXpath(“//*[@filter='filter5']”);
    var nodecount = nodelist.length;
    Application.Alert(“Fixing ” + nodecount + ” nodes…”);
    for (i=0; i nodelist.item(0).setAttribute(“filter”, “”);
    }

    Can i collapse the element tag of the specific node at this point, or do i have to somehow convert that to a selection and then call CollapsedContainerTags?

    thanks,

    Russ

    Reply

    Derek Read

    Reply to: Collapsing tags containging specific nodes

    Yes, you will need to convert to a selection and then set CollapsedContainerTags = true

    One way (perhaps the best way) to do this would be to:
    1. Create a Range object at the start of the script: var rng = ActiveDocument.Range;
    2. Inside the for loop move rng to the node in question (before you remove the attribute): rng = nodelist.item(0).SelectContainerContents();
    3. Then (also inside the for loop call): rng.CollapsedContainerTags = true;

    Because this might cause a bunch of flickering as things get redrawn all over the place (this will be more noticeable on slower machines or larger docs) I would suppress any screen formatting updates until everything is done. Something like this:

    [code]ActiveDocument.FormattingUpdating = false;
    var nodelist = ActiveDocument.getNodesByXpath(“//*[@filter='filter5']”);
    var nodecount = nodelist.length;
    var rng = ActiveDocument.Range;
    Application.Alert(“Fixing ” + nodecount + ” nodes…”);
    for (i=0; i rng.SelectNodeContents(nodelist.item(0));
    rng.CollapsedContainerTags = true;
    nodelist.item(0).setAttribute(“filter”, “”);
    }
    ActiveDocument.FormattingUpdating = true;[/code]

    Reply

    russurquhart1

    Reply to: Collapsing tags containging specific nodes

    Thanks for that!

    (As i wanted to just collapse the nodes, and in this case not change their attribiute value, the code as it was only changed the first node. Changing the node selected to i, did the trick!)

    Thanks again for your help!

    Russ

    Reply

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

Lost Your Password?

Products
Downloads
Support