Mercurial > hg > lib > markup
changeset 2:2b399c612a3e
from elsewhere, pbly out of date
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 25 May 2021 13:59:08 -0400 |
parents | f005daf4488a |
children | 870e13483642 |
files | xml/doc.dtd xml/doc.xsl |
diffstat | 2 files changed, 495 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/doc.dtd Tue May 25 13:59:08 2021 -0400 @@ -0,0 +1,60 @@ +<!--* DTD for my XML documents *--> +<!ELEMENT doc (head?,body)> +<!ATTLIST doc style CDATA #IMPLIED> +<!ENTITY % bits 'emph|code|name|link|term'> +<!ENTITY % chunks 'p|list|display|note|image|table|figure'> +<!ELEMENT head (title+,author+,(date|note)*,style?)> +<!ELEMENT title (#PCDATA|%bits;)*> +<!ELEMENT author (#PCDATA|%bits;)*> +<!ELEMENT date (#PCDATA)> +<!ELEMENT style (#PCDATA)> +<!ELEMENT body (div+)> +<!ELEMENT div (title,(div|%chunks;)+)> +<!ATTLIST div id ID #IMPLIED> +<!ELEMENT p (#PCDATA|%bits;)*> +<!ELEMENT display (#PCDATA|%bits;)*> +<!ELEMENT note (#PCDATA|%bits;)*> +<!ELEMENT list ((note|item)+)> +<!ATTLIST list type (normal|enum|defn|1defn|naked|tdefn|2col|ndivs) 'normal' + term-width CDATA "30pt" + term-align (left|center|right|justify|char) "right" + indent CDATA #IMPLIED> +<!ELEMENT emph (#PCDATA|name)*> +<!ATTLIST emph color CDATA #IMPLIED> +<!ELEMENT code (#PCDATA|%bits;)*> +<!ELEMENT name (#PCDATA)> +<!ELEMENT term EMPTY> +<!ATTLIST term def NMTOKENS #REQUIRED> +<!ELEMENT item (#PCDATA|%chunks;|%bits;)*> +<!ATTLIST item term CDATA #IMPLIED> +<!ELEMENT link (#PCDATA|%bits;)*> +<!ATTLIST link href CDATA #IMPLIED + target CDATA #IMPLIED + name CDATA #IMPLIED> +<!ELEMENT image (#PCDATA)> +<!ATTLIST image source CDATA #REQUIRED> +<!ELEMENT figure (%chunks;|caption)*> +<!ELEMENT caption (#PCDATA|%bits;)*> +<!-- Why was this here????? <!ENTITY lt '&#60;'>--> +<!ENTITY mdash "—"> +<!ENTITY ndash "–"> +<!ENTITY rsquo "’"> +<!ENTITY lsquo "‘"> +<!ENTITY rdquo "”"> +<!ENTITY ldquo "“"> +<!ENTITY ccedil "ç" > +<!ENTITY aacute "á" > +<!ENTITY eacute "é" > +<!ENTITY egrave "è" > +<!ENTITY ouml "ö" > +<!ENTITY uuml "ü" > +<!ENTITY copy "©" > + +<!-- allow for table under control of withTables entity. + Either use -i withTables when invoking doxt or nsgmlx to enable, + or put <!ENTITY % withTables 'INCLUDE'> in your internal subset --> +<!ENTITY % withTables 'IGNORE'> +<![%withTables;[ +<!ENTITY % tableDTD SYSTEM 'html-table.dtd'> +%tableDTD; +]]>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/doc.xsl Tue May 25 13:59:08 2021 -0400 @@ -0,0 +1,435 @@ +<?xml version='1.0'?> +<!DOCTYPE xsl:stylesheet SYSTEM "xsl.dtd" [ +<!ENTITY nbsp " "> +]> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml"> + + <xsl:param name="font">DejaVu Sans, Arial</xsl:param> + <xsl:param name="font-size">12pt</xsl:param> + <xsl:param name="topChrome" select="xyzzy"/> + <xsl:param name="botChrome" select="xyzzy"/> + +<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/> + + <xsl:variable name="toc" select="count(//div/@id)>1"/> + + <!-- The real stylesheet starts here --> + <xsl:template match="/"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta name="copyright" content="Copyright (C) 2007 Henry S. Thompson"/> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> + <style type="text/css"> + @page { size: A4 portrait; margin: 2cm} + @media screen { + body {width: 20cm; margin-left: auto; margin-right: auto} + } + body {font-size: <xsl:value-of select="$font-size"/>} + pre.code {font-family: monospace} + pre {margin-left: 0em} + ul.nolabel { margin: 0; margin-left: -2.5em} + ul.naked li { list-style-type: none } + ol ol {list-style-type: lower-alpha} + div.ndli { margin-bottom: 1ex } + .math {font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', serif} + .sub {font-size: 80%; vertical-align: sub} + .termref {text-decoration: none; color: #606000} + div.toc h2 {font-size: 120%; margin-top: 0em; margin-bottom: 0em} + div.toc h4 {font-size: 100%; margin-top: 0em; margin-bottom: 0em; + margin-left: 1em} + div.toc h1 {font-size: 140%; margin-bottom: 0em} + div.toc ul {margin-top: 1ex} + .byline {font-size: 120%} + div.figure {margin-left: 2em} + div.caption {font-style: italic; font-weight: bold; margin-top: 1em} + i i {font-style: normal} + <xsl:value-of select="doc/head/style"/> + <xsl:if test="$topChrome"> + <xsl:text>.skiplink {display: none} + div#banner img {border: none} + A.headertext:link, A.headertext:visited { + color:#ffffff; + text-decoration:none; + font-weight:bold; + font-size: small; + /* font-size:89%;*/ + } + + A.headertext:hover, A.headertext:active { + color:#ffffff; + text-decoration:underline; + font-weight:bold; + font-size: small; + /* font-size:89%;*/ + }</xsl:text> + </xsl:if> + </style> + <title> + <xsl:for-each select="doc/head/title"> + <xsl:value-of select="."/> + </xsl:for-each> + </title> + <xsl:if test="doc/@style"> + <link href="http://www.w3.org/StyleSheets/{doc/@style}.css" rel="stylesheet" type="text/css"/> + </xsl:if> + </head> + <body style="font-family: {$font}; background: rgb(254,250,246)"> + <xsl:if test="$topChrome"> + <xsl:copy-of select="$topChrome"/></xsl:if> + <xsl:apply-templates/> + <xsl:if test="$botChrome"> + <xsl:copy-of select="$botChrome"/></xsl:if> + </body> + </html> + </xsl:template> + + <xsl:template match="doc"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="head/style"/> + + <xsl:template match="body"> + <xsl:choose> + <xsl:when test="$toc"> + <!-- Provide a TOC --> + <xsl:apply-templates select="div[not(@id)]"/> + <div class="toc"> + <h1>Table of Contents</h1> + <ul class="naked"> + <xsl:for-each select=".//div[@id]"> + <li> + <xsl:apply-templates select="title" mode="toc"/> + </li> + </xsl:for-each> + </ul> + </div> + <xsl:apply-templates select="div[@id]"/> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template match="head"> + <div style="text-align: center"> + <xsl:if test="$topChrome//x:a[@href='#main']" xmlns:x="http://www.w3.org/1999/xhtml"> + <xsl:attribute name="id">main</xsl:attribute> + </xsl:if> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="author|date"> + <div class="byline"> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="head/title"> + <h1> + <xsl:apply-templates/> + </h1> + </xsl:template> + + <xsl:template match="div/title"> + <h2> + <xsl:call-template name="title"> + <xsl:with-param name="name" select="../@id"/> + </xsl:call-template> + </h2> + </xsl:template> + + <xsl:template name="title"> + <xsl:param name="name" select="xyzzy"/> + <xsl:param name="href" select="xyzzy"/> + <xsl:choose> + <xsl:when test="$toc and ($name or $href)"> + <xsl:number format="1.1. " level="multiple" count="div[@id]"/> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:when test="not($toc)"> + <xsl:number format="1.1. " level="multiple" count="div"/> + <xsl:text> </xsl:text> + </xsl:when> + </xsl:choose> + <xsl:choose> + <xsl:when test="$name"> + <a name="{$name}"> + <xsl:apply-templates/> + </a> + </xsl:when> + <xsl:when test="$href"> + <a href="#{$href}"> + <xsl:apply-templates/> + </a> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template match="div//div/title" priority="2"> + <h4> + <xsl:call-template name="title"> + <xsl:with-param name="name" select="../@id"/> + </xsl:call-template> + </h4> + </xsl:template> + + <xsl:template match="title" mode="toc"> + <h2> + <xsl:call-template name="title"> + <xsl:with-param name="href" select="../@id"/> + </xsl:call-template> + </h2> + </xsl:template> + + <xsl:template match="div//div/title" priority="2" mode="toc"> + <h4> + <xsl:call-template name="title"> + <xsl:with-param name="href" select="../@id"/> + </xsl:call-template> + </h4> + </xsl:template> + + <xsl:template match="image[contains(@source,'.svg')]"> + <xsl:if test="not(substring-after(@source,'.svg')='')"><xsl:message terminate="yes">Confused by internal '.svg' in <xsl:value-of select="@source"/></xsl:message></xsl:if> + <iframe src="{@source}" frameborder="no" width="100%"> + <xsl:for-each select="@*"> + <xsl:if test="not(local-name()='source' or local-name()='textGloss' or local-name()='float')"> + <xsl:copy> + <xsl:value-of select="."/> + </xsl:copy> + </xsl:if> + </xsl:for-each> + </iframe> + </xsl:template> + + <xsl:template match="image"> + <img src="{@source}" style="border: 0"> + <xsl:attribute name="alt"> + <xsl:choose> + <xsl:when test="@textGloss"> + <xsl:value-of select="@textGloss"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="."/> + </xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <xsl:for-each select="@*"> + <xsl:if test="not(local-name()='source' or local-name()='textGloss')"> + <xsl:copy> + <xsl:value-of select="."/> + </xsl:copy> + </xsl:if> + </xsl:for-each> + </img> + </xsl:template> + + <xsl:template match="figure"> + <div class="figure"> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="figure/caption"> + <div class="caption"><xsl:text>Figure </xsl:text> + <xsl:number count="figure" level="any"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="note"> + <div style="width: 20%; float: right; clear: right; margin-left: .5em"> + <small><i><xsl:apply-templates/></i></small> + </div> + </xsl:template> + + <xsl:template match="item/note"> + <div style="margin-left: 2em"> + <small><i><xsl:apply-templates/></i></small> + </div> + </xsl:template> + + <xsl:template match="emph"> + <i> + <xsl:apply-templates/> + </i> + </xsl:template> + + <xsl:template match="emph[@color]"> + <span style="color: {@color}"> + <xsl:apply-templates/> + </span> + </xsl:template> + + <xsl:template match="name"> + <b> + <xsl:apply-templates/> + </b> + </xsl:template> + + <xsl:template match="link[@href]"> + <a href="{@href}"> + <xsl:if test="@target and not(number(@target))"> + <xsl:attribute name="target"> + <xsl:value-of select="@target"/> + </xsl:attribute> + </xsl:if> + <xsl:apply-templates/> + </a> + </xsl:template> + + <xsl:template match="link[@name]"> + <a> + <xsl:attribute name="name"> + <xsl:value-of select="@name"/> + </xsl:attribute> + <xsl:apply-templates/> + </a> + </xsl:template> + + <xsl:template match="display/node()[self::code and position()=1 and position()=last()]" priority="2"> + <pre class="code"> + <xsl:apply-templates/> + </pre> + </xsl:template> + + <xsl:template match="display"> + <blockquote> + <div> + <xsl:apply-templates/> + </div> + </blockquote> + </xsl:template> + + + <xsl:template match="list[@type="defn"]"> + <dl> + <xsl:apply-templates/> + </dl> + </xsl:template> + +<xsl:template match="list[@type="1defn"]"> + <ul class="naked"> + <xsl:apply-templates/> + </ul> + </xsl:template> + + <xsl:template match="list[@type="defn"]/item"> + <xsl:variable name="n" select="translate(@term,' /','_.')"/> + <dt><b> +<a name="{$n}"><xsl:value-of select="@term"/></a> +</b></dt> + <dd><xsl:apply-templates/></dd> + </xsl:template> + + <xsl:template match="list[@type="1defn"]/item"> + <xsl:variable name="n" select="translate(@term,' /','_.')"/> + <li> +<a name="{$n}"><b><xsl:value-of select="@term"/></b></a> + <xsl:apply-templates/></li> + </xsl:template> + + <xsl:template match="term"> + <a href="#{translate(@def,' ','_')}" class="termref"> + <xsl:text>·</xsl:text> + <xsl:value-of select="@def"/> + <xsl:text>·</xsl:text> + </a> + </xsl:template> + + <xsl:template match="list[@type='normal' or not(@type)]"> + <!-- Firefox doesn't do local DTD attr defaults :-) --> + <ul> + <xsl:apply-templates/> + </ul> + </xsl:template> + + <xsl:template match="list[@type="enum"]"> + <ol> + <xsl:apply-templates/> + </ol> + </xsl:template> + + <xsl:template match="list/item" priority="0"> + <li><xsl:apply-templates/></li> + </xsl:template> + + <xsl:template match="list[@type='naked']"> + <ul class="naked nolabel"> + <xsl:apply-templates/> + </ul> + </xsl:template> + + <xsl:template match="list[@type='ndivs']"> + <div class="ndl"> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="list[@type='ndivs']/item"> + <div class="ndli"> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="list[@type='2col']"> + <xsl:variable name="n" select="count(item)"/> + <div style="float: left;width: 50%"><xsl:apply-templates select="item[position()<=($n div 2)]"/></div> + <div style="margin-left: 50%"><xsl:apply-templates select="item[position()>($n div 2)]"/></div> + </xsl:template> + + <xsl:template match="list[@type='2col']/item"> + <div> + <xsl:if test="../@indent"> + <xsl:attribute name="style"> + <xsl:text>margin-left: </xsl:text> + <xsl:value-of select="../@indent"/> + </xsl:attribute> + </xsl:if> + <xsl:apply-templates/> + </div> + </xsl:template> + + <xsl:template match="list[@type="tdefn"]"> + <table> + <tbody> + <xsl:apply-templates/> + </tbody> + </table> + </xsl:template> + + <xsl:template match="list[@type='tdefn']/item"> + <tr> + <td><xsl:value-of select="@term"/></td> + <td><xsl:apply-templates/></td> + </tr> + </xsl:template> + + <xsl:template match="div|p|table|code|caption|col|colgroup|thead|tfoot|tbody|td|th|span|sup|sub|tr"> + <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml"> + <xsl:apply-templates select="@*|node()"/> + </xsl:element> + </xsl:template> + +<!-- + XHTML + + We just copy any unrecognised stuff, as is. + This means you can mix XHTML with no-namespace elts and + get the 'right' effect. + --> + +<xsl:template match="*|@*"> + <xsl:copy> + <xsl:apply-templates select="* | @* | text()"/> + </xsl:copy> +</xsl:template> + +</xsl:stylesheet>