|
|||||
XML to HTML conversions: linking based on implied structure | |||||
Introduction: XML to HTML conversions: linking based on implied 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 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="#exp-%v(id)">%g(chap-title)</a>%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. 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 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" ; Some cleanup. ; translate white-space+ content-end
---- |