Re: Accessing the Document Prolog with Jade

Subject: Re: Accessing the Document Prolog with Jade
From: Tony Graham <tgraham@xxxxxxxxxxxxxxxx>
Date: Thu, 26 Nov 1998 13:01:51 -0500 (EST)
At 26 Nov 1998 16:47 +0100, SGML@xxxxxxxxxxxxx wrote:
 > I´m trying to do an SGML transformation using Jade.
 > At this stage, I´d be happy to have an identity transformation, but I dont´t
 > know how to copy the document prolog, in particular external entity
 > declarations like
 > <!ENTITY internal SYSTEM "w:\daten\sgml\graphic\aom\internal.tif" NDATA
 > ccitt4>.
 > The don´t appear in the oputput.

This is something that I use, which is based largely on code that I
received from Dan Speck.

------------------------------------------------------------
(define (copy-attributes #!optional (nd (current-node)))
  (let loop ((atts (named-node-list-names (attributes nd))))
    (if (null? atts)
        '()
        (let* ((name (car atts))
               (value (attribute-string name nd)))
          (if value
              (cons (list name value)
                    (loop (cdr atts)))
              (loop (cdr atts)))))))

(define (grove-root #!optional (node (current-node)))
  (node-property 'grove-root node))

(define (declare-external-entities #!optional (the-root (grove-root (current-node))))
  (let loop ((entity-list 
	      (named-node-list-names (node-property 'entities the-root))))
    (if (null? entity-list)
	""
	    (let ((ename (car entity-list)))
	      (if (not (entity-text ename the-root))
		  (string-append "&lt;!ENTITY "
				 ename
				 " "
				 (cond
				  ((entity-public-id ename the-root)
				   (string-append "PUBLIC \"" 
						  (entity-public-id ename the-root)
						  "\""
						  ))
				  ((entity-system-id ename the-root)
				   (string-append "SYSTEM \"" 
						  (entity-system-id ename the-root)
						  "\""
						  ))
				  (else (error (string-append "unknown type entity: " ename)))
				  )
				 (if (entity-notation ename the-root)
				     (string-append " NDATA " (entity-notation ename the-root))
				     "")
				 ">&#RE;"
				 (loop (cdr entity-list)))
		  (loop (cdr entity-list)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Root element
(element ROOTELEMENT
	 (make sequence
	       (make formatting-instruction
		     data: (string-append "&lt;!DOCTYPE " 
					  "rootelement"
					  " PUBLIC \""
					  "Put your public identifier here" "\" [&#RE;"))
	       (make formatting-instruction
		     data: (declare-external-entities))
	       (make formatting-instruction
		     data: "]>&#RE;")
	       (make element
		     attributes: (copy-attributes))))
------------------------------------------------------------

Regards,


Tony Graham
======================================================================
Tony Graham                            mailto:tgraham@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9632
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Current Thread