modules/@themost/xml/xpath.js
function xpathSort(input, sort) {
    if (sort.length === 0) {
        return;
    }
    var sortlist = [];
    var i;
    for (i = 0; i < input.contextSize(); ++i) {
        var node = input.nodelist[i];
        var sortitem = {node: node, key: []};
        var context = input.clone(node, 0, [node]);

        for (var j = 0; j < sort.length; ++j) {
            var s = sort[j];
            var value = s.expr.evaluate(context);

            var evalue;
            if (s.type === 'text') {
                evalue = value.stringValue();
            } else if (s.type === 'number') {
                evalue = value.numberValue();
            }
            sortitem.key.push({value: evalue, order: s.order});
        }

        // Make the sort stable by adding a lowest priority sort by
        // id. This is very convenient and furthermore required by the
        // spec ([XSLT] - Section 10 Sorting).
        sortitem.key.push({value: i, order: 'ascending'});

        sortlist.push(sortitem);
    }

    sortlist.sort(xpathSortByKey);

    var nodes = [];
    for (i = 0; i < sortlist.length; ++i) {
        nodes.push(sortlist[i].node);
    }
    input.nodelist = nodes;
    input.setNode(0);
}
function xpathSort(input, sort) {
    if (sort.length === 0) {
        return;
    }
    var sortlist = [];
    var i;
    for (i = 0; i < input.contextSize(); ++i) {
        var node = input.nodelist[i];
        var sortitem = {node: node, key: []};
        var context = input.clone(node, 0, [node]);

        for (var j = 0; j < sort.length; ++j) {
            var s = sort[j];
            var value = s.expr.evaluate(context);

            var evalue;
            if (s.type === 'text') {
                evalue = value.stringValue();
            } else if (s.type === 'number') {
                evalue = value.numberValue();
            }
            sortitem.key.push({value: evalue, order: s.order});
        }

        // Make the sort stable by adding a lowest priority sort by
        // id. This is very convenient and furthermore required by the
        // spec ([XSLT] - Section 10 Sorting).
        sortitem.key.push({value: i, order: 'ascending'});

        sortlist.push(sortitem);
    }

    sortlist.sort(xpathSortByKey);

    var nodes = [];
    for (i = 0; i < sortlist.length; ++i) {
        nodes.push(sortlist[i].node);
    }
    input.nodelist = nodes;
    input.setNode(0);
}
function xpathSort ( input , sort ) { if ( sort . length === 0 ) { return ; } var sortlist = [ ] ; var i ; for ( i = 0 ; i < input . contextSize ( ) ; ++ i ) { var node = input . nodelist [ i ] ; var sortitem = { node : node , key : [ ] } ; var context = input . clone ( node , 0 , [ node ] ) ; for ( var j = 0 ; j < sort . length ; ++ j ) { var s = sort [ j ] ; var value = s . expr . evaluate ( context ) ; var evalue ; if ( s . type === 'text' ) { evalue = value . stringValue ( ) ; } else if ( s . type === 'number' ) { evalue = value . numberValue ( ) ; } sortitem . key . push ( { value : evalue , order : s . order } ) ; } // Make the sort stable by adding a lowest priority sort by // id. This is very convenient and furthermore required by the // spec ([XSLT] - Section 10 Sorting). sortitem . key . push ( { value : i , order : 'ascending' } ) ; sortlist . push ( sortitem ) ; } sortlist . sort ( xpathSortByKey ) ; var nodes = [ ] ; for ( i = 0 ; i < sortlist . length ; ++ i ) { nodes . push ( sortlist [ i ] . node ) ; } input . nodelist = nodes ; input . setNode ( 0 ) ; }
Utility function to sort a list of nodes. eslint-disable-next-line no-unused-vars
Utility function to sort a list of nodes . eslint - disable - next - line no - unused - vars