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

Array sort with XML Attributes

New Here ,
Mar 20, 2009 Mar 20, 2009
Hi All,

Windows / CS3 / JavaScript

1. I have XML Elements in Array, each Element have attribute called pg='34' like this, I want to sort this array using 'pg' attribute.

2. I am Reading all stories from indesign file, it is not coming with perfect alignment order (ie) First story coming from last page and second story coming from first page. I want to align the stories with layout order.

Regards,
Sudar
TOPICS
Scripting
876
Translate
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
Participant ,
Mar 21, 2009 Mar 21, 2009
Use a callback function with the standard JavaScript sort call. The function would be responsible for comparing the values of the pg attributes and returning -1, 0 or 1 to the sort function.

The general idea is described here (first hit on a Google search):

http://solutoire.com/2007/05/02/sorting-javascript-arrays/

Dave
Translate
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
New Here ,
Mar 22, 2009 Mar 22, 2009
Thanks Dave,

I have sorted using attribute, but in the second question Is it possible or not?

Regards,
Sudar
Translate
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
Participant ,
Mar 23, 2009 Mar 23, 2009
LATEST
You'll need to get the stories references into an array:

myStories = myDocument.stories.everyItem().getElements();

and the sort them based on the page numbers of the first text container.

So, yes it is possible.

Dave
Translate
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