#! /bin/sh string=? ; exec mzscheme -M errortrace -gr $0 $* ; $Id: soccer.scm,v 1.2 2004/01/21 02:56:05 kl Exp kl $ ; http://pair.com/lisovsky/transform/examples/ (require (lib "sxml-tools.ss" "sxml") (lib "sxpath.ss" "sxml") (lib "stx-engine.ss" "sxml") (lib "fragments.ss" "sxml")) ; Source document (define doc (read (open-input-file "soccer.sxml"))) ; Transformation stylesheet (define sst (sxml:stylesheet (match 'results (lambda (current-node stx:templates current-root $) `(html (head (title "Result of group " ,(sxml:attr current-node 'group))) (body (h1 "Result of group " ,(sxml:attr current-node 'group)) ,@(xsl:apply-templates))))) (match 'match (lambda (current-node stx:templates current-root $) (let* ((team1 ((car-sxpath '((team 1))) current-node)) (team2 ((car-sxpath '((team 2))) current-node))) `((h2 ,(sxml:text team1) " versus " ,(sxml:text team2)) (p "Played on " ,((car-sxpath '(date *text*)) current-node)) (p "Result: " ,(sxml:text team1) " " ,(sxml:attr team1 'score) "," ,(sxml:text team2) " " ,(sxml:attr team2 'score)))))) )) ; 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