(=> (q 'sd) (map create-document (find-all-from))) (define (find-all-from) (uniquify (map contents (node-set->list (q '(type: at name: from owner: fare)))))) (define (create-document from) (create-root from output-dtd (subtree-spec add: '((type sd)) children: (list (create-table from))))) (define (create-table from) (create-element 'table '() (cons (create-title from) (append (create-header-rows) (map (lambda (to) (create-data-row from to)) (find-all-to from)))))) (define (find-all-to from) (sort-uniquify (map contents (q `(type: at name: to owner: (fare attribute: from ,from)))))) (define (create-element gi attributes children) (subtree-spec add: `((type el) (gi ,gi)) attributes: attributes children: children)) (define (create-data-row from to) (create-element row '() (list (create-cell from to 'adult 'single) (create-cell from to 'adult 'return) (create-cell from to 'child 'single) (create-cell from to 'child 'return)))) (define (create-cell from to child return) (create-element 'cell '() (string->subtree-spec (contents (q `(fare attribute: from ,from attribute: to ,to attribute: child ,child attribute: return ,return)))))) ;; the remaining functions are left as an exercise to the reader