Looping over all xml elements
how loop on tagged xml elements in story? i've created reference xml elements of story want this:
var xmlstory = mydoc.xmlelements[0].xmlelements[0];
in structure have elements <v>10</v> want change <v id="10">10</v>. i'd in indesign scripting , not xsl upon export because of workflow i'm planning. know can loop on children in structure this:
for(var i=0;i<xmlstory.xmlelements.length;i++){ if(xmlstory.xmlelements[i].markuptag.name == "v"){ xmlstory.xmlelements[i].xmlattributes.add("id", xmlstory.xmlelements[i].contents); } }
this works fine first level, want find every element markup tag "<v>". these tags can appear @ level in structure. how make sure of them included , not first child elements of story element?
hi simonlinden,
please try below js code works cs5.5.
#target indesign; #include /program files (x86)/adobe/adobe indesign cs5.5/scripts/xml rules/glue code.jsx// change script path in indesign version cs4 or cs5 var mydoc = app.activedocument; //____________________ xml rule set var myruleset = new array (new margintag); with(mydoc){ var elements = xmlelements; __processruleset(elements.item(0), myruleset); } function margintag(){ this.name = margintag; this.xpath = "//v"; this.apply = function(myelement, myruleprocessor){ with(myelement){ try{ myelement.xmlattributes.add("id", myelement.xmlcontent.contents); }catch(e){} } return true; } }
thx,
csm_phil
More discussions in InDesign Scripting
adobe
Comments
Post a Comment