Skip to main content
Participant
April 22, 2009
Question

index

  • April 22, 2009
  • 2 replies
  • 571 views

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.contents);

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

Regards,
kumargobi

This topic has been closed for replies.

2 replies

April 26, 2010

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

April 25, 2010

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