sxml tranform attributes pasted by iterrogo on Tue Mar 25 16:10:32 2014
`(button (@ (class "button")) ,@body) ; plus `(button (@ (class "red") (id "foo")) "hi") ; => (button (@ (class "button red") (id "foo")) "hi")
using sxml-zipper (in theory) added by DerGuteMoritz on Tue Mar 25 17:16:37 2014
(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")