Re: conditionaly setting characteristics

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))
        (string-number colnum))

(define (mapalign align)
  (if (string? align)
    (case (STRING-DOWNCASE align)
          (("start") 'start)
          (("end") 'end)
          (("center") 'center)
          (("centre") 'center)
          (else '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

 DSSSList info and archive:

Current Thread
  • conditionaly setting characteristics
    • Charlie & Barbara Bozeman - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id OAA06929Sat, 21 Feb 1998 14:05:26 -0500 (EST)
      • Lassi A. Tuura - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id HAA21007Sun, 22 Feb 1998 07:35:04 -0500 (EST)
      • Richard Light - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id FAA15131Mon, 23 Feb 1998 05:41:42 -0500 (EST) <=
        • Chris Maden - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id NAA12108Tue, 24 Feb 1998 13:31:12 -0500 (EST)
      • <Possible follow-ups>
      • W. Eliot Kimber - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id OAA07168Sat, 21 Feb 1998 14:21:46 -0500 (EST)