eerohele / sigel

XSLT and XPath in your Clojure
Eclipse Public License 1.0
28 stars 3 forks source link

hiccup-style input #6

Open akond opened 1 year ago

akond commented 1 year ago

I frequently find myself utilizing hiccup-style data structures rather than strings/streams. Something like:

[:list
     [:token "defproject"]
     [:whitespace " "]...
   ]

In the past, I would convert it into a string and then perform my XSLT transformations. However, more recently, I crafted a straightforward wrapper around TinyBuilder.

(defn xml-document [tree]
    (let [processor     (Processor. false)
          configuration (.getUnderlyingConfiguration processor)
          builder       (TinyBuilder. (.makePipelineConfiguration configuration))
          walk          (fn walk [x]
                            (if (coll? x)
                                (do
                                    (.startElement builder (FingerprintedQName. "" "" (name (first x))) (Untyped/getInstance) ExplicitLocation/UNKNOWN_LOCATION 0)
                                    (run! walk (rest x))
                                    (.endElement builder))
                                (.characters builder x ExplicitLocation/UNKNOWN_LOCATION 0)))]
        (.open builder)
        (.startDocument builder 0)
        (walk tree)
        (.close builder)
        (.getRootNode (.getTree builder))))

At present, it does not have the capability to handle attributes. Would you be interested in incorporating this code into your library once it is completed?

eerohele commented 1 year ago

Interesting! I'll have to think on this a bit.