Re: SGML transformation?

Subject: Re: SGML transformation?
From: "Mitch C. Amiano" <amiamc@xxxxxxxxxxxxxxx>
Date: Mon, 18 Jan 1999 14:20:24 -0500
Use the formatting-instruction procedure. This is a Jade extension.

Start by figuring out what SGML elements will trigger which
SQL statements. Then, match the elements using an element rule, 
and make a formatting-instruction to output the SQL. I'd typically 
use a (let) expression to put together the information for the transaction
before making the formatting-instruction.

Here's a modified snippet of code from a Jade style sheet. It should 
give you some ideas.
(%NEWLINE%) and (FORMAT-ARGLIST) are simple functions I wrote to make 
dealing with source-code output a bit easier. It converts some SGML 
which looks vaguely like the following into a snippet of JavaScript code.

<product title="myprod"><description>This is my product</description></product>

(declare-flow-object-class formatting-instruction
  "UNREGISTERED::James Clark//Flow Object Class::formatting-instruction")
; make a product object
(element (PRODUCT)
     (let 
         (
            (title (attribute-string "TITLE" (current-node)))
            (desc (data (node-list-first (select-elements (children (current-node))
"DESCRIPTION"))))
            (myidentifier "myproductid")
         )
         (make formatting-instruction
            data: (string-append
               (%NEWLINE%)
               "var someproduct = new product("
               (FORMAT-ARGLIST (list title desc)) ", " myidentifier
               ");" 
               (%NEWLINE%) 
) ) ) )

;
; Some syntactic sweeteners
;
(define (%NEWLINE%) (string #\&#RE))    ;; insert a new line into output

;; put quotations around a string while escaping embedded quotes with backslash
(define (ENQUOTE v)                     
   (string-append
      (string #\quotation-mark)
      (string-replace v (string #\quotation-mark) (string-append (string #\reverse-solidus) (string
#\quotation-mark)))
      (string #\quotation-mark)
   )
)

; format a list of comma-separated literal arguments (e.g. JavaScript/C/C++/Java style argument
lists)
; quotes are placed around each the arguments, and embedded quotes are escaped with a backslash
(define (FORMAT-ARGLIST l)    
   (let loop 
      (  
         (t l)
         (str "")
      )
      (if (null? t) 
         str
         (loop 
            (cdr t) 
            (string-append str (ENQUOTE (car t)) (if (null? (cdr t)) "" ", "))
         )
)  )  )

Grzegorz Staniak wrote:
> 
> Hello,
> 
> I'd like to request your advice: I've got data in SGML (a rather
> simple DTD) that I need to edit in a specialised editor, then
> export to SGML again, and then feed it to an SQL database. I
> want to spare myself some work and generate SQL from the
> SGML data using Jade. Is it feasible? And, more importantly,
> how would you start? I've never got past the tutorial example
> stage as far as DSSSL and Jade are concerned, but the DTD
> is really simple, and I'm not afraid to laern something new.
> Could anyone kick me in the right direction, like for example by
> telling me what kind of flow object class to use? "Sequence", I
> guess? And is everything I need implemented in Jade?
> 
> TIA,
> 
> --
> Grzegorz Staniak
> <gstaniak@xxxxxxxxxxxxxxxxxxxx>
> 
>  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


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


Current Thread