0
Array sort with XML Attributes
New Here
,
/t5/indesign-discussions/array-sort-with-xml-attributes/td-p/1079196
Mar 20, 2009
Mar 20, 2009
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/array-sort-with-xml-attributes/m-p/1079197#M367009
Mar 21, 2009
Mar 21, 2009
Copy link to clipboard
Copied
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
The general idea is described here (first hit on a Google search):
http://solutoire.com/2007/05/02/sorting-javascript-arrays/
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_sudar1983_
AUTHOR
New Here
,
/t5/indesign-discussions/array-sort-with-xml-attributes/m-p/1079198#M367010
Mar 22, 2009
Mar 22, 2009
Copy link to clipboard
Copied
Thanks Dave,
I have sorted using attribute, but in the second question Is it possible or not?
Regards,
Sudar
I have sorted using attribute, but in the second question Is it possible or not?
Regards,
Sudar
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
LATEST
/t5/indesign-discussions/array-sort-with-xml-attributes/m-p/1079199#M367011
Mar 23, 2009
Mar 23, 2009
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

