Hi all,
first of all thanks for your work on clojure. It's a lot of fun to
hack on it!
Maybe somebody has the same problem and can use the following code as
a start: I wanted to transform an XHTML-template to the HTML DSL
that's coming with clojure. Luckily everything is available in the
base or contrib libs so it wasn't that hard to do.
(ns de.evernet2000.util
(:use clojure.contrib.str-utils)
(:use clojure.contrib.duck-streams)
(:use clojure.contrib.pprint)
(:use [clojure.xml :only (parse)])
(:import (
java.io File)))
(defn format-attrs
[m]
(when m
(format "%s" m)))
(defn empty-when-null
[x]
(if (nil? x)
""
x))
(declare format-full-node)
(defn format-node
[node]
(cond
(string? node) (format "\"%s\"" (.trim node))
(nil? node) nil
:else (format-full-node node)))
(defn format-full-node
[node]
(format "[%s %s %s]\n"
(:tag node)
(empty-when-null (format-attrs (:attrs node)))
(str-join " " (map format-node (:content node)))))
(defn transform-file
[filename]
(print (pprint (read-string (format-node (parse filename))))))
Cheers,
Robin