Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort XML document in Javascript?

Status
Not open for further replies.

gdrenfrew

Programmer
Aug 1, 2002
227
GB
Hello,

I currently display a list of orders on an HTML page, and use XSLT to transform the incoming XML into a particular sort order.

Is it possible to sort an XMLDocument in Javascript using some transform function?

Customer now wants the data from the page copied to the clipboard so it can be pasted into another app.

I'm using javascript to get the fields they want available in the other application. The probelm is the XML document I've got in the script is unsorted. Is it possible to sort an XMLDocument in Javascript? If so, how would I achieve this?

I want to sort by ascending order number.
XML:
<orders>
<order>
<orderid>4</orderid>
<customer>bert</customer>
</order>
<order>
<orderid>2</orderid>
<customer>big bird</customer>
</order>
<order>
<orderid>1</orderid>
<customer>mr. snuffleupagus</customer>
</order>
<order>
<orderid>5</orderid>
<customer>guy smiley</customer>
</order>
</orders>

thanks in advance
 
Use your XSLT to sort it for you:


Code:
<xsl:for-each select="/orders/order">
	<xsl:sort select="orderid" data-type="number"/>
	<xsl:value-of select="customer"/><br />
</xsl:for-each>

This is better because you're code isn't then hardcoded into trying to manipulate the data, the transformation is (which is what is dealing with how it looks, after all ;)


Matt

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top