• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Advisor ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

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)?

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Sep 14, 2012 Sep 14, 2012

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;

        myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Disk");

        }

    }catch(e){}

//_______________________

...

Votes

Translate

Translate
Advocate ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

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;

        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;

        myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Square");

        }

    }catch(e){}

//_______________________________________________________________________________

thx,

csm_phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

LATEST

thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines