|
Subject: Re: conditionaly setting characteristics From: Richard Light <richard@xxxxxxxxxxxxxxxxx> Date: Mon, 23 Feb 1998 09:58:26 +0000 |
In message <34EF2511.526C39F8@xxxxxxxxxx>, Charlie & Barbara Bozeman
<cbozeman@xxxxxxxxxx> writes
>Is there a method to construct flow objects and conditionally set their
>characteristics depending on the value or presence of attributes? An
>example of what I want to do is:
>
>(element cell
> (let ((col-num attribute-string "col-num")
> (align attribute-string "align"))
> (make table-cell
> (if col-num
> column-number: col-num)
> (if align
> cell-row-alignment: align))))
In principle there is no problem doing this. You need to 'bracket'
attribute-string, since it is a procedure, and you need to take care
with the object it returns, which is #f if it fails to produce an
attribute value for any reason, and a string representation of that
value if it succeeds.
This can give rise to some strange logic - I don't think that you can
test for (attribute-string) returning #t as you do, since it only
returns #f or a string. You will see a similar case in the (mapcolnum)
procedure below, where I have tried to cope with the similar behaviour
of (string->number) by testing for the #f case:
(if (not (string->number colnum))
... #f returned, so give default value
... else number returned, so use it
Finally, since attribute-string returns a string literal, you need to
map this to a symbol or integer so it can be a valid characteristic
value. Write sub-procedures to check 'col-num' and 'align' and return a
suitable characteristic value:
(element cell
(make table-cell
column-number: (mapcolnum (attribute-string "col-num"))
cell-row-alignment: (mapalign (attribute-string "align"))))
(define (mapcolnum colnum)
(if (string? colnum)
(if (not (string->number colnum))
1
(string-number colnum))
1))
(define (mapalign align)
(if (string? align)
(case (STRING-DOWNCASE align)
(("start") 'start)
(("end") 'end)
(("center") 'center)
(("centre") 'center)
(else 'start))
'start))
[Note that I have chosen not to use (string->symbol) to convert the
attribute (string) values to symbols. Providing an explicit set of
options in a case statement lets you guard against invalid settings in
the instance which could give DSSSL processing errors. It also lets you
deal with reasonable variations, e.g. 'centre'.]
Richard Light.
Richard Light
SGML/XML and Museum Information Consultancy
richard@xxxxxxxxxxxxxxxxx
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: conditionaly setting characteri, Lassi A. Tuura | Thread | Re: conditionaly setting characteri, Chris Maden |
| Re: Java pretty printing in/with Do, Lassi A. Tuura | Date | Re: Java pretty printing in/with Do, Sean Mc Grath |
| Month |