Home › Forums › General XMetaL Discussion › How to loop through current selection › Reply To: How to loop through current selection
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.