Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: SXML   [Contents][Index]


7.20.4 Transforming SXML

7.20.4.1 Overview

SXML expression tree transformers

Pre-Post-order traversal of a tree and creation of a new tree

pre-post-order:: <tree> x <bindings> -> <new-tree>

where

 <bindings> ::= (<binding> ...)
 <binding> ::= (<trigger-symbol> *preorder* . <handler>) |
               (<trigger-symbol> *macro* . <handler>) |
		(<trigger-symbol> <new-bindings> . <handler>) |
		(<trigger-symbol> . <handler>)
 <trigger-symbol> ::= XMLname | *text* | *default*
 <handler> :: <trigger-symbol> x [<tree>] -> <new-tree>

The pre-post-order function visits the nodes and nodelists pre-post-order (depth-first). For each <Node> of the form (name <Node> ...), it looks up an association with the given name among its <bindings>. If failed, pre-post-order tries to locate a *default* binding. It’s an error if the latter attempt fails as well. Having found a binding, the pre-post-order function first checks to see if the binding is of the form

	(<trigger-symbol> *preorder* . <handler>)

If it is, the handler is ’applied’ to the current node. Otherwise, the pre-post-order function first calls itself recursively for each child of the current node, with <new-bindings> prepended to the <bindings> in effect. The result of these calls is passed to the <handler> (along with the head of the current <Node>). To be more precise, the handler is _applied_ to the head of the current node and its processed children. The result of the handler, which should also be a <tree>, replaces the current <Node>. If the current <Node> is a text string or other atom, a special binding with a symbol *text* is looked up.

A binding can also be of a form

	(<trigger-symbol> *macro* . <handler>)

This is equivalent to *preorder* described above. However, the result is re-processed again, with the current stylesheet.

7.20.4.2 Usage

Scheme Procedure: SRV:send-reply . fragments

Output the fragments to the current output port.

The fragments are a list of strings, characters, numbers, thunks, #f, #t – and other fragments. The function traverses the tree depth-first, writes out strings and characters, executes thunks, and ignores #f and '(). The function returns #t if anything was written at all; otherwise the result is #f If #t occurs among the fragments, it is not written out but causes the result of SRV:send-reply to be #t.

Scheme Procedure: foldts fdown fup fhere seed tree
Scheme Procedure: post-order tree bindings
Scheme Procedure: pre-post-order tree bindings
Scheme Procedure: replace-range beg-pred end-pred forest

Next: , Previous: , Up: SXML   [Contents][Index]