[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.16 sxml-match
: Pattern Matching of SXML
The (sxml match)
module provides syntactic forms for pattern matching of
SXML trees, in a “by example” style reminiscent of the pattern matching of the
syntax-rules
and syntax-case
macro systems. See section the (sxml simple)
module, for more information on SXML.
The following example(23) provides a brief illustration, transforming a music album catalog language into HTML.
(define (album->html x) (sxml-match x [(album (@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...) `(ul (li ,t) (li (b ,n) (i ,f)) ...)]))
Three macros are provided: sxml-match
, sxml-match-let
, and
sxml-match-let*
.
Compared to a standard s-expression pattern matcher (see section Pattern Matching), sxml-match
provides the following benefits:
- matching of SXML elements does not depend on any degree of normalization of the SXML;
- matching of SXML attributes (within an element) is under-ordered; the order of the attributes specified within the pattern need not match the ordering with the element being matched;
- all attributes specified in the pattern must be present in the element being matched; in the spirit that XML is ’extensible’, the element being matched may include additional attributes not specified in the pattern.
The present module is a descendant of WebIt!, and was inspired by an s-expression pattern matcher developed by Erik Hilsdale, Dan Friedman, and Kent Dybvig at Indiana University.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 3, 2012 using texi2html 5.0.