(define button-a (sxml-zipper `(button (@ (class "button")) "foo"))) (define button-b (sxml-zipper `(button (@ (class "red") (id "foo")) "hi"))) (define (find-class-attr x) (and-let* ((x (find-first x (tag= '@)))) (find-first x (tag= 'class)))) (define (merge-classes a b) (and-let* ((x (text (find-class-attr a))) (y (find-class-attr b)) (y (edit y (lambda (n) (cons* (car n) x " " (cdr n)))))) (root y))) ;;; usage: (node (merge-classes button-a button-b)) => (button (@ (class "button" " " "red") (id "foo")) "hi")