General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › How to loop through current selection
-
NandoC August 28, 2014 at 2:01 pm
How to loop through current selection
August 28, 2014 at 2:01 pmParticipants 1Replies 2Last Activity 8 years, 5 months agoHi I just started doing some work with Xmetal 7.0 and I am wondering how i can loop through the current selection and insert an element to each of the nodes that have been selected.
example:
ford toyota has been highlightedAnd let's say we want to underline what was selected to
ford toyota Thanks
Derek Read August 28, 2014 at 5:32 pm
Reply to: How to loop through current selection
August 28, 2014 at 5:32 pmHere's one possibility among many.
//XMetaL Script Language JScript:
var rng = ActiveDocument.Range;
var targetElem = “car”;
var insertElem = “u”;
while(rng.MoveToElement(targetElem)) {
rng.SelectContainerContents();
rng.Surround(insertElem);
}Depending on your actual needs, the full content of your documents, and the starting position for the Selection, that code may either be a good or bad way to solve your issue. Without knowing the full details I cannot say. I suspect that you will find it needs to at least be extended to cover cases that you have not anticipated.
-
AuthorPosts
- You must be logged in to reply to this topic.