我有一个 struct 化的InDesign文档.我 Select 了一个带有文本的文本框架,其中的一些符号用一个XML标记‘XXX’来标记.我想用‘YYY’标签来标记这篇文章中的所有其他文本.
我试过这个代码:
var mySelection = app.selection[0]; // Get the selected frame
var tagToApply = "YYY"; // Tag to apply
var tagToSkip = "XXX"; // Tag to skip
var myTextFrame = mySelection;
var myTexts = myTextFrame.texts;
var myStory = myTextFrame.parentStory;
// Function to check if the text is not marked with tag to skip
function isUntagged(text) {
return text.associatedXMLElements.name !== tagToSkip;
}
// Check all the text in the selected frame
for (var i = 0; i < myTexts.length; i++) {
var thisText = myTexts[i];
if (isUntagged(thisText)) {
// Mark the found untagged text with the tag to apply
var myXMLElement = app.activeDocument.xmlElements.item(0).xmlElements.add(tagToApply, thisText);
}
}
问题是,所有的故事文本都标记了‘YYY’标记,包括标记为‘XXX’的片段.