#! /bin/sh string=? ; exec mzscheme -M errortrace -gr $0 $* ; http://pair.com/lisovsky/transform/examples/ (require (lib "sxml-tools.ss" "sxml") (lib "sxpath.ss" "sxml") (lib "13.ss" "srfi") (lib "common.ss" "sxml") (lib "myenv.ss" "ssax") (lib "stx-engine.ss" "sxml") (lib "fragments.ss" "sxml")) ; Read thw document to transform (define doc (read (open-input-file "mail.sxml"))) ; A "demo" spam filter: any email which contains % character in subject ; is considered spam. ; You can use _any_ Scheme function instead of this one-liner. ; For real filtering a Bayesian filter ; http://www.shiro.dreamhost.com/scheme/vault/scbayes.tgz ; is worth a consideration (define (is-spam? msg) (string-contains ((car-sxpath '(subject *text*)) msg) "%")) ; Transformation stylesheet (define sst (sxml:stylesheet (match 'mailbox (lambda (current-node stx:templates current-root $) `(html (head (title "Mail messages")) (body (h1 "E-mail subjects: ") (ol ,@(xsl:apply-templates)))))) (match 'msg (lambda (current-node stx:templates current-root $) `(li ,@(if (is-spam? current-node) ; if the message is spam '("[SPAM] ") ; insert the tag '()) ,((car-sxpath '(subject *text*)) current-node)) )) )) ; Do the transformation and print out HTML output (sxml:display-fragments (sxml:sxml->html (stx:apply-templates doc ; document sst ; stylesheet doc ; root '()))) ; var bindings