|
Subject: Re: Emulation of XSL's id() in DSSSL? From: Norman Walsh <ndw@xxxxxxxxxx> Date: Fri, 25 Feb 2000 10:56:19 -0500 |
/ Ralf Kempkens <kempkens@xxxxxxxxxxx> was heard to say:
| Thank you Norman, but you haven't got my point;
Oops. Right you are. Sorry about that.
| That's just the problem. I want to support multiple
| references. So I need a scheme function that breaks up a
| string into a list, using space as separator. But my Scheme
| knowledge doesn't go that far.
This is from dblib.dsl:
(define (split str #!optional (whitespace '(#\space)))
;; REFENTRY split
;; PURP Splits string at whitespace and returns the resulting list of tokens
;; DESC
;; Given a string containing delimited tokens, return a list
;; of the tokens in string form.
;; ARGS
;; ARG 'str'
;; The string to split.
;; /ARG
;; ARG 'whitespace' o
;; A list of characters that should
;; be treated as whitespace.
;; /ARG
;; /ARGS
;; /DESC
;; AUTHOR David Megginson
;; EMAIL dmeggins@xxxxxxxxxx
;; /REFENTRY
(let loop ((characters (string->list str)) ; Top-level recursive loop.
(current-word '())
(tokens '()))
; If there are no characters left,
; then we're done!
(cond ((null? characters)
; Is there a token in progress?
(if (null? current-word)
(reverse tokens)
(reverse (cons (list->string (reverse current-word))
tokens))))
; If there are characters left,
; then keep going.
(#t
(let ((c (car characters))
(rest (cdr characters)))
; Are we reading a space?
(cond ((member c whitespace)
(if (null? current-word)
(loop rest '() tokens)
(loop rest
'()
(cons (list->string (reverse current-word))
tokens))))
; We are reading a non-space
(#t
(loop rest (cons c current-word) tokens))))))))
Having split the string into a list of tokens, you now want to build
a nodelist of the targets, so something like this ought to work (totally
untested...)
(let loop ((idstrlist (split (attribute-string "references")))
(targets (empty-node-list)))
(if (null? idstrlist)
targets
(loop (cdr idstrlist)
(nodelist targets (element-with-id (car idstrlist))))))
Be seeing you,
norm
--
Norman Walsh <ndw@xxxxxxxxxx> | In a universe of electrons and
http://nwalsh.com/ | selfish genes, blind physical
| forces and genetic replication,
| some people are going to get hurt,
| other people are going to get
| lucky, and you won't find any
| rhyme or reason in it, nor any
| justice.--Richard Dawkins
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: Emulation of XSL's id() in DSSS, Ralf Kempkens | Thread | Re: Emulation of XSL's id() in DSSS, Ralf Kempkens |
| RE: Counting Nodes, Maltby, David G | Date | Re: Emulation of XSL's id() in DSSS, Toby Speight |
| Month |