Re: transformin CALS tables

Subject: Re: transformin CALS tables
From: Paul Tyson <ptyso@xxxxxxxxxxxxx>
Date: Mon, 27 Mar 2000 22:27:02 -0600
You can get rid of the explicit loop by using map-constructor:

(element entry
         (let ((current-class 
                (attribute-string "class" (parent (current-node))))
               (entry-nbr (child-number (current-node))))
           (make element 
                 gi: "entry"
                 (sosofo-append
                  (process-children-trim)
                  (let ((appended-entry-nl (node-list-filter
                                (lambda (snl)
                                  (equal? 
                                   (child-number snl) 
                                   entry-nbr))
                                (select-elements
                                 (children
                                  (follow (parent (current-node))))
                                 (list
                                  "row"
                                  (list "class" current-class)
                                  "entry")))))
                    (map-constructor (lambda ()
                                       (sosofo-append
                                        (literal " ")
                                        (process-node-list
                                         (children (current-node)))))
                                     appended-entry-nl))))))

 -pt

Paul Tyson wrote:
> 
> Hi Jany,
> 
> I don't know what your idea of "simple & efficient" is, but here's a set
> of rules that processes your sample data as specified:
> 
> (element row
>         (let ((current-class (attribute-string "class")))
>                (if (node-list-empty? (select-elements
>                                      (preced (current-node))
>                                       (list
>                                         "row"
>                                         (list "class" current-class))))
>                (make element
>                      gi: "row"
>                 ; if other attributes are expected, change this
>                 ; to use generic identity transformation
>                 ; for attribute lists
>                      attributes: (list (list "class" current-class))
>                      (process-children))
>                 ; don't process row if class attribute value
>                 ; has already appeared
>                (empty-sosofo))))
> 
> (element entry
>          (let ((current-class
>                 (attribute-string "class" (parent (current-node))))
>                (entry-nbr (child-number (current-node))))
>            (make element
>                  gi: "entry"
>                  (sosofo-append
>                   (process-children-trim)
>                   (let loop ((to-do (node-list-filter
>                                       (lambda (snl)
>                                         (equal?
>                                          (child-number snl)
>                                          entry-nbr))
>                                       (select-elements
>                                        (children
>                                         (follow (parent
> (current-node))))
>                                        (list
>                                         "row"
>                                         (list "class" current-class)
>                                         "entry")))))
>                     (if (node-list-empty? to-do)
>                         (empty-sosofo)
>                         (sosofo-append
>                          (literal " ")
>                          (process-node-list
>                                 (children (node-list-first to-do)))
>                          (loop (node-list-rest to-do)))))))))
> 
> (element tbody
>          (make element gi: "tbody"
>                (process-children)))
> 
> It might "look" a little simpler if you defined the to-do list and class
> occurrence test as separate procedures, but I think it's got to do the
> same thing no matter how you write it.
> 
> As far as general guidelines: of course anything in the grove can be
> processed from any particular construction rule, so the biggest problem
> is avoiding duplicate processing by virtue of the default construction
> rules.  In this case, just putting the "if" clause in the row element
> construction rule prevents rows from being processed if the class
> attribute value has been encountered previously.  In other cases it's
> easier to use modes.
> 
> As long as you're not looping or selecting over large chunks of data,
> this approach seems to work pretty well.
> 
> Hope this helps.
> 
> Paul Tyson
> 
> 
> Jany Quintard wrote:
> >
> > Hi all.
> >
> > I have a problem of SGML to SGML transformation. The element to transform
> > are table (derived from cals tables).
> > The input SGML is badly generated and I want to correct this with a dsssl
> > stylesheet. My purpose is to merge the rows that have same class
> > attribute.
> > The use of class attribute is not mandatory, but it seeme a mean to
> > mark the rows that are actually parts of the same row.
> >
> > Suppose I have a table part like this :
> > <tbody>
> >   <row class="01">
> >     <entry>1 of 01</entry>
> >     <entry>2 of 01</entry>
> >     <entry>3 of 01</entry>
> >   </row>
> >
> >   <row class="01">
> >     <entry>following of 01-1</entry>
> >     <entry>following of 01-2</entry>
> >     <entry>following of 01-3</entry>
> >   </row>
> >
> >   <row class="02">
> >     <entry>1 of 02</entry>
> >     <entry>2 of 02</entry>
> >     <entry>3 of 02</entry>
> >   </row>
> > </tbody>
> >
> > I want to
> >
> > What I want is :
> > <tbody>
> >   <row class="01">
> >     <entry>1 of 01 following of 01-1</entry>
> >     <entry>2 of 01 following of 01-2</entry>
> >     <entry>3 of 01 following of 01-3</entry>
> >   </row>
> >
> >   <row class="02">
> >     <entry>1 of 02</entry>
> >     <entry>2 of 02</entry>
> >     <entry>3 of 02</entry>
> >   </row>
> > </tbody>
> >
> > I am trying to build a stylesheet to obtain this result. The problem
> > is that my code  seems awfully complicated (select-elements, loops and so
> > on) and I am not even sure that it will work.
> >
> > Does anyone have some guidelines to process this in a simple (and
> > efficient) way ?
> >
> > TIA. Jany.
> >
> >  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
> 
>  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


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


Current Thread