When I asked the question I thought I could use some sxml function to do this job. Particularly, I found out a way to do it with the SXML modifications explained here:

http://www.modis.ispras.ru/Lizorkin/sxml-tutorial.html#hevea:modif

Unfortunately this is not available in Guile. So, This function removes whitespace text nodes from an sxml.

(define (remove-whitespace-nodes sxml)
  (define (node-fix node)
    (cond ((symbol? node) (list node))
          ((string? node) (if (string-null? (string-trim node))
                              #nil
                              (list node)))
          (else (list (remove-whitespace-nodes node)))))
  (let loop ((node sxml) (result '()))
    (cond ((null? node) result)
          (else (loop (cdr node)
                      (append result (node-fix (car node))))))))

I'm new to scheme, so a code review is really welcome!

Cheers,

Aleix

Reply via email to