2 Replies Latest reply on Sep 14, 2012 5:10 AM by Vamitul

    Apply a paragraph style to XML elements that have a specific attribute

    Vamitul Level 4

      1) I'm an almost complete noob when it comes to XML

      2) I have an XML with a ssstructure like this:

       

       

      <chapter>
           <paragraph> bla bla </paragraph>
           <paragraph> bla bla </paragraph>
           <list type="disk">
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
           </list>
      
           <list type="square">
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
                <listitem>
                     <paragraph> bla bla </paragraph>
                     <paragraph> bla bla </paragraph>
                </listitem>
           </list>
      </chapter>
      

       

      Is there a easyer way (except iterating all the xmlElements) to find all the lists and apply the appropriate paragraph style (i have a "list_with_disk" paragraphstyle, and a "list_with_square" one)?

        • 1. Re: Apply a paragraph style to XML elements that have a specific attribute
          csm_phil Level 4

          Hi Vamitul,

           

          Please try the below JS code.

           

           

          var myDoc = app.activeDocument;
          //____________________ disk bullet style apply
          try{
              var rootElement = myDoc.xmlElements.item(0);
              var linkElementList = rootElement.evaluateXPathExpression("//list[@type='disk']//paragraph");
              for(i=linkElementList.length-1; i>=0; i--){
                  var myAttribute = linkElementList[i];
                  myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Disk");
                  }
              }catch(e){}
          //_______________________________________________________________________________
          
          //____________________ Squar bullet style apply
          try{
              var rootElement = myDoc.xmlElements.item(0);
              var linkElementList = rootElement.evaluateXPathExpression("//list[@type='square']//paragraph");
              for(i=linkElementList.length-1; i>=0; i--){
                  var myAttribute = linkElementList[i];
                  myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Square");
                  }
              }catch(e){}
          //_______________________________________________________________________________
          

           

           

          thx,

          csm_phil