contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
XML to HTML conversions: chunking  
Introduction: XML to HTML conversions: chunking  

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
  global stream cba
  global stream chap-title

  document-start
    ;
    ; Table of contents (toc).
    ;
    open toc as referent "toc"
    ;
    ; Contents by audience.
    ;
    open cba with referents-allowed as referent "cba"

  element doc
    output "%sc"

  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>'
    ;
    ; This is where we want the contents by audience.
    ;
    output "<hr><h2>Contents by Audience</h2>%n"
        || '<ul>%n'
        || referent "cba"
        || '</ul>'


  element audience
    local stream aud
    set aud to "%c"
    output "<b>For:</b> <i>%g(aud)</i>%n"
    ;
    ; Handle contents by audience.
    ;
    do when referents hasnt key "audtype-%g(aud)"
      ;
      ; Give it a starting value.
      ;
      set referent
         "audtype-%g(aud)" to "<li>%g(aud): "
      ;
      ; Create a place for this list of audience references
      ; in the contents by audience referent.
      ;
      put cba referent "audtype-%g(aud)"
    else
      ;
      ; A referent for this audience exists, so just append
      ; the desired delimiter (a semicolon in this case).
      ;
      set referent
         "audtype-%g(aud)" to referents ^ "audtype-%g(aud)" || "; "
    done
    ;
    ; Now write the necessary linking information to the end of the
    ; audience referent.
    ;
    using attribute id of parent
    set referent
       "audtype-%g(aud)" to referents ^ "audtype-%g(aud)"
       || '<a href="chap-%d(chap-no).htm">%g(chap-title)</a>'

  element p
    output "<p>%n%n%c"


  element glossary
    set file "gloss.htm" to
          '<font size=-2>'
          || '<a href="chunk.htm">[Tables of Contents]</a><br>%n'
          || '</font>'
          || "<h2>Glossary</h2>%n%n"
          || "<ul>%n%c"
          || "</ul>%n"

  element term
    local stream term
    set term to "%c"                 ; Content linking.
    output '<a name="content-%g(term)">'
        || "<li>%g(term):"

  element part
    local stream part
    set part to "%c"
    output '<a href="gloss.htm#content-%g(part)">'
        || "%g(part)"
        || '</a>'

  element defn
    output " %c%n"

  ; Explicit links.

  element xref
    output referent "chapfile-%v(idref)"
    suppress

  element chapter
    increment chap-no
    set file "chap-%d(chap-no).htm" with referents-allowed to '%c'

  element title when parent is chapter
    local counter prev-chap-no
    set chap-title to "Chapter %d(chap-no), %c"
    ;
    ; Small navigation font.
    ;
    output "<font size=-2>"
    ;
    ; Backward linking.
    ;
    do when chap-no > 1
      set prev-chap-no to chap-no - 1
      output '<a ref="chap-%d(prev-chap-no).htm">'
            || '[Previous Chapter]'
            || '</a><br>'
    else
      output '<font color=gray>'
            || '[Previous Chapter]'
            || '</font><br>'
    done
    ;
    ; Forward linking (output a referent, set a default in case
    ; there are no more chapters).
    ;
    output referent "chap-forw-link-%d(chap-no)"
    set referent
       "chap-forw-link-%d(chap-no)" to
       "<font color=gray>[Next Chapter]</font><br>"
       ; in case there isn't a next
    set referent
       "chap-forw-link-%d(prev-chap-no)" to
       '<a href="chap-%d(chap-no).htm">'
       || '[Next Chapter]</a><br>'
       ; backfill
    ;
    ; A couple of hardcoded ones to assist navigation.
    ;
    output
       '<a href="chunk.htm">[Tables of Contents]</a><br>%n'
    output
       '<a href="gloss.htm">[Glossary]</a><br>%n'
    output
       "</font>"
    ;
    output
       "<h2>%g(chap-title)</h2>%n"
    using attribute id of parent
      do
        set referent
           "chapfile-%v(id)" to '<a href="chap-%d(chap-no).htm">'
                                          || '%g(chap-title)</a>'
        put toc '<li><a href="chap-%d(chap-no).htm">%g(chap-title)</a>'
      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"

  ; Some cleanup.
  ;
  translate white-space+ content-end

 
----  

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:01:46 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.