1 Reply Latest reply on Mar 29, 2013 4:47 PM by booyajamo

    set fonts and styles based on xml parent's attribute

    patchlab

      Hi,

       

      I am trying to write an Indesign javascript that can set the font and style based on the import XML parent's attribute,

       

      <products>

      <product>

          <language value="EN"><feature_1>1000w</feature><feature_2>10 max</feature_2></language>

          <language value="JP"><feature_1>500w</feature><feature_2>2 max</feature_2></language>

          <language value="TCN"><feature_1>750w</feature><feature_2>5 max</feature_2></language>

      </product>

      <product>

          <language value="EN"><feature_1>2000w</feature></language>

          <language value="TCN"><feature_1>2500w</feature><feature_2>2 max</feature_2><color>red</color></language>

      </product>

      </products>

       

      each feature tag will be in its own tag frame.

       

      all the sub-set under language value="EN" will have like Univers font, font size 100%, align to left  (which mean 1000w, 10 max, and 2000w will be this)

       

      all the sub-set under language value="TCN" will have Sim Hei font, font size 100%, align to right

       

      all the sub-set under language value="JP" will have MS Gothic font, font size 125%, align to left

       

      I am new to indesign scripting, can someone point me to the right direction to get this started?

       

      Thanks,

        • 1. Re: set fonts and styles based on xml parent's attribute
          booyajamo

          Hello,

           

          You can define the paragraph styles something like:

           

          var myParagraphStyle = app.activeDocument.paragraphStyles.add ({
               name: "stylename", 
               appliedFont: "Univers", 
               pointSize: 12
          });
          

           

          Then you can create an import map (to map the defined styles to your XML elements) like:

           

          var myImportMap = app.activeDocument.xmlImportMaps.add ("myTagName", myParagraphStyle);
          

           

          Then you import the XML

           

          app.activeDocument.importXML (File ("C:/xmlfile.xml"));
          

           

          Then place the XML on your page (you can do this several different ways)

           

          app.activeDocument.pages[0].placeXML (app.activeDocument.xmlElements[0], [0,0], true);
          

           

          I'd be interested to know if others have had issues with mapping styles to XML elements when you place the XML? Even on extremely small documents (approximately 2 pages of content) my INDD crashes when I have mapped styles. Non-mapped XML elements place fine.

           

          Thanks,

          Lindsay