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

Change attribute value for sequence order

Contributor ,
Mar 30, 2016 Mar 30, 2016

Copy link to clipboard

Copied

Dear Java Expert.

I was try to script. Find/Change attribute(id) value for sequence order (attached screenshot for your reference). It is passable to script?

Example:

id = table8_3   change to   id = table8_1

id = table8_3   change to   id = table8_2

id = table8_3   change to   id = table8_3

Screen Shot 2016-03-30 at 5.03.27 PM.png

Please suggest friends.

Advance Thanks,

TOPICS
Scripting

Views

555

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

Enthusiast , Mar 30, 2016 Mar 30, 2016

Hi,

Something like that ...

var doc = app.activeDocument;

var _XML = doc.xmlElements[0];

var _XMLelements = _XML.evaluateXPathExpression("//*/table[@id='table8_3']")

for(var i=0;i<_XMLelements.length;i++){

    _XMLelements.xmlAttributes.item("id").value= 'table8_' + (i+1);

}

Regards

Votes

Translate

Translate
Enthusiast ,
Mar 30, 2016 Mar 30, 2016

Copy link to clipboard

Copied

Hi,

Something like that ...

var doc = app.activeDocument;

var _XML = doc.xmlElements[0];

var _XMLelements = _XML.evaluateXPathExpression("//*/table[@id='table8_3']")

for(var i=0;i<_XMLelements.length;i++){

    _XMLelements.xmlAttributes.item("id").value= 'table8_' + (i+1);

}

Regards

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
Contributor ,
Mar 30, 2016 Mar 30, 2016

Copy link to clipboard

Copied

Hi Ronald63

Thanks so match Ronald.

I have run your script. I got result is undefined and also alert(_XMLelements.length); // Table length is 0?. What i mistake here Ronald. Please suggestion me.

Screen Shot 2016-03-31 at 10.32.19 AM.png

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
People's Champ ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

If your table is a direct child of the root, your xpath won't return anything as you are looking for a table inside any possible element starting from the root.

So

/root/xxxx/table => OK

/root/table => NO OK

You should use

var doc = app.activeDocument; 

var _XML = doc.xmlElements[0]; 

var _XMLelements = _XML.evaluateXPathExpression("//table[@id='table8_3']") 

 

for(var i=0;i<_XMLelements.length;i++){ 

    _XMLelements.xmlAttributes.item("id").value= 'table8_' + (i+1); 

}

Loic

Ozalto | Productivity Oriented - Loïc Aigon

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
Contributor ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

HI Loic.Aigon,

Thank you Loic, your script is working super.

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
People's Champ ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

LATEST

You should have marked Ronald63‌'s answer as corerct instead of mine. I have done much than refining the path.

Loic

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