Something like:
Code:
var sortByName = function(node1, node2){
    var v1 = node1.text, v2 = node2.text;
    if (v1 < v2) {
        return -1;
    } else if (v1 > v2) {
        return 1;
    }
    return 0;
};
var sortByCount = function(node1, node2){
    var v1 = node1.attributes.count, v2 = node2.attributes.count;
    return v1 - v2;
};