merge stable-2.0
[bpt/guile.git] / doc / ref / sxml.texi
1 @c -*-texinfo-*-
2 @c This is part of the GNU Guile Reference Manual.
3 @c Copyright (C) 2013 Free Software Foundation, Inc.
4 @c See the file guile.texi for copying conditions.
5
6 @node SXML
7 @section SXML
8
9 @menu
10 * sxml apply-templates:: A more XSLT-like approach to SXML transformations
11 * sxml fold:: Fold-based SXML transformation operators
12 * sxml simple:: Convenient XML parsing and serializing
13 * sxml ssax:: Functional-style XML parsing for Scheme
14 * sxml ssax input-parse:: The SSAX tokenizer, optimized for Guile
15 * sxml transform:: A higher-order SXML transformation operator, @code{pre-post-order}
16 * sxml xpath:: XPath for SXML
17 @end menu
18
19 @node sxml apply-templates
20 @subsection (sxml apply-templates)
21 @subsubsection Overview
22 Pre-order traversal of a tree and creation of a new tree:
23
24 @smallexample
25 apply-templates:: tree x <templates> -> <new-tree>
26 @end smallexample
27
28 where
29
30 @smallexample
31 <templates> ::= (<template> ...)
32 <template> ::= (<node-test> <node-test> ... <node-test> . <handler>)
33 <node-test> ::= an argument to node-typeof? above
34 <handler> ::= <tree> -> <new-tree>
35 @end smallexample
36
37 This procedure does a @emph{normal}, pre-order traversal of an SXML
38 tree. It walks the tree, checking at each node against the list of
39 matching templates.
40
41 If the match is found (which must be unique, i.e., unambiguous), the
42 corresponding handler is invoked and given the current node as an
43 argument. The result from the handler, which must be a @code{<tree>},
44 takes place of the current node in the resulting tree. The name of the
45 function is not accidental: it resembles rather closely an
46 @code{apply-templates} function of XSLT.
47
48 @subsubsection Usage
49 @anchor{sxml apply-templates apply-templates}@defun apply-templates tree templates
50 @end defun
51
52 @node sxml fold
53 @subsection (sxml fold)
54 @subsubsection Overview
55 @code{(sxml fold)} defines a number of variants of the @dfn{fold}
56 algorithm for use in transforming SXML trees. Additionally it defines
57 the layout operator, @code{fold-layout}, which might be described as a
58 context-passing variant of SSAX's @code{pre-post-order}.
59
60 @subsubsection Usage
61 @anchor{sxml fold foldt}@defun foldt fup fhere tree
62 The standard multithreaded tree fold.
63
64 @var{fup} is of type [a] -> a. @var{fhere} is of type object -> a.
65
66 @end defun
67
68 @anchor{sxml fold foldts}@defun foldts fdown fup fhere seed tree
69 The single-threaded tree fold originally defined in SSAX. @xref{sxml
70 ssax,,(sxml ssax)}, for more information.
71
72 @end defun
73
74 @anchor{sxml fold foldts*}@defun foldts* fdown fup fhere seed tree
75 A variant of @ref{sxml fold foldts,,foldts} that allows pre-order tree
76 rewrites. Originally defined in Andy Wingo's 2007 paper,
77 @emph{Applications of fold to XML transformation}.
78
79 @end defun
80
81 @anchor{sxml fold fold-values}@defun fold-values proc list . seeds
82 A variant of @ref{SRFI-1 Fold and Map,fold} that allows multi-valued
83 seeds. Note that the order of the arguments differs from that of
84 @code{fold}.
85
86 @end defun
87
88 @anchor{sxml fold foldts*-values}@defun foldts*-values fdown fup fhere tree . seeds
89 A variant of @ref{sxml fold foldts*,,foldts*} that allows multi-valued
90 seeds. Originally defined in Andy Wingo's 2007 paper, @emph{Applications
91 of fold to XML transformation}.
92
93 @end defun
94
95 @anchor{sxml fold fold-layout}@defun fold-layout tree bindings params layout stylesheet
96 A traversal combinator in the spirit of SSAX's @ref{sxml transform
97 pre-post-order,,pre-post-order}.
98
99 @code{fold-layout} was originally presented in Andy Wingo's 2007 paper,
100 @emph{Applications of fold to XML transformation}.
101
102 @example
103 bindings := (<binding>...)
104 binding := (<tag> <bandler-pair>...)
105 | (*default* . <post-handler>)
106 | (*text* . <text-handler>)
107 tag := <symbol>
108 handler-pair := (pre-layout . <pre-layout-handler>)
109 | (post . <post-handler>)
110 | (bindings . <bindings>)
111 | (pre . <pre-handler>)
112 | (macro . <macro-handler>)
113 @end example
114
115 @table @var
116 @item pre-layout-handler
117 A function of three arguments:
118
119 @table @var
120 @item kids
121 the kids of the current node, before traversal
122
123 @item params
124 the params of the current node
125
126 @item layout
127 the layout coming into this node
128
129 @end table
130
131 @var{pre-layout-handler} is expected to use this information to return a
132 layout to pass to the kids. The default implementation returns the
133 layout given in the arguments.
134
135 @item post-handler
136 A function of five arguments:
137
138 @table @var
139 @item tag
140 the current tag being processed
141
142 @item params
143 the params of the current node
144
145 @item layout
146 the layout coming into the current node, before any kids were processed
147
148 @item klayout
149 the layout after processing all of the children
150
151 @item kids
152 the already-processed child nodes
153
154 @end table
155
156 @var{post-handler} should return two values, the layout to pass to the
157 next node and the final tree.
158
159 @item text-handler
160 @var{text-handler} is a function of three arguments:
161
162 @table @var
163 @item text
164 the string
165
166 @item params
167 the current params
168
169 @item layout
170 the current layout
171
172 @end table
173
174 @var{text-handler} should return two values, the layout to pass to the
175 next node and the value to which the string should transform.
176
177 @end table
178
179 @end defun
180
181 @node sxml simple
182 @subsection (sxml simple)
183 @subsubsection Overview
184 A simple interface to XML parsing and serialization.
185
186 @subsubsection Usage
187 @anchor{sxml simple xml->sxml}@defun xml->sxml [port]
188 Use SSAX to parse an XML document into SXML. Takes one optional
189 argument, @var{port}, which defaults to the current input port.
190
191 @end defun
192
193 @anchor{sxml simple sxml->xml}@defun sxml->xml tree [port]
194 Serialize the sxml tree @var{tree} as XML. The output will be written to
195 the current output port, unless the optional argument @var{port} is
196 present.
197
198 @end defun
199
200 @anchor{sxml simple sxml->string}@defun sxml->string sxml
201 Detag an sxml tree @var{sxml} into a string. Does not perform any
202 formatting.
203
204 @end defun
205
206 @node sxml ssax
207 @subsection (sxml ssax)
208 @subsubsection Overview
209 @subheading Functional XML parsing framework
210 @subsubheading SAX/DOM and SXML parsers with support for XML Namespaces and validation
211 This is a package of low-to-high level lexing and parsing procedures
212 that can be combined to yield a SAX, a DOM, a validating parser, or a
213 parser intended for a particular document type. The procedures in the
214 package can be used separately to tokenize or parse various pieces of
215 XML documents. The package supports XML Namespaces, internal and
216 external parsed entities, user-controlled handling of whitespace, and
217 validation. This module therefore is intended to be a framework, a set
218 of "Lego blocks" you can use to build a parser following any discipline
219 and performing validation to any degree. As an example of the parser
220 construction, this file includes a semi-validating SXML parser.
221
222 The present XML framework has a "sequential" feel of SAX yet a
223 "functional style" of DOM. Like a SAX parser, the framework scans the
224 document only once and permits incremental processing. An application
225 that handles document elements in order can run as efficiently as
226 possible. @emph{Unlike} a SAX parser, the framework does not require an
227 application register stateful callbacks and surrender control to the
228 parser. Rather, it is the application that can drive the framework --
229 calling its functions to get the current lexical or syntax element.
230 These functions do not maintain or mutate any state save the input port.
231 Therefore, the framework permits parsing of XML in a pure functional
232 style, with the input port being a monad (or a linear, read-once
233 parameter).
234
235 Besides the @var{port}, there is another monad -- @var{seed}. Most of
236 the middle- and high-level parsers are single-threaded through the
237 @var{seed}. The functions of this framework do not process or affect the
238 @var{seed} in any way: they simply pass it around as an instance of an
239 opaque datatype. User functions, on the other hand, can use the seed to
240 maintain user's state, to accumulate parsing results, etc. A user can
241 freely mix his own functions with those of the framework. On the other
242 hand, the user may wish to instantiate a high-level parser:
243 @code{SSAX:make-elem-parser} or @code{SSAX:make-parser}. In the latter
244 case, the user must provide functions of specific signatures, which are
245 called at predictable moments during the parsing: to handle character
246 data, element data, or processing instructions (PI). The functions are
247 always given the @var{seed}, among other parameters, and must return the
248 new @var{seed}.
249
250 From a functional point of view, XML parsing is a combined
251 pre-post-order traversal of a "tree" that is the XML document itself.
252 This down-and-up traversal tells the user about an element when its
253 start tag is encountered. The user is notified about the element once
254 more, after all element's children have been handled. The process of XML
255 parsing therefore is a fold over the raw XML document. Unlike a fold
256 over trees defined in [1], the parser is necessarily single-threaded --
257 obviously as elements in a text XML document are laid down sequentially.
258 The parser therefore is a tree fold that has been transformed to accept
259 an accumulating parameter [1,2].
260
261 Formally, the denotational semantics of the parser can be expressed as
262
263 @smallexample
264 parser:: (Start-tag -> Seed -> Seed) ->
265 (Start-tag -> Seed -> Seed -> Seed) ->
266 (Char-Data -> Seed -> Seed) ->
267 XML-text-fragment -> Seed -> Seed
268 parser fdown fup fchar "<elem attrs> content </elem>" seed
269 = fup "<elem attrs>" seed
270 (parser fdown fup fchar "content" (fdown "<elem attrs>" seed))
271
272 parser fdown fup fchar "char-data content" seed
273 = parser fdown fup fchar "content" (fchar "char-data" seed)
274
275 parser fdown fup fchar "elem-content content" seed
276 = parser fdown fup fchar "content" (
277 parser fdown fup fchar "elem-content" seed)
278 @end smallexample
279
280 Compare the last two equations with the left fold
281
282 @smallexample
283 fold-left kons elem:list seed = fold-left kons list (kons elem seed)
284 @end smallexample
285
286 The real parser created by @code{SSAX:make-parser} is slightly more
287 complicated, to account for processing instructions, entity references,
288 namespaces, processing of document type declaration, etc.
289
290 The XML standard document referred to in this module
291 is@uref{http://www.w3.org/TR/1998/REC-xml-19980210.html}
292
293 The present file also defines a procedure that parses the text of an XML
294 document or of a separate element into SXML, an S-expression-based model
295 of an XML Information Set. SXML is also an Abstract Syntax Tree of an
296 XML document. SXML is similar but not identical to DOM; SXML is
297 particularly suitable for Scheme-based XML/HTML authoring, SXPath
298 queries, and tree transformations. See SXML.html for more details. SXML
299 is a term implementation of evaluation of the XML document [3]. The
300 other implementation is context-passing.
301
302 The present frameworks fully supports the XML Namespaces
303 Recommendation:@uref{http://www.w3.org/TR/REC-xml-names/} Other links:
304
305 @table @asis
306 @item [1]
307 Jeremy Gibbons, Geraint Jones, "The Under-appreciated Unfold," Proc.
308 ICFP'98, 1998, pp. 273-279.
309
310 @item [2]
311 Richard S. Bird, The promotion and accumulation strategies in
312 transformational programming, ACM Trans. Progr. Lang. Systems,
313 6(4):487-504, October 1984.
314
315 @item [3]
316 Ralf Hinze, "Deriving Backtracking Monad Transformers," Functional
317 Pearl. Proc ICFP'00, pp. 186-197.
318
319 @end table
320
321 @subsubsection Usage
322 @anchor{sxml ssax current-ssax-error-port}@defun current-ssax-error-port
323 @end defun
324
325 @anchor{sxml ssax with-ssax-error-to-port}@defun with-ssax-error-to-port port thunk
326 @end defun
327
328 @anchor{sxml ssax xml-token?}@defun xml-token? _
329 @verbatim
330 -- Scheme Procedure: pair? x
331 Return `#t' if X is a pair; otherwise return `#f'.
332
333
334 @end verbatim
335
336 @end defun
337
338 @anchor{sxml ssax xml-token-kind}@defspec xml-token-kind token
339 @end defspec
340
341 @anchor{sxml ssax xml-token-head}@defspec xml-token-head token
342 @end defspec
343
344 @anchor{sxml ssax make-empty-attlist}@defun make-empty-attlist
345 @end defun
346
347 @anchor{sxml ssax attlist-add}@defun attlist-add attlist name-value
348 @end defun
349
350 @anchor{sxml ssax attlist-null?}@defun attlist-null? _
351 @verbatim
352 -- Scheme Procedure: null? x
353 Return `#t' iff X is the empty list, else `#f'.
354
355
356 @end verbatim
357
358 @end defun
359
360 @anchor{sxml ssax attlist-remove-top}@defun attlist-remove-top attlist
361 @end defun
362
363 @anchor{sxml ssax attlist->alist}@defun attlist->alist attlist
364 @end defun
365
366 @anchor{sxml ssax attlist-fold}@defun attlist-fold kons knil lis1
367 @end defun
368
369 @anchor{sxml ssax define-parsed-entity!}@defun define-parsed-entity! entity str
370 Define a new parsed entity. @var{entity} should be a symbol.
371
372 Instances of &@var{entity}; in XML text will be replaced with the string
373 @var{str}, which will then be parsed.
374
375 @end defun
376
377 @anchor{sxml ssax reset-parsed-entity-definitions!}@defun reset-parsed-entity-definitions!
378 Restore the set of parsed entity definitions to its initial state.
379
380 @end defun
381
382 @anchor{sxml ssax ssax:uri-string->symbol}@defun ssax:uri-string->symbol uri-str
383 @end defun
384
385 @anchor{sxml ssax ssax:skip-internal-dtd}@defun ssax:skip-internal-dtd port
386 @end defun
387
388 @anchor{sxml ssax ssax:read-pi-body-as-string}@defun ssax:read-pi-body-as-string port
389 @end defun
390
391 @anchor{sxml ssax ssax:reverse-collect-str-drop-ws}@defun ssax:reverse-collect-str-drop-ws fragments
392 @end defun
393
394 @anchor{sxml ssax ssax:read-markup-token}@defun ssax:read-markup-token port
395 @end defun
396
397 @anchor{sxml ssax ssax:read-cdata-body}@defun ssax:read-cdata-body port str-handler seed
398 @end defun
399
400 @anchor{sxml ssax ssax:read-char-ref}@defun ssax:read-char-ref port
401 @end defun
402
403 @anchor{sxml ssax ssax:read-attributes}@defun ssax:read-attributes port entities
404 @end defun
405
406 @anchor{sxml ssax ssax:complete-start-tag}@defun ssax:complete-start-tag tag-head port elems entities namespaces
407 @end defun
408
409 @anchor{sxml ssax ssax:read-external-id}@defun ssax:read-external-id port
410 @end defun
411
412 @anchor{sxml ssax ssax:read-char-data}@defun ssax:read-char-data port expect-eof? str-handler seed
413 @end defun
414
415 @anchor{sxml ssax ssax:xml->sxml}@defun ssax:xml->sxml port namespace-prefix-assig
416 @end defun
417
418 @anchor{sxml ssax ssax:make-parser}@defspec ssax:make-parser . kw-val-pairs
419 @end defspec
420
421 @anchor{sxml ssax ssax:make-pi-parser}@defspec ssax:make-pi-parser orig-handlers
422 @end defspec
423
424 @anchor{sxml ssax ssax:make-elem-parser}@defspec ssax:make-elem-parser my-new-level-seed my-finish-element my-char-data-handler my-pi-handlers
425 @end defspec
426
427 @node sxml ssax input-parse
428 @subsection (sxml ssax input-parse)
429 @subsubsection Overview
430 A simple lexer.
431
432 The procedures in this module surprisingly often suffice to parse an
433 input stream. They either skip, or build and return tokens, according to
434 inclusion or delimiting semantics. The list of characters to expect,
435 include, or to break at may vary from one invocation of a function to
436 another. This allows the functions to easily parse even
437 context-sensitive languages.
438
439 EOF is generally frowned on, and thrown up upon if encountered.
440 Exceptions are mentioned specifically. The list of expected characters
441 (characters to skip until, or break-characters) may include an EOF
442 "character", which is to be coded as the symbol, @code{*eof*}.
443
444 The input stream to parse is specified as a @dfn{port}, which is usually
445 the last (and optional) argument. It defaults to the current input port
446 if omitted.
447
448 If the parser encounters an error, it will throw an exception to the key
449 @code{parser-error}. The arguments will be of the form @code{(@var{port}
450 @var{message} @var{specialising-msg}*)}.
451
452 The first argument is a port, which typically points to the offending
453 character or its neighborhood. You can then use @code{port-column} and
454 @code{port-line} to query the current position. @var{message} is the
455 description of the error. Other arguments supply more details about the
456 problem.
457
458 @subsubsection Usage
459 @anchor{sxml ssax input-parse peek-next-char}@defun peek-next-char [port]
460 @end defun
461
462 @anchor{sxml ssax input-parse assert-curr-char}@defun assert-curr-char expected-chars comment [port]
463 @end defun
464
465 @anchor{sxml ssax input-parse skip-until}@defun skip-until arg [port]
466 @end defun
467
468 @anchor{sxml ssax input-parse skip-while}@defun skip-while skip-chars [port]
469 @end defun
470
471 @anchor{sxml ssax input-parse next-token}@defun next-token prefix-skipped-chars break-chars [comment] [port]
472 @end defun
473
474 @anchor{sxml ssax input-parse next-token-of}@defun next-token-of incl-list/pred [port]
475 @end defun
476
477 @anchor{sxml ssax input-parse read-text-line}@defun read-text-line [port]
478 @end defun
479
480 @anchor{sxml ssax input-parse read-string}@defun read-string n [port]
481 @end defun
482
483 @anchor{sxml ssax input-parse find-string-from-port?}@defun find-string-from-port? _ _ . _
484 Looks for @var{str} in @var{<input-port>}, optionally within the first
485 @var{max-no-char} characters.
486
487 @end defun
488
489 @node sxml transform
490 @subsection (sxml transform)
491 @subsubsection Overview
492 @heading SXML expression tree transformers
493 @subheading Pre-Post-order traversal of a tree and creation of a new tree
494 @smallexample
495 pre-post-order:: <tree> x <bindings> -> <new-tree>
496 @end smallexample
497
498 where
499
500 @smallexample
501 <bindings> ::= (<binding> ...)
502 <binding> ::= (<trigger-symbol> *preorder* . <handler>) |
503 (<trigger-symbol> *macro* . <handler>) |
504 (<trigger-symbol> <new-bindings> . <handler>) |
505 (<trigger-symbol> . <handler>)
506 <trigger-symbol> ::= XMLname | *text* | *default*
507 <handler> :: <trigger-symbol> x [<tree>] -> <new-tree>
508 @end smallexample
509
510 The pre-post-order function visits the nodes and nodelists
511 pre-post-order (depth-first). For each @code{<Node>} of the form
512 @code{(@var{name} <Node> ...)}, it looks up an association with the
513 given @var{name} among its @var{<bindings>}. If failed,
514 @code{pre-post-order} tries to locate a @code{*default*} binding. It's
515 an error if the latter attempt fails as well. Having found a binding,
516 the @code{pre-post-order} function first checks to see if the binding is
517 of the form
518
519 @smallexample
520 (<trigger-symbol> *preorder* . <handler>)
521 @end smallexample
522
523 If it is, the handler is 'applied' to the current node. Otherwise, the
524 pre-post-order function first calls itself recursively for each child of
525 the current node, with @var{<new-bindings>} prepended to the
526 @var{<bindings>} in effect. The result of these calls is passed to the
527 @var{<handler>} (along with the head of the current @var{<Node>}). To be
528 more precise, the handler is _applied_ to the head of the current node
529 and its processed children. The result of the handler, which should also
530 be a @code{<tree>}, replaces the current @var{<Node>}. If the current
531 @var{<Node>} is a text string or other atom, a special binding with a
532 symbol @code{*text*} is looked up.
533
534 A binding can also be of a form
535
536 @smallexample
537 (<trigger-symbol> *macro* . <handler>)
538 @end smallexample
539
540 This is equivalent to @code{*preorder*} described above. However, the
541 result is re-processed again, with the current stylesheet.
542
543 @subsubsection Usage
544 @anchor{sxml transform SRV:send-reply}@defun SRV:send-reply . fragments
545 Output the @var{fragments} to the current output port.
546
547 The fragments are a list of strings, characters, numbers, thunks,
548 @code{#f}, @code{#t} -- and other fragments. The function traverses the
549 tree depth-first, writes out strings and characters, executes thunks,
550 and ignores @code{#f} and @code{'()}. The function returns @code{#t} if
551 anything was written at all; otherwise the result is @code{#f} If
552 @code{#t} occurs among the fragments, it is not written out but causes
553 the result of @code{SRV:send-reply} to be @code{#t}.
554
555 @end defun
556
557 @anchor{sxml transform foldts}@defun foldts fdown fup fhere seed tree
558 @end defun
559
560 @anchor{sxml transform post-order}@defun post-order tree bindings
561 @end defun
562
563 @anchor{sxml transform pre-post-order}@defun pre-post-order tree bindings
564 @end defun
565
566 @anchor{sxml transform replace-range}@defun replace-range beg-pred end-pred forest
567 @end defun
568
569 @node sxml xpath
570 @subsection (sxml xpath)
571 @subsubsection Overview
572 @heading SXPath: SXML Query Language
573 SXPath is a query language for SXML, an instance of XML Information set
574 (Infoset) in the form of s-expressions. See @code{(sxml ssax)} for the
575 definition of SXML and more details. SXPath is also a translation into
576 Scheme of an XML Path Language, @uref{http://www.w3.org/TR/xpath,XPath}.
577 XPath and SXPath describe means of selecting a set of Infoset's items or
578 their properties.
579
580 To facilitate queries, XPath maps the XML Infoset into an explicit tree,
581 and introduces important notions of a location path and a current,
582 context node. A location path denotes a selection of a set of nodes
583 relative to a context node. Any XPath tree has a distinguished, root
584 node -- which serves as the context node for absolute location paths.
585 Location path is recursively defined as a location step joined with a
586 location path. A location step is a simple query of the database
587 relative to a context node. A step may include expressions that further
588 filter the selected set. Each node in the resulting set is used as a
589 context node for the adjoining location path. The result of the step is
590 a union of the sets returned by the latter location paths.
591
592 The SXML representation of the XML Infoset (see SSAX.scm) is rather
593 suitable for querying as it is. Bowing to the XPath specification, we
594 will refer to SXML information items as 'Nodes':
595
596 @example
597 <Node> ::= <Element> | <attributes-coll> | <attrib>
598 | "text string" | <PI>
599 @end example
600
601 This production can also be described as
602
603 @example
604 <Node> ::= (name . <Nodeset>) | "text string"
605 @end example
606
607 An (ordered) set of nodes is just a list of the constituent nodes:
608
609 @example
610 <Nodeset> ::= (<Node> ...)
611 @end example
612
613 Nodesets, and Nodes other than text strings are both lists. A <Nodeset>
614 however is either an empty list, or a list whose head is not a symbol. A
615 symbol at the head of a node is either an XML name (in which case it's a
616 tag of an XML element), or an administrative name such as '@@'. This
617 uniform list representation makes processing rather simple and elegant,
618 while avoiding confusion. The multi-branch tree structure formed by the
619 mutually-recursive datatypes <Node> and <Nodeset> lends itself well to
620 processing by functional languages.
621
622 A location path is in fact a composite query over an XPath tree or its
623 branch. A singe step is a combination of a projection, selection or a
624 transitive closure. Multiple steps are combined via join and union
625 operations. This insight allows us to @emph{elegantly} implement XPath
626 as a sequence of projection and filtering primitives -- converters --
627 joined by @dfn{combinators}. Each converter takes a node and returns a
628 nodeset which is the result of the corresponding query relative to that
629 node. A converter can also be called on a set of nodes. In that case it
630 returns a union of the corresponding queries over each node in the set.
631 The union is easily implemented as a list append operation as all nodes
632 in a SXML tree are considered distinct, by XPath conventions. We also
633 preserve the order of the members in the union. Query combinators are
634 high-order functions: they take converter(s) (which is a Node|Nodeset ->
635 Nodeset function) and compose or otherwise combine them. We will be
636 concerned with only relative location paths [XPath]: an absolute
637 location path is a relative path applied to the root node.
638
639 Similarly to XPath, SXPath defines full and abbreviated notations for
640 location paths. In both cases, the abbreviated notation can be
641 mechanically expanded into the full form by simple rewriting rules. In
642 case of SXPath the corresponding rules are given as comments to a sxpath
643 function, below. The regression test suite at the end of this file shows
644 a representative sample of SXPaths in both notations, juxtaposed with
645 the corresponding XPath expressions. Most of the samples are borrowed
646 literally from the XPath specification, while the others are adjusted
647 for our running example, tree1.
648
649 @subsubsection Usage
650 @anchor{sxml xpath nodeset?}@defun nodeset? x
651 @end defun
652
653 @anchor{sxml xpath node-typeof?}@defun node-typeof? crit
654 @end defun
655
656 @anchor{sxml xpath node-eq?}@defun node-eq? other
657 @end defun
658
659 @anchor{sxml xpath node-equal?}@defun node-equal? other
660 @end defun
661
662 @anchor{sxml xpath node-pos}@defun node-pos n
663 @end defun
664
665 @anchor{sxml xpath filter}@defun filter pred?
666 @verbatim
667 -- Scheme Procedure: filter pred list
668 Return all the elements of 2nd arg LIST that satisfy predicate
669 PRED. The list is not disordered - elements that appear in the
670 result list occur in the same order as they occur in the argument
671 list. The returned list may share a common tail with the argument
672 list. The dynamic order in which the various applications of pred
673 are made is not specified.
674
675 (filter even? '(0 7 8 8 43 -4)) => (0 8 8 -4)
676
677
678 @end verbatim
679
680 @end defun
681
682 @anchor{sxml xpath take-until}@defun take-until pred?
683 @end defun
684
685 @anchor{sxml xpath take-after}@defun take-after pred?
686 @end defun
687
688 @anchor{sxml xpath map-union}@defun map-union proc lst
689 @end defun
690
691 @anchor{sxml xpath node-reverse}@defun node-reverse node-or-nodeset
692 @end defun
693
694 @anchor{sxml xpath node-trace}@defun node-trace title
695 @end defun
696
697 @anchor{sxml xpath select-kids}@defun select-kids test-pred?
698 @end defun
699
700 @anchor{sxml xpath node-self}@defun node-self pred?
701 @verbatim
702 -- Scheme Procedure: filter pred list
703 Return all the elements of 2nd arg LIST that satisfy predicate
704 PRED. The list is not disordered - elements that appear in the
705 result list occur in the same order as they occur in the argument
706 list. The returned list may share a common tail with the argument
707 list. The dynamic order in which the various applications of pred
708 are made is not specified.
709
710 (filter even? '(0 7 8 8 43 -4)) => (0 8 8 -4)
711
712
713 @end verbatim
714
715 @end defun
716
717 @anchor{sxml xpath node-join}@defun node-join . selectors
718 @end defun
719
720 @anchor{sxml xpath node-reduce}@defun node-reduce . converters
721 @end defun
722
723 @anchor{sxml xpath node-or}@defun node-or . converters
724 @end defun
725
726 @anchor{sxml xpath node-closure}@defun node-closure test-pred?
727 @end defun
728
729 @anchor{sxml xpath node-parent}@defun node-parent rootnode
730 @end defun
731
732 @anchor{sxml xpath sxpath}@defun sxpath path
733 @end defun