14.6 SXML Templates

SXML is an alternative syntax for writing XML data, using the form of S-expressions.

SXML is to Scheme as JSON is to ECMAScript(the so-called Javascript). Maybe this explains it clearer.

One benefit of SXML is that it takes advantage of the quasiquote in Scheme. Please search in the internet "scheme quasiquote" for more details.

This is an SXML expression:

(tpl->response '(html (body (p (@ (id "content")) "hello world"))))

The above would result the following HTML code:

<html><body><p id="content">hello world</p></body></html>

Sometimes you may need quasiquote to refer to a variable, for example:

(let ((content "hello world"))
  (tpl->response `(html (body (p (@ (id "content")) ,content)))))

Here, the "html" block is being quoted with the backtick, which in combination with a "," character before the variable name, makes the variable be referred to instead of just passing a string.