|        | |||||
|  | |||||
| XML to HTML conversions: linking based on structure | |||||
| Introduction: XML to HTML conversions: linking based on structure | 
Sample
This program uses the mart.xml sample input file.
  down-translate with xml   ; Use XML parser.
  global counter chap-no initial {0}
  global stream toc  ; table of contents
  document-start
    ;
    ; Table of contents (toc).
    ;
    open toc as referent "toc"
  element #implied
    output "%c"
  element title when parent is doc
    local stream title
    set title to "%c"
    output "<title>%g(title)</title>%n" || "<h1>%g(title)</h1>%n"
  element author
    output "by: %c%n"
    ;
    ; This is where we want the table of contents.
    ;
    output "<hr><h2>Table of Contents</h2>%n"
        || '<ul>%n'
        || referent "toc"
        || '</ul>'
  element audience
    output "<b>For:</b> <i>%c</i>%n"
  element p
    output "<p>%n%n%c"
  element glossary
    output "%n%n<hr><h2>Glossary</h2>%n%n" || "<ul>%n%c" || "</ul>%n"
  element term
    local stream term
    set term to "%c"                 ; content linking stuff
    output '<a name="content-%g(term)">' || "<li>%g(term):"
  element part
    local stream part
    set part to "%c"
    output '<a href="#content-%g(part)">' || "%g(part)" || '</a>'
  element defn
    output " %c%n"
  ; Explicit links.
  element xref
    output '<a href="#exp-%v(idref)">'
        || referent "exp-%v(idref)"
        || '</a>%c'
  element chapter
    output "<hr>"
    increment chap-no
    output '<a name="exp-%v(id)">%n%c'
  element title when parent is chapter
    local stream chap-title
    set chap-title to "Chapter %d(chap-no), %c"
    output "<h2>%g(chap-title)</h2>%n"
    using attribute id of parent
      do
        set referent "exp-%v(id)" to chap-title
        put toc '<li><a href="#exp-%v(id)">%g(chap-title)</a>%n'
      done
  document-end
    ;
    ; Some browsers don't link well to things at the bottom of 
    ; a page, so put in extra blank lines.
    ;
    output "<br>" ||* 45
           || "<center><i>The End</i></center>%n"
  document-end
    close toc
| ---- |