ok, Ive got a script I am using that reads data from an XML file, then outputs that information into a table when a link is clicked. It works great as it is right now, however I want to be able to sort the information in different ways and am not sure what the best way to do this would be...

I just want to write a new function that will say sort this alphabetically, or by section or whatever else... any help would be greatly appreciated...

david_kw

12-06-2006, 11:15 PM

If you are just trying to sort the output and not the XML you just put your info in an array then sort it using sort(). If it is too big or you need to sort the whole XML tree then XSL is probably the way to go. Here is an example of sorting the array once it is created.

OK, i got it doing what I want. Now i have a new problem to solve. I have it setup so my data from the xml file gets inserted into 2 arrays. 1 array as an "index" for the words, then within that, each element is its own array with the word, section, and definition.

The first item of the array in each is the word name, allowing for easy alphabetically, however I am trying to sort by section and am not sure what the best way to do this would be. any ideas?

thank you that makes a lot of sense after being layed out better... what function would i use to change the place of items within the array though?
(What would the 0, 1, or -1 be sent into to make this shift?)

david_kw

12-08-2006, 10:53 PM

Ahh, I see your question. The key is this line.

array1.sort(sortAlphaBySection);

This is a built in javascript function. It takes the "testing" function as a parameter. This function actually does the moving around. The sort() function calls your testing function to see how to compare two elements of the array so that the sort() function can move them around. For more information on sort() you can look here