Welcome to the CHICKEN Scheme pasting service

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"))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure that returns the car of a cdr?
Visually impaired? Let me spell it for you (wav file) download WAV