Hi Daniel,
thanks a lot for your observations, I know moustache.{xq,js} as well, and I'd be thrilled if we eventually come up with our own BaseX compatible implementation :-)
Anyway, until then, I'd like to let you know how we handle this at the moment: We introduce a template module that accepts a map of options and some content. Inside the template wrapping function, we wire our page elements with the map’s contents. This proved to be rather flexible while still being lightweight enough to be out of the way most of the time.
Please excuse the messed up highlighting: https://gist.github.com/e053068a41eb35e727bb
We chose maps, as they make it especially easy to provide default values that can be easily overridden from calling functions by combining a map:
let $defaults := map {"Foo" := "Bar", "foo" := "bar", "Bar" := "Foo"} let $options := map {"Foo" := "Override"} let $options := map:new(($defaults, $options)) return string-join(map:keys($options) ! (. || " := "|| $options(.)), " ")
I hope this helps feel free to discuss this issue more :)
Michael
Am 17.11.2012 um 19:27 schrieb Daniel Kvasnička daniel.kvasnicka@me.com:
Hi folks,
another thing I'm trying to solve while working on a XQuery web app. What kind of templating system do you use to separate HTML templates from the rest of your code?
XSLT - the only problem I have with this is performance. I tested the XSLT Module with Saxon 9 and a primitive page and it was more than 3x slower compared to pure XQuery templates (XQuery fn taking $model). Other than that I think it's the best built-in option. I actually don't have any users-per-second expectations and those templates will be quite small... do I overemphasize the perf. question?
pure XQuery - not aimed at templating at all and it shows I'm afraid... just can't come up with a solution that would be clean enough (plus HTML, JS & CSS highlighting withing xq files is not good at all, at least in Vim)
I looked at Mustache.xq and quite liked it - depends on MarkLogic though :(
Any hidden gem I haven't googled yet?
Leaning towards XSLT right now... Daniel
-- danielkvasnicka.net
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk