Extracting heading elements of a certain level from a lowdown document added by DerGuteMoritz on Wed Oct 3 17:22:10 2012
(use sxml-transforms clojurian-syntax) (define (extract-headings doc level) (->> `((heading *preorder* . ,(lambda (name children) (and (pair? children) (= level (car children)) (cons name children)))) (*default* . ,(constantly #f))) (pre-post-order* doc) (filter identity))) (define doc '((heading 1 "foo") (paragraph "test") (heading 2 "bar") (heading 1 "nice"))) (extract-headings doc 1) ; => ((heading 1 "foo") (heading 1 "nice")) (extract-headings doc 2) ; => ((heading 2 "bar"))