algorithmics and dsssl

Subject: algorithmics and dsssl
From: Jany Quintard <quintard.j@xxxxxx>
Date: Wed, 9 Aug 2000 17:08:22 +0200 (CEST)
Hi all.
This is not really a question but...

As an old C C++ SmallTalk (and things even worse) programmer, I am
often puzzled by (sometimes very simple) problems I meet using dsssl
and impressed by the solutions given by some membrs of the group.

I let you imagine how much I can be puzzled by the thread 
"Preceding list function".
So, I am desperately trying to improve my "skills" in this domain.

Here is a (somewhat lengthy) example :
We want to build an RTF table from such an sgml file :
*********************
<!DOCTYPE Species
[
<!ELEMENT Species - - (SpeciesOrder, SpeciesFamily, SpeciesGenus,
SpeciesSpecies)+ >
<!ELEMENT SpeciesOrder - - (#PCDATA)>
<!ELEMENT SpeciesFamily - - (#PCDATA)>
<!ELEMENT SpeciesGenus - - (#PCDATA)>
<!ELEMENT SpeciesSpecies - - (#PCDATA)>
]
>

<Species>
<SpeciesOrder>Order 1</SpeciesOrder>
<SpeciesFamily>Family 1</SpeciesFamily>
<SpeciesGenus>Genus 1</SpeciesGenus>
<SpeciesSpecies>Species 1</SpeciesSpecies>

<SpeciesOrder>Order 2</SpeciesOrder>
<SpeciesFamily>Family 2</SpeciesFamily>
<SpeciesGenus>Genus 2</SpeciesGenus>
<SpeciesSpecies>Species 2</SpeciesSpecies>

<SpeciesOrder>Order 3</SpeciesOrder>
<SpeciesFamily>Family 3</SpeciesFamily>
<SpeciesGenus>Genus 3</SpeciesGenus>
<SpeciesSpecies>Species 3</SpeciesSpecies>

</Species>
 
*********************

The output should look like 

--------------------------------------------
|   Order |   Family |  Genus  |   Species |
--------------------------------------------
| order 1 | Family 1 | Genus 1 | Species 1 |
--------------------------------------------
| order 2 | Family 2 | Genus 2 | Species 2 |
--------------------------------------------
| order 3 | Family 3 | Genus 3 | Species 3 |
--------------------------------------------

And here is my solution :

*********************
<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN"
>

<style-specification>

;;  make a table with four columns
  (element Species
    (make table table-border: #t
      (make table-part content-map: '((head header)
                                      (body #f))
        (make sequence label: 'body
          (make table-column column-number: 1 width: 1in)
          (make table-column column-number: 2 width: 1in)
          (make table-column column-number: 3 width: 1in)
          (make table-column column-number: 4 width: 1in))
  
        (make sequence label: 'head
          (make table-row
            (makeHeaderCell 1 "Order")
            (makeHeaderCell 2 "Family")
            (makeHeaderCell 3 "Genus")
            (makeHeaderCell 4 "Species")))
  
; process the children of SpeciesSpecies
              (make sequence label: 'body
                (processSpecies (children (current-node)))))))

  (default (empty-sosofo))

; Function processing the first four elements
; and looping for the remains (let us hope the file is valid) 
(define (processSpecies nl)
  (let loop ((noeuds nl)
             (result (empty-sosofo)))

    (if (node-list-empty? noeuds)
        result
        (loop (node-list-tail noeuds 4)
              (sosofo-append
                result
                (make table-row

                  (makeCell (node-list-ref noeuds 0) 1)
                  (makeCell (node-list-ref noeuds 1) 2)
                  (makeCell (node-list-ref noeuds 2) 3)
                  (makeCell (node-list-ref noeuds 3) 4)))))))


(define (makeCell snl column-number)
  (make table-cell column-number: column-number
       cell-before-column-border: (make table-border line-thickness: 1pt)
        cell-after-column-border: (make table-border line-thickness: 1pt)
          cell-before-row-border: (make table-border line-thickness: 1pt)
           cell-after-row-border: (make table-border line-thickness: 1pt)
        (make paragraph quadding: 'start
          (literal (data snl)))))

(define (makeHeaderCell column-number text)
  (make table-cell column-number: column-number
       cell-before-column-border: (make table-border line-thickness: 1pt)
        cell-after-column-border: (make table-border line-thickness: 1pt)
          cell-before-row-border: (make table-border line-thickness: 1pt)
           cell-after-row-border: (make table-border line-thickness: 1pt)
    (make paragraph font-weight: 'bold
                       quadding: 'center
      (literal text))))

</style-specification>

*********************

So my questions are :

  - Do you see many other (better) solutions ?

  - Would it be better to use a mode to process the children of
  SpeciesSpecies, instead of a function ?

  - I could have grouped the two makeCell functions in one and use a test to
  output header or body.
  but this are mere variations.

  - More generally, is there a set of rules, examples, tutorials,
  exercises to learn building stylesheets "the right way" ?
  I do not believe there is any dsssl book.
  There are examples in the cookbook, Norman Walsh's stylesheets and the
  procedures, but I would like something more "school oriented" 

  - Or is the best solution to train with scheme tutorials ?
    (and read and try to understand posts on this list)

TIA. Jany.



 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread