2 Replies Latest reply on Apr 26, 2010 12:25 AM by sudar1983_14

    index

    kumargobi

      Dear All,

       

      In indesign cs3 Add index topics using below javascript code. This Source are to get topics from only character style content. But I want to get a topics in some xml tags. for example

      <index> addcontent</Index>

       

      How to get Xml Element content in javascript or xpath?

       

      I am using below codes

       

      "app.findGrepPreferences.appliedCharacterStyle = "Inx";

      var myFinds = doc.findGrep();

      var myHowManyEntries = myFinds.length;

      for (i = myHowManyEntries-1; i >= 0; i--){

      var myTopic = doc.indexes[0].topics.add(myFinds[i].contents);

      myTopic.pageReferences.add (myFinds[i],PageReferenceType.CURRENT_PAGE);"

      Regards,
      kumargobi

        • 1. Re: index
          HoneoyeFalls

          how about add a script to map tags to styles (if the style and the element tag are only used for indexing)?

          • 2. Re: index
            sudar1983_14 Level 2

            Gopi,

             

            Please try the following code.

             

            var scriptTitle="Add Index";
            var indexItems=new Array();
            var indexElementName='index';

             

            var aDoc=app.activeDocument;

             

            app.doScript (File(app.filePath+"/Scripts/Xml Rules/glue code.jsx"));

             

            getElements(aDoc.xmlElements.item(0));

             

            if (indexItems.length > 0)
            {
                aDoc.indexes.add();
                for(var ind=0; ind < indexItems.length; ind++)
                {
                    var myTopic = aDoc.indexes[0].topics.add(indexItems[ind].contents);
                    myTopic.pageReferences.add (indexItems[ind].texts[0],PageReferenceType.CURRENT_PAGE);
                }
            }
            else
            {
                alert("There is no <"+indexElementName+"> element in the active document", scriptTitle);
                exit(0);
            }

             

            function getElements(rootElement)
            {
                var myCondition;
                var EntRuleSet = new Array(new FindElement("//"+indexElementName));
                __processRuleSet(rootElement, EntRuleSet);
            }

             

            function FindElement(myRule)
            {
                this.name = "FindElement";
                this.xpath = myRule;
                this.apply = function(myElement, myRuleProcessor)
                {
                    indexItems.push(myElement);
                }
            }

             

             

             

            Arivu