|
Subject: Re: breaking a string at record ends From: Brandon Ibach <bibach@xxxxxxxxxxxxxx> Date: Thu, 7 Sep 2000 10:05:52 -0500 |
Quoting Jany Quintard <quintard.j@xxxxxx>:
> So I process the contents of xmp with a function :
> (define (output-xmp liste)
> (let loop ((chars liste)
> (result (empty-sosofo)))
> (if (null? chars)
> result
> (loop (cdr chars)
> (sosofo-append
> result
> (if (char-property 'record-end? (car chars))
> (make empty-element gi: "br")
> (literal (string (car chars)))))))))
>
> This works, but I am none too proud of it.
> The "(literal (string (car chars)))" seems *very* complicated
> and I wonder if there is not a better way to do it (using (make character)
> maybe ?).
>
Well, yes, you should be able to replace the (literal ...) with
(make character char: (car chars)). Or, you could take a different
approach to the whole function and just have it return a modified
node-list. So, instead of:
(element XMP (output-xmp (string->list (data (current-node)))))
you'd have:
(element XMP (process-node-list (filter-xmp (children (current-node)))))
(define (filter-xmp liste)
(let ((br (node-list-first (select-elements
(descendants (current-root)) "BR"))))
(let loop ((chars liste)
(result (empty-sosofo)))
(if (node-list-empty? chars)
result
(loop (node-list-rest chars)
(node-list
result
(let ((c (node-list-first chars)))
(if (char-property 'record-end? c) br c))))))))
Of course, this assumes that you've got a <br> element somewhere in
your source document that we can copy into our output node-list,
because DSSSL provides no way to "construct" such a node. If this is
not the case, this function will break. You could do something as
elaborate as parsing an extra document which has a <br> in it (and,
perhaps, little more), if needed, but that would tend to defeat the
simplicity gained by this approach.
-Brandon :)
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| breaking a string at record ends, Jany Quintard | Thread | Re: breaking a string at record end, Jany Quintard |
| breaking a string at record ends, Jany Quintard | Date | Re: breaking a string at record end, Jany Quintard |
| Month |