0

I'm working with XML files in InDesign CS6 that each have several dozen paragraphs where the attribute class="boxtitle". Each of these need to be set to the "Boxtitle" paragraph style. Because InDesign won't let you set styles based on attributes, my only options for assigning the correct styles to the relevant paragraphs is to do so manually, or via script.

Naturally, I chose the latter, and found a script on the Adobe forums that seemed like it would do the trick. Unfortunately, the script isn't working and I'm not sure why.

var myDoc = app.activeDocument;
//____________________ Apply Boxtitle
try{
var rootElement = myDoc.xmlElements.item(0);
var subheadElementList = rootElement.evaluateXPathExpression("Boxtitle");
for(i=subheadElementList.length-1; i>=0; i--){
    var myAttribute = subheadElementList[i];
    myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("boxtitle");
    }
}catch(e){}

If anyone can point me to what's going wonky here, I'd appreciate it. Thanks!

ajw-art
  • 173
  • 1
  • 1
  • 12

1 Answers1

1

you will want to use the correct xPath Expression to match your paragraphs

var subheadElementList = rootElement.evaluateXPathExpression("//*[@class = 'boxtitle']");

or more specific if your paragraphs have the markupTag name "mypara" for Example:

var subheadElementList = rootElement.evaluateXPathExpression("//mypara[@class = 'boxtitle']");
jko
  • 11
  • 1