Sorting ... sure, we do it all the time. Even the Samples have an example of two of sorting using jscript. In general, you need to create a separate secondary DOM to insert your elements into or create an index in your main DOM into the secondary DOM. Sounds like you want to do an xsl sort though, which is also possible but has to be defined in the xsl via the filter. Greg will have more info.
Patrick Halstead [InfoPath MVP]
InfoPathDev
Patrick Halstead
Project Manager at Qdabra