;;============================================================================== ;; HUTpubl_HTML32.dsl - DSSSL specification for HUTpubl to HTML 3.2 conversion ;; ;; $Id: HUTpubl_HTML32.dsl,v 1.3 1998/02/12 15:01:43 wes Exp $ ;; ;; Author: Jorgen M Westerling ;; ;; Copyright (C) 1997 The Helsinki University of Technology Library ;; ;; Permission to use, copy, modify and distribute this HUTpubl DSSSL- ;; specification and its accompanying documentation for any non- ;; commercial purpose and without fee is hereby granted, provided that ;; this copyright notice appears in all copies. If you modify this ;; HUTpubl DSSSL-specification, rename your modified version. ;; Helsinki University of Technology make no representation about the ;; suitability of the specification for any purpose. It is provided ;; "as is" without expressed or implied warranty. ;; ;; ---------------------------------------------------------------- ;; ;; $Log: HUTpubl_HTML32.dsl,v $ ;; Revision 1.3 1998/02/12 15:01:43 wes ;; Added copyright statement. ;; ;; Revision 1.2 1997/08/25 10:38:06 wes ;; All major elements from the HUTpubl DTD now have corresponding ;; constructs in HTML. ;; + Added support for a Table of Contents ;; + All the different cross-references (the xref-element) now works ;; + The footnotes have links to them ;; + The numbering of the different levels of head-elements works ;; + The lists are implemented ;; + The bibliography is implemented ;; + Tables convert nicely ;; + The unimplemented parts are shown in a red font ;; ;; Revision 1.1 1997/06/13 13:40:13 wes ;; Added the DSSSL specification for HUTpubl -> HTML translation to ;; the repository. ;; All elements are defined in the specification, but many of them ;; still only generates empty sosofos. ;;============================================================================== ;;============================================================================== ;; non-standard functions ;;============================================================================== (declare-flow-object-class element "UNREGISTERED::James Clark//Flow Object Class::element") (declare-flow-object-class empty-element "UNREGISTERED::James Clark//Flow Object Class::empty-element") (declare-flow-object-class document-type "UNREGISTERED::James Clark//Flow Object Class::document-type") (declare-flow-object-class processing-instruction "UNREGISTERED::James Clark//Flow Object Class::processing-instruction") (declare-flow-object-class entity "UNREGISTERED::James Clark//Flow Object Class::entity") (declare-flow-object-class entity-ref "UNREGISTERED::James Clark//Flow Object Class::entity-ref") (declare-flow-object-class formatting-instruction "UNREGISTERED::James Clark//Flow Object Class::formatting-instruction") ;;============================================================================== ;; variables ;;============================================================================== (define %no-multiple-files% #f) (define %no-toc% #f) (define %no-index% #f) (define %pictures-as-links% #f) (define %basename% "HUTpubl2HTML") (define %suffix% ".html") (define %html-public-id% "-//W3C//DTD HTML 3.2 Final//EN") ;;============================================================================== ;; The root element ;;============================================================================== (root (sosofo-append (make document-type name: "HTML" public-id: %html-public-id%) (make element gi: "html" (sosofo-append (make element gi: "head" (make element gi: "title" (with-mode extract-document-title (process-first-descendant "title")))) (make element gi: "body" attributes: (list (list "bgcolor" "#FFFFFF") (list "text" "#000000")) (process-children)))))) (mode extract-head-text (element (head) (process-children-trim))) (mode extract-document-title (element (title) (process-children))) ;=============================================================================== ; %words; ;=============================================================================== (element abbrev (make element gi: "em")) (element abbrdef (make element gi: "tt")) (element definition (make element gi: "pre")) (mode footnote-ref (element footnote (make element gi: "sup" (make element gi: "a" attributes: (list (list "href" (string-append "#fn" (format-number (element-number (current-node)) "1")))) (literal (format-number (element-number (current-node)) "1")))))) (mode footnote-def (element footnote (sosofo-append (make empty-element gi: "a" attributes: (list (list "name" (string-append "fn" (format-number (element-number (current-node)) "1"))))) (make element gi: "blockquote" (make element gi: "font" attributes: (list (list "size" "2")) (make element gi: "strong" (literal (string-append (format-number (element-number (current-node)) "1") ". "))) (process-children)))))) (element glossterm (not-implemented)) (element term (make element gi: "em")) (element typed (make element gi: "tt")) (element quote (sosofo-append (make element gi: "em" (literal "\"") (process-children) (literal "\"")))) ;=============================================================================== ; %computer; ;=============================================================================== (element code (make element gi: "code")) (element keyboard (make element gi: "kbd")) (element output (make element gi: "strong" (make element gi: "em"))) (element variable (make element gi: "strong" (make element gi: "tt"))) ;=============================================================================== ; %styles; ;=============================================================================== (element emphasis (make element gi: "em")) (element strong (make element gi: "strong")) (element preformat (make element gi: "pre")) ;=============================================================================== ; %inlineobj; ;=============================================================================== (element inlinemath (not-implemented)) (element inlinepict (not-implemented)) ;=============================================================================== ; %ref; ;=============================================================================== (element link (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "linkend")))))) (element target (make element gi: "a" attributes: (list (list "name" (format-number (child-number (current-node)) "1"))))) (element xref (let* ((%id% (attribute-string "refid")) (%xref-type% (attribute-string "type"))) (cond ((equal? %xref-type% "FIG") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Figure ") (literal (format-number (element-number (element-with-id %id%)) "1"))))) ((equal? %xref-type% "TABLE") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Table ") (literal (format-number (element-number (element-with-id %id%)) "1"))))) ((equal? %xref-type% "CHAPTER") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Chapter ") (literal (format-number (ancestor-child-number "chapter" (element-with-id %id%)) "1"))))) ((equal? %xref-type% "SECT1") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Section ") (literal (format-number (element-number (ancestor "chapter" (current-node))) "1" )) (literal ".") (literal (format-number (ancestor-child-number "sect1" (element-with-id %id%)) "1"))))) ((equal? %xref-type% "SECT2") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Section ") (literal (format-number (element-number (ancestor "chapter" (current-node))) "1" )) (literal ".") (literal (format-number (child-number (ancestor "sect1" (current-node))) "1")) (literal ".") (literal (format-number (ancestor-child-number "sect2" (element-with-id %id%)) "1"))))) ((equal? %xref-type% "SECT3") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Section ") (literal (format-number (element-number (ancestor "chapter" (current-node))) "1" )) (literal ".") (literal (format-number (child-number (ancestor "sect1" (current-node))) "1")) (literal ".") (literal (format-number (child-number (ancestor "sect2" (current-node))) "1")) (literal ".") (literal (format-number (ancestor-child-number "sect3" (element-with-id %id%)) "1"))))) ((equal? %xref-type% "SECT4") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (sosofo-append (literal " Section ") (literal (format-number (element-number (ancestor "chapter" (current-node))) "1" )) (literal ".") (literal (format-number (child-number (ancestor "sect1" (current-node))) "1")) (literal ".") (literal (format-number (child-number (ancestor "sect2" (current-node))) "1")) (literal ".") (literal (format-number (child-number (ancestor "sect3" (current-node))) "1")) (literal ".") (literal (format-number (ancestor-child-number "sect4" (element-with-id %id%)) "1"))))) ((equal? %xref-type% "BIBL") (sosofo-append (make element gi: "font" attributes: '(("size" "2")) (literal "[") (make element gi: "a" attributes: (list (list "href" (string-append "#" (attribute-string "refid" (current-node))))) (literal (attribute-string "xreflabel" (element-with-id %id%)))) (literal "]"))))))) ;=============================================================================== ; %floating; ;=============================================================================== (element blockquote (sosofo-append (make element gi: "blockquote" (make element gi: "em" (literal "\"") (process-children) (literal "\""))))) (element equation (not-implemented)) (element figure (sosofo-append (make empty-element gi: "br") (make element gi: "div" attributes: (list (list "align" "center")) (process-children)))) (element (figure graphic) (sosofo-append (make empty-element gi: "br") (make-anchor) (if (not %pictures-as-links%) (make empty-element gi: "img" attributes: (list (list "src" (attribute-string "file" (current-node))))) (sosofo-append (literal "[ ") (make element gi: "a" attributes: (list (list "href" (attribute-string "file" (current-node)))) (literal "Click for graphic / Kuva osoittamalla / Klicka för bild")) (literal " ]"))))) (element (figure caption) (make element gi: "p" attributes: '(("align" "center")) (make element gi: "em" (literal "Figure ") (literal (format-number (element-number (ancestor "figure" (current-node))) "1")) (literal ": ") (literal (data (select-elements (current-node) "caption")))))) (element mmedia (not-implemented)) (element table (make element gi: "div" attributes: (list (list "align" "center")) (sosofo-append (make-anchor) (make element gi: "table" attributes: (list (list "border" "1")))))) (element thead (make element gi: "tr" (make element gi: "th"))) (element row (make element gi: "tr")) (element entry (sosofo-append (make element gi: "td") (with-mode footnote-def (process-matching-children "footnote")))) (element (table caption) (sosofo-append (make empty-element gi: "br") (make element gi: "div" attributes: (list (list "align" "center")) (make element gi: "em" (sosofo-append (literal "Table ") (literal (format-number (element-number (ancestor "table" (current-node))) "1")) (literal ": ") (literal (data (select-elements (current-node) "caption"))) (make empty-element gi: "br")))))) ;=============================================================================== ; %lists; ;=============================================================================== (element orderedlist (make element gi: "ol")) (element itemizedlist (make element gi: "ul")) (element desclist (make element gi: "dl")) (element listitem (make element gi: "li")) (element descterm (make element gi: "strong" (make element gi: "dt"))) (element descdata (make element gi: "dd")) (element (descdata para) (make element gi: "p" (process-children))) (element (listitem para) (process-children)) ; No P for PARA inside listitem ;=============================================================================== ; %phrase; ;=============================================================================== (element subscript (make element gi: "sub")) (element superscript (make element gi: "sup")) ;=============================================================================== ; The front matter ;=============================================================================== (element (metadata title) (make element gi: "h1" attributes: (list (list "align" "center")))) (element (metadata author) (sosofo-append (make element gi: "div" attributes: (list (list "align" "center")) (make element gi: "font" attributes: (list (list "size" "4")) (process-children))))) (element (metadata subject) (not-implemented)) (element (metadata description) (not-implemented)) (element (metadata publisher) (not-implemented)) (element (metadata contributors) (not-implemented)) (element (metadata date) (not-implemented)) (element (metadata type) (not-implemented)) (element (metadata format) (not-implemented)) (element (metadata identifier) (not-implemented)) (element (metadata source) (not-implemented)) (element (metadata language) (not-implemented)) (element (metadata relation) (not-implemented)) (element (metadata coverage) (not-implemented)) (element (metadata rights) (not-implemented)) (element (front copyright) (sosofo-append (make element gi: "div" attributes: (list (list "align" "center")) (make empty-element gi: "br") (make element gi: "font" attributes: (list ( list "size" "2")) (literal "© ") (process-children))))) (element (copyright holder) (sosofo-append (literal " ") (process-children))) (element (abstract head) (sosofo-append (make empty-element gi: "hr") (make element gi: "h2" (process-children)))) (element (abstract para) (sosofo-append (make element gi: "blockquote" (make element gi: "i" (if (first-sibling?) (empty-sosofo) (literal "  ")) (process-children))))) (element (keywords) (sosofo-append (make empty-element gi: "hr") (make element gi: "div" attributes: (list (list "align" "center")) (make element gi: "strong" (literal "Keywords: ")) (process-children)))) (element (keyword) (sosofo-append (process-children) (if (last-sibling?) (literal ".") (literal ", ")))) (element (abbrlist) (not-implemented)) (element (symlist) (not-implemented)) (element (figlist) (not-implemented)) (element (toc) (empty-sosofo)) (element (foreword head) (sosofo-append (make empty-element gi: "hr") (make element gi: "h2" (process-children)))) ;=============================================================================== ; The body matter ;=============================================================================== (element (body) (cond ((not %no-toc%) (sosofo-append (make empty-element gi: "hr") (make element gi: "h2" (literal "Table of Contents")) (make element gi: "dl" (with-mode make-toc (process-matching-children "chapter"))) (process-children))) (#t (empty-sosofo)))) (mode make-toc (element (body) (process-children)) (element (chapter) (make-toc-links)) (element (appendix) (make-toc-links)) (element (sect1) (make-toc-links)) (element (sect2) (make-toc-links)) (default (empty-sosofo))) (element (chapter) (sosofo-append (make-anchor) (process-children))) (element (chapter head) (make-head 2 1)) (element (sect1) (sosofo-append (make-anchor) (process-children))) (element (sect1 head) (make-head 3 0)) (element (sect2) (sosofo-append (make-anchor) (process-children))) (element (sect2 head) (make-head 4 0)) (element (sect3) (sosofo-append (make-anchor) (process-children))) (element (sect3 head) (make-head 5 0)) (element (sect4) (sosofo-append (make-anchor) (process-children))) (element (sect4 head) (make-head 6 0)) (element (para) (sosofo-append (make empty-element gi: "p") (if (first-sibling?) (empty-sosofo) (literal "  ")) (with-mode footnote-ref (process-children)) (with-mode footnote-def (process-matching-children "footnote")))) ;=============================================================================== ; The back matter ;=============================================================================== (element (bibl head) (sosofo-append (make empty-element gi: "hr") (make-anchor) (make element gi: "h2" ; (literal (string-append ; (format-number (absolute-child-number (parent (parent (current-node)))) "1") ; ". ")) (process-children)))) (element (appendix head) (make-head 2 1)) (element (magazine) (biblitem-sosofo)) (element (book) (biblitem-sosofo)) (element (serial) (biblitem-sosofo)) (element (confproc) (biblitem-sosofo)) (element (compiled) (biblitem-sosofo)) (element (standard) (biblitem-sosofo)) (element (patent) (biblitem-sosofo)) (element (netres) (biblitem-sosofo)) (element (biblother) (biblitem-sosofo)) (element (author) (separate-bibl-elements)) (element (title) (separate-bibl-elements)) (element (publyear) (separate-bibl-elements)) (element (maganame) (separate-bibl-elements)) (element (volnr) (separate-bibl-elements)) (element (maganr) (separate-bibl-elements)) (element (pages) (separate-bibl-elements)) (element (edition) (separate-bibl-elements)) (element (editor) (separate-bibl-elements)) (element (publwhere) (separate-bibl-elements)) (element (totpages) (separate-bibl-elements)) (element (conference) (separate-bibl-elements)) (element (comptitle) (separate-bibl-elements)) (element (standid) (separate-bibl-elements)) (element (standname) (separate-bibl-elements)) (element (patid) (separate-bibl-elements)) (element (patname) (separate-bibl-elements)) (element (patholder) (separate-bibl-elements)) (element (applnr) (separate-bibl-elements)) (element (appldate) (separate-bibl-elements)) (element (url) (sosofo-append (make element gi: "a" attributes: (list (list "href" (data (select-elements (current-node) "url")))) (literal (data (select-elements (current-node) "url")))) (if (last-sibling? (current-node)) (literal ". ") (literal "; ")))) (element (descript) (separate-bibl-elements)) ;=============================================================================== ; functions ;=============================================================================== (define (make-head %heading-level% %ruler%) (sosofo-append (if (= %ruler% 1) (make empty-element gi: "hr") (empty-sosofo)) (make-anchor) (let ((%GI% (string-append "h" (format-number %heading-level% "1")))) (make element gi: %GI% (literal (make-autonumber-head %heading-level%)) (process-children))))) (define (make-autonumber-head %level%) (cond ((= %level% 2) (string-append (format-number (element-number (ancestor "chapter")) "1") ". ")) ((= %level% 3) (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") " ")) ((= %level% 4) (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") "." (format-number (child-number (ancestor "sect2")) "1") " ")) ((= %level% 5) (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") "." (format-number (child-number (ancestor "sect2")) "1") "." (format-number (child-number (ancestor "sect3")) "1") " ")) ((= %level% 6) (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") "." (format-number (child-number (ancestor "sect2")) "1") "." (format-number (child-number (ancestor "sect3")) "1") "." (format-number (child-number (ancestor "sect4")) "1") " ")))) (define (absolute-child-number %element%) (+ 1 (node-list-length (preced %element%)))) (define (biblitem-sosofo) (make element gi: "p" (sosofo-append (make element gi: "a" attributes: (list (list "name" (attribute-string "id" (current-node)))) (literal "")) (literal "[") (literal (attribute-string "xreflabel" (current-node))) (literal "] ") (process-children)))) (define (separate-bibl-elements) (sosofo-append (process-children) (if (last-sibling? (current-node)) (literal ". ") (literal "; ")))) (define (make-anchor) (if (id) (make element gi: "a" attributes: (list (list "name" (id))) (literal "")) (empty-sosofo))) (define (make-toc-links) (sosofo-append (make empty-element gi: "dd") (let* ((title-number (literal (cond ((equal? (gi) "CHAPTER") (string-append (format-number (element-number (current-node)) "1") ". ")) ((equal? (gi) "SECT1") (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (current-node)) "1") " ")) ((equal? (gi) "SECT2") (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") "." (format-number (child-number (current-node)) "1") " ")) ((equal? (gi) "SECT3") (string-append (format-number (element-number (ancestor "chapter")) "1") "." (format-number (child-number (ancestor "sect1")) "1") "." (format-number (child-number (ancestor "sect2")) "1") "." (format-number (child-number (current-node)) "1") " ")) ((equal? (gi) "APPENDIX") (string-append "Appendix " (format-number (element-number (current-node)) "A") ". "))))) (title-text (with-mode extract-head-text (process-first-descendant "head")))) (if (id) (sosofo-append title-number (make element gi: "a" attributes: (list (list "href" (string-append "#" (id)))) title-text)) (make element gi: "font" attributes: (list (list "color" "red")) title-text))) (make element gi: "dl" (with-mode make-toc (process-matching-children "sect1"))) (make element gi: "dl" (with-mode make-toc (process-matching-children "sect2"))) (make element gi: "dl" (with-mode make-toc (process-matching-children "sect3"))))) (define (not-implemented) (make element gi: "font" attributes: (list (list "color" "red")) (process-children-trim))) ;=============================================================================== ; end of file ;===============================================================================