From: Ole Streicher <olebole@debian.org>
Date: Fri, 3 Mar 2017 14:35:24 +0100
Subject: Add XSLT sheets for conversion of the xml documentation to javahelp
 and html.

The files were taken from the "xdoc" package, which is not available in Debian:

https://github.com/Starlink/starjava/tree/master/xdoc/src/etc
---
 src/etc/xdoc/docs.dtd      | 126 ++++++++
 src/etc/xdoc/sun-style.css |   1 +
 src/etc/xdoc/toHTML.xslt   | 206 ++++++++++++++
 src/etc/xdoc/toHTML1.xslt  | 694 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1027 insertions(+)
 create mode 100644 src/etc/xdoc/docs.dtd
 create mode 100644 src/etc/xdoc/sun-style.css
 create mode 100644 src/etc/xdoc/toHTML.xslt
 create mode 100644 src/etc/xdoc/toHTML1.xslt

diff --git a/src/etc/xdoc/docs.dtd b/src/etc/xdoc/docs.dtd
new file mode 100644
index 0000000..01a91a4
--- /dev/null
+++ b/src/etc/xdoc/docs.dtd
@@ -0,0 +1,126 @@
+
+  <!ENTITY % paracontent "( #PCDATA
+                            | em | strong | code
+                            | m | sub | sup
+                            | webref | docxref | javadoc | ref
+                            | blockquote | blockcode | verbatim
+                            | dl | ul | ol
+                            | var | label | img
+                           )*">
+
+  <!-- %simplephrase; is used in some cases where the Starlink General
+   !   (but not Programcode) DTD has span content instead.  Since the
+   !   span model is (similar to) simplephrase, this would be easy to
+   !   reconcile - either modify the general DTD to allow simplephrase
+   !   content as well as span, or just wrap a span around the content
+   !   of elements following this DTD which have content more complicated
+   !   than CDATA. -->
+  <!ENTITY % simplephrase "( #PCDATA
+                             | em | strong | code
+                             | m | sub | sup
+                             | webref | docxref | javadoc | ref
+                             | var | label | img
+                           )*">
+
+  <!ENTITY % sectatts "tocleaf ( yes | no ) #IMPLIED">
+
+  <!ELEMENT sun ( docinfo?, docbody )>
+  <!ELEMENT docinfo ( title?,
+                      authorlist?,
+                      softwareversion?,
+                      docnumber?,
+                      history?,
+                      docdate?,
+                      contactlist? )>
+  <!ELEMENT title %simplephrase;>
+  <!ELEMENT authorlist ( author* )>
+  <!ELEMENT softwareversion ( #PCDATA )>
+  <!ELEMENT docnumber ( #PCDATA )>
+  <!ELEMENT docdate ( #PCDATA )>
+  <!ELEMENT contactlist ( contact* )>
+  <!ELEMENT contact %paracontent;>
+  <!ELEMENT docbody ( blockcode?, abstract?, sect*, appendices? )>
+  <!ELEMENT appendices ( sect+ )>
+  <!ELEMENT abstract ( px* )>
+  <!ELEMENT subhead ( title )>
+  <!ELEMENT p %paracontent;>
+  <!ELEMENT px %paracontent;>
+  <!ELEMENT ul ( li* )>
+  <!ELEMENT ol ( li* )>
+  <!ELEMENT li %paracontent;>
+  <!ELEMENT dl ( ( dt, dd? )* )>
+  <!ELEMENT dt %paracontent;>
+  <!ELEMENT dd ( p* )>
+  <!ELEMENT em %paracontent;>
+  <!ELEMENT strong %paracontent;>
+  <!ELEMENT code %paracontent;>
+  <!ELEMENT m ( #PCDATA | sub | sup )*>
+  <!ELEMENT sup ( #PCDATA )>
+  <!ELEMENT sub ( #PCDATA )>
+  <!ELEMENT verbatim %paracontent;>
+  <!ELEMENT hidden ( #PCDATA )>
+  <!ELEMENT imports ( #PCDATA )>
+  <!ELEMENT blockquote %paracontent;>
+  <!ELEMENT var %paracontent;>
+  <!ELEMENT label %paracontent;>
+  <!ELEMENT history ( version* )>
+  <!ELEMENT version ( px+ )>
+
+  <!ELEMENT blockcode ( #PCDATA | imports | hidden )*>
+  <!ATTLIST blockcode group NMTOKEN #IMPLIED>
+
+  <!ELEMENT author ( #PCDATA )>
+  <!ATTLIST author id ID #IMPLIED
+                   email CDATA #IMPLIED
+                   webpage CDATA #IMPLIED
+                   affiliation CDATA #IMPLIED>
+
+  <!ELEMENT img EMPTY>
+  <!ATTLIST img src CDATA #REQUIRED
+                alt CDATA #IMPLIED>
+
+  <!-- Can't use SSN/70-style figurecontent element with ENTITY-type attribute
+   !   here because there's no way of getting the external unparsed entity's
+   !   URL back properly.  XSLT's unparsed-entity-uri() function looks
+   !   promising, but it turns it into an absolute URI, and a relative
+   !   one is required for our purposes.  So use img instead.
+   !-->
+  <!ELEMENT figure ( caption?, figureimage )>
+  <!ELEMENT caption ( px+ )>
+  <!ELEMENT figureimage EMPTY>
+  <!ATTLIST figureimage src CDATA #REQUIRED>
+
+  <!ELEMENT ref %simplephrase;>
+  <!ATTLIST ref id IDREF #REQUIRED
+                plaintextref ( yes | no ) #IMPLIED>
+
+  <!ELEMENT webref %simplephrase;>
+  <!ATTLIST webref url CDATA #REQUIRED
+                   plaintextref ( yes | no ) #IMPLIED>
+
+  <!ELEMENT docxref %simplephrase;>
+  <!ATTLIST docxref doc CDATA #REQUIRED
+                    loc CDATA #IMPLIED
+                    plaintextref ( yes | no ) #IMPLIED>
+
+  <!ELEMENT javadoc %simplephrase;>
+  <!ATTLIST javadoc class CDATA #REQUIRED
+                    member CDATA #IMPLIED
+                    docset CDATA #IMPLIED
+                    codetext CDATA #IMPLIED>
+
+  <!ELEMENT sect ( subhead?, ( p | figure | subsect )* )>
+  <!ATTLIST sect id ID #IMPLIED
+                 %sectatts;>
+
+  <!ELEMENT subsect ( subhead?, ( p | figure | subsubsect )* )>
+  <!ATTLIST subsect id ID #IMPLIED
+                    %sectatts;>
+
+  <!ELEMENT subsubsect ( subhead?, ( p | figure | subsubsubsect )* )>
+  <!ATTLIST subsubsect id ID #IMPLIED
+                       %sectatts;>
+
+  <!ELEMENT subsubsubsect ( subhead?, ( p | figure )* )>
+  <!ATTLIST subsubsubsect id ID #IMPLIED
+                          %sectatts;>
diff --git a/src/etc/xdoc/sun-style.css b/src/etc/xdoc/sun-style.css
new file mode 100644
index 0000000..0019c5a
--- /dev/null
+++ b/src/etc/xdoc/sun-style.css
@@ -0,0 +1 @@
+p > code, dd > code, body > code, li > code, pre {color: #663300;}
diff --git a/src/etc/xdoc/toHTML.xslt b/src/etc/xdoc/toHTML.xslt
new file mode 100644
index 0000000..eec3922
--- /dev/null
+++ b/src/etc/xdoc/toHTML.xslt
@@ -0,0 +1,206 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:import href="toHTML1.xslt"/>
+
+  <xsl:output method="xml"/>
+
+  <xsl:key name="file" use="'true'"
+           match="*/docinfo|*/abstract|*/sect|*/subsect|*/subsubsect|*/subsubsubsect"/>
+
+  <xsl:template match="sun">
+    <multisection>
+      <xsl:element name="filesection">
+        <xsl:attribute name="file">
+          <xsl:call-template name="getFile"/>
+        </xsl:attribute>
+        <xsl:attribute name="method">
+          <xsl:text>html</xsl:text>
+        </xsl:attribute>
+        <html>
+          <xsl:text>&#x0a;</xsl:text>
+          <head>
+            <xsl:call-template name="cssStylesheet"/>
+            <title>
+              <xsl:apply-templates select="docinfo/title"/>
+            </title>
+          </head>
+          <xsl:text>&#x0a;</xsl:text>
+          <body>
+            <xsl:apply-templates select="docinfo"/>
+            <hr/>
+            <h2>Contents</h2>
+            <xsl:apply-templates select="docbody" mode="toc"/>
+            <xsl:call-template name="pageFooter"/>
+          </body>
+        </html>
+      </xsl:element>
+      <xsl:apply-templates select="docbody"/>
+    </multisection>
+  </xsl:template>
+
+  <xsl:template match="abstract|sect|subsect|subsubsect|subsubsubsect">
+    <xsl:text>&#x0a;</xsl:text>
+    <hr/>
+    <xsl:text>&#x0a;</xsl:text>
+    <xsl:element name="filesection">
+      <xsl:attribute name="file">
+        <xsl:call-template name="getFile"/>
+      </xsl:attribute>
+      <html>
+        <xsl:text>&#x0a;</xsl:text>
+        <head>
+          <xsl:call-template name="cssStylesheet"/>
+          <title>
+            <xsl:apply-templates mode="nameref" select="."/>
+          </title>
+        </head>
+        <xsl:text>&#x0a;</xsl:text>
+        <body>
+          <hr/>
+          <xsl:text>&#x0a;</xsl:text>
+          <xsl:call-template name="navBar"/>
+          <hr/>
+          <xsl:if test="name(.)='abstract'">
+            <h2>Abstract</h2>
+          </xsl:if>
+          <xsl:apply-templates select="subhead|p|px|figure"/>
+          <xsl:if test="sect|subsect|subsubsect|subsubsubsect">
+            <ul>
+              <xsl:apply-templates mode="toc"
+                               select="sect|subsect|subsubsect|subsubsubsect"/>
+            </ul>
+          </xsl:if>
+          <hr/>
+          <xsl:call-template name="navBar"/>
+          <xsl:call-template name="pageFooter"/>
+        </body>
+      </html>
+    </xsl:element>
+    <xsl:apply-templates select="sect|subsect|subsubsect|subsubsubsect"/>
+  </xsl:template>
+
+  <xsl:template name="getRef">
+    <xsl:param name="node" select="."/>
+    <xsl:call-template name="getFile">
+      <xsl:with-param name="node" select="$node"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="getFile">
+    <xsl:param name="node" select="."/>
+    <xsl:choose>
+      <xsl:when test="name($node)='docinfo' or
+                      name($node)='docbody' or
+                      name($node)='sun'">
+        <xsl:text>index.html</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="getId">
+          <xsl:with-param name="node" select="$node"/>
+        </xsl:call-template>
+        <xsl:text>.html</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="seqNo">
+    <xsl:variable name="seqNode" select="."/>
+    <xsl:for-each select="key('file','true')">
+      <xsl:if test=".=$seqNode">
+        <xsl:value-of select="position()"/>
+      </xsl:if>
+    </xsl:for-each>
+  </xsl:template>
+
+  <xsl:template name="navBar">
+    <xsl:variable name="seqno">
+      <xsl:call-template name="seqNo"/>
+    </xsl:variable>
+    <xsl:variable name="next"
+                  select="key('file','true')[position()=$seqno + 1]"/>
+    <xsl:variable name="prev"
+                  select="key('file','true')[position()=$seqno - 1]"/>
+    <xsl:variable name="up"
+                  select="ancestor::*[local-name()!='appendices'][1]"/>
+    <xsl:variable name="contents"
+                  select="/sun/docinfo"/>
+
+    <xsl:call-template name="navButton">
+      <xsl:with-param name="text" select="'Next'"/>
+      <xsl:with-param name="destination" select="$next"/>
+    </xsl:call-template>
+    <xsl:call-template name="navButton">
+      <xsl:with-param name="text" select="'Previous'"/>
+      <xsl:with-param name="destination" select="$prev"/>
+    </xsl:call-template>
+    <xsl:call-template name="navButton">
+      <xsl:with-param name="text" select="'Up'"/>
+      <xsl:with-param name="destination" select="$up"/>
+    </xsl:call-template>
+    <xsl:call-template name="navButton">
+      <xsl:with-param name="text" select="'Contents'"/>
+      <xsl:with-param name="destination" select="$contents"/>
+    </xsl:call-template>
+    <br/>
+    <xsl:call-template name="navLine">
+      <xsl:with-param name="text" select="'Next'"/>
+      <xsl:with-param name="destination" select="$next"/>
+    </xsl:call-template>
+    <xsl:call-template name="navLine">
+      <xsl:with-param name="text" select="'Up'"/>
+      <xsl:with-param name="destination" select="$up"/>
+    </xsl:call-template>
+    <xsl:call-template name="navLine">
+      <xsl:with-param name="text" select="'Previous'"/>
+      <xsl:with-param name="destination" select="$prev"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="navButton">
+    <xsl:param name="text"/>
+    <xsl:param name="destination"/>
+    <xsl:choose>
+      <xsl:when test="$destination">
+        <xsl:element name="a">
+          <xsl:attribute name="href">
+            <xsl:call-template name="getRef">
+              <xsl:with-param name="node" select="$destination"/>
+            </xsl:call-template>
+          </xsl:attribute>
+          <xsl:value-of select="$text"/>
+        </xsl:element>
+       </xsl:when>
+       <xsl:otherwise>
+         <xsl:value-of select="$text"/>
+       </xsl:otherwise>
+    </xsl:choose>
+    <xsl:text> </xsl:text>
+  </xsl:template>
+
+  <xsl:template name="navLine">
+    <xsl:param name="text"/>
+    <xsl:param name="destination"/>
+    <xsl:text> </xsl:text>
+    <xsl:choose>
+      <xsl:when test="$destination">
+        <b>
+          <xsl:value-of select="$text"/>
+          <xsl:text>: </xsl:text>
+        </b>
+        <xsl:element name="a">
+          <xsl:attribute name="href">
+            <xsl:call-template name="getRef">
+              <xsl:with-param name="node" select="$destination"/>
+            </xsl:call-template>
+          </xsl:attribute>
+          <xsl:apply-templates mode="nameref" select="$destination"/>
+        </xsl:element>
+        <br/>
+        <xsl:text>&#x0a;</xsl:text>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:template>
+
+</xsl:stylesheet>
diff --git a/src/etc/xdoc/toHTML1.xslt b/src/etc/xdoc/toHTML1.xslt
new file mode 100644
index 0000000..c3496b4
--- /dev/null
+++ b/src/etc/xdoc/toHTML1.xslt
@@ -0,0 +1,694 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:java="http://xml.apache.org/xalan/java"
+                xmlns:ImageIcon="xalan://javax.swing.ImageIcon"
+                xmlns:File="xalan://java.io.File"
+                exclude-result-prefixes="java ImageIcon File">
+
+  <xsl:param name="JAVADOCS"
+             select="'http://andromeda.star.bris.ac.uk/starjavadocs/'"/>
+  <xsl:param name="VERSION" select="'???'"/>
+  <xsl:param name="BASEDIR" select="'.'"/>
+  <xsl:param name="COVERIMAGE" select="''"/>
+  <xsl:param name="CSS_HREF" select="''"/>
+  <xsl:param name="DOCTYPE" select="'Starlink User Note'"/>
+
+  <!-- Top level element -->
+
+  <xsl:template match="sun">
+    <html>
+      <head>
+        <xsl:call-template name="cssStylesheet"/>
+        <title>
+          <xsl:apply-templates select="docinfo/title"/>
+        </title>
+      </head>
+      <body>
+        <xsl:apply-templates select="docinfo"/>
+        <hr/>
+        <h2>Contents</h2>
+        <xsl:apply-templates select="docbody" mode="toc"/>
+        <hr/>
+        <xsl:apply-templates select="docbody"/>
+        <xsl:call-template name="pageFooter"/>
+      </body>
+    </html>
+  </xsl:template>
+
+
+  <!-- normal processing -->
+
+  <xsl:template match="docinfo">
+    <h1 align="center">
+      <xsl:apply-templates select="title"/>
+      <br/>
+      <xsl:text>Version </xsl:text>
+      <xsl:call-template name="getVersion"/>
+    </h1>
+    <xsl:if test="$COVERIMAGE">
+      <div align="center">
+        <xsl:call-template name="outImg">
+          <xsl:with-param name="src" select="$COVERIMAGE"/>
+          <xsl:with-param name="alt" select="'Cover image'"/>
+        </xsl:call-template>
+      </div>
+    </xsl:if>
+    <hr/>
+    <p>
+      <i>
+        <xsl:value-of select="$DOCTYPE"/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates select="docnumber"/>
+        <br/>
+        <xsl:apply-templates select="authorlist"/>
+        <br/>
+        <xsl:apply-templates select="docdate"/>
+        <br/>
+        <xsl:apply-templates select="history"/>
+      </i>
+    </p>
+  </xsl:template>
+
+  <xsl:template match="author">
+    <xsl:apply-templates/>
+    <xsl:if test="following-sibling::author">
+      <xsl:text>, </xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="contact">
+    <xsl:apply-templates/>
+    <br/>
+  </xsl:template>
+
+  <xsl:template match="abstract">
+    <h2><a name="abstract"/>Abstract</h2>
+    <xsl:apply-templates/>
+  </xsl:template>
+
+  <xsl:template match="p|px">
+    <p><xsl:apply-templates/></p>
+  </xsl:template>
+
+  <xsl:template match="dd/p[position()=1]">
+    <xsl:apply-templates/>
+  </xsl:template>
+
+  <xsl:template match="ul|ol|li|dl|dd|blockquote|code|em|strong|sub|sup">
+    <xsl:copy>
+      <xsl:apply-templates/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="m">
+    <i>
+      <xsl:apply-templates/>
+    </i>
+  </xsl:template>
+
+  <xsl:template match="label">
+    <b><xsl:apply-templates/></b>
+  </xsl:template>
+
+  <xsl:template match="var">
+    <i><xsl:apply-templates/></i>
+  </xsl:template>
+
+  <xsl:template match="img">
+    <xsl:call-template name="outImg">
+      <xsl:with-param name="src" select="@src"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="figure">
+    <div align="center">
+      <xsl:call-template name="outImg">
+        <xsl:with-param name="src" select="figureimage/@src"/>
+        <xsl:with-param name="alt" select="caption/px[position()=1]"/>
+      </xsl:call-template>
+      <xsl:apply-templates select="caption"/>
+    </div>
+  </xsl:template>
+
+  <xsl:template match="caption">
+    <b>
+      <xsl:apply-templates/>
+    </b>
+  </xsl:template>
+
+  <xsl:template match="verbatim">
+    <pre><xsl:apply-templates/></pre>
+  </xsl:template>
+
+  <xsl:template match="blockcode">
+    <pre><xsl:apply-templates/></pre>
+  </xsl:template>
+
+  <xsl:template match="hidden"/>
+  <xsl:template match="imports"/>
+
+  <xsl:template match="dt">
+    <xsl:copy>
+      <strong>
+        <xsl:apply-templates/>
+      </strong>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="ref">
+    <xsl:element name="a">
+      <xsl:attribute name="href">
+        <xsl:call-template name="getRef">
+          <xsl:with-param name="node" select="id(@id)"/>
+        </xsl:call-template>
+      </xsl:attribute>
+      <xsl:choose>
+        <xsl:when test="string(.)">
+          <xsl:apply-templates/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates mode="sectype" select="id(@id)"/>
+          <xsl:text> </xsl:text>
+          <xsl:apply-templates mode="ref" select="id(@id)"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:element>
+  </xsl:template>
+
+  <xsl:template match="webref">
+    <a href="{@url}">
+      <xsl:choose>
+        <xsl:when test="string(.)">
+          <xsl:apply-templates/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="@url"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </a>
+  </xsl:template>
+
+  <xsl:template match="docxref">
+    <xsl:element name="a">
+      <xsl:attribute name="href">
+        <xsl:call-template name="docRefUrl">
+          <xsl:with-param name="doc" select="@doc"/>
+          <xsl:with-param name="loc" select="@loc"/>
+        </xsl:call-template>
+      </xsl:attribute>
+      <xsl:choose>
+        <xsl:when test="string(.)">
+          <xsl:apply-templates/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:call-template name="docRefText">
+            <xsl:with-param name="doc" select="@doc"/>
+            <xsl:with-param name="loc" select="@loc"/>
+          </xsl:call-template>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:element>
+  </xsl:template>
+
+  <xsl:template match="javadoc">
+    <xsl:element name="a">
+      <xsl:attribute name="href">
+        <xsl:choose>
+          <xsl:when test="@docset">
+            <xsl:value-of select="@docset"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$JAVADOCS"/>
+          </xsl:otherwise>
+        </xsl:choose>
+        <xsl:value-of
+             select="translate(translate(@class, '.', '/'), '$', '.')"/>
+        <xsl:choose>
+          <xsl:when test="@class='.'">
+            <xsl:value-of select="'index.html'"/>
+          </xsl:when>
+          <xsl:when test="substring(@class, string-length(@class))='.'">
+            <xsl:value-of select="'package-summary.html'"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="'.html'"/>
+          </xsl:otherwise>
+        </xsl:choose>
+        <xsl:if test="@member">
+          <xsl:value-of select="'#'"/>
+          <xsl:value-of select="normalize-space(@member)"/>
+        </xsl:if>
+      </xsl:attribute>
+      <xsl:choose>
+        <xsl:when test="@codetext">
+          <code>
+            <xsl:value-of select="@codetext"/>
+          </code>
+        </xsl:when>
+        <xsl:when test="string(.)">
+          <xsl:apply-templates/>
+        </xsl:when>
+        <xsl:otherwise>
+          <code>
+            <xsl:choose>
+              <xsl:when test="substring(@class, string-length(@class))='.'">
+                <xsl:value-of
+                     select="substring(@class, 1, string-length(@class)-1)"/>
+              </xsl:when>
+              <xsl:when test="@member">
+                <xsl:choose>
+                  <xsl:when test="contains(@member, '(')">
+                    <xsl:value-of select="substring-before(@member, '(')"/>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <xsl:value-of select="@member"/>
+                  </xsl:otherwise>
+                </xsl:choose>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:call-template name="lastPart">
+                  <xsl:with-param name="text" select="@class"/>
+                </xsl:call-template>
+              </xsl:otherwise>
+            </xsl:choose>
+          </code>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:element>
+  </xsl:template>
+
+
+  <!-- titles -->
+
+  <xsl:template
+      match="docbody/sect/subhead/title
+            |appendices/sect/subhead/title
+            |appendices/sect/subsect/subhead/title">
+    <hr/>
+    <h2>
+      <xsl:element name="a">
+        <xsl:attribute name="name">
+          <xsl:call-template name="getId">
+            <xsl:with-param name="node" select="../.."/>
+          </xsl:call-template>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="../.."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates/>
+      </xsl:element>
+    </h2>
+  </xsl:template>
+
+  <xsl:template
+      match="docbody/sect/subsect/subhead/title
+            |appendices/sect/subsect/subsubsect/subhead/title">
+    <h3>
+      <xsl:element name="a">
+        <xsl:attribute name="name">
+          <xsl:call-template name="getId">
+            <xsl:with-param name="node" select="../.."/>
+          </xsl:call-template>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="../.."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates/>
+      </xsl:element>
+    </h3>
+  </xsl:template>
+
+  <xsl:template
+      match="docbody/sect/subsect/subsubsect/subhead/title
+            |appendices/sect/subsect/subsubsect/subsubsubsect/subhead/title">
+    <h4>
+      <xsl:element name="a">
+        <xsl:attribute name="name">
+          <xsl:call-template name="getId">
+            <xsl:with-param name="node" select="../.."/>
+          </xsl:call-template>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="../.."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates/>
+      </xsl:element>
+    </h4>
+  </xsl:template>
+
+  <xsl:template
+       match="docbody/sect/subsect/subsubsect/subsubsubsect/subhead/title">
+    <h4>
+      <xsl:element name="a">
+        <xsl:attribute name="name">
+          <xsl:call-template name="getId">
+            <xsl:with-param name="node" select="../.."/>
+          </xsl:call-template>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="../.."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates/>
+      </xsl:element>
+    </h4>
+  </xsl:template>
+
+
+  <!-- table of contents -->
+
+  <xsl:template mode="toc" match="docbody">
+    <ul>
+      <xsl:apply-templates mode="toc"
+                           select="abstract|sect|appendices/sect"/>
+    </ul>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="title">
+    <xsl:apply-templates/>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="abstract">
+    <li>
+      <xsl:element name="a">
+        <xsl:attribute name="href">
+          <xsl:call-template name="getRef"/>
+        </xsl:attribute>
+        <xsl:text>Abstract</xsl:text>
+      </xsl:element>
+    </li>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="sect">
+    <li>
+      <xsl:element name="a">
+        <xsl:attribute name="href">
+          <xsl:call-template name="getRef"/>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates mode="toc" select="subhead/title"/>
+      </xsl:element>
+    </li>
+    <xsl:if test="not(@tocleaf='yes')">
+      <xsl:if test="subsect">
+        <ul>
+          <xsl:apply-templates mode="toc" select="subsect"/>
+        </ul>
+      </xsl:if>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="subsect">
+    <li>
+      <xsl:element name="a">
+        <xsl:attribute name="href">
+          <xsl:call-template name="getRef"/>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates mode="toc" select="subhead/title"/>
+      </xsl:element>
+    </li>
+    <xsl:if test="not(@tocleaf='yes')">
+      <xsl:if test="subsubsect">
+        <ul>
+          <xsl:apply-templates mode="toc" select="subsubsect"/>
+        </ul>
+      </xsl:if>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="subsubsect">
+    <li>
+      <xsl:element name="a">
+        <xsl:attribute name="href">
+          <xsl:call-template name="getRef"/>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates mode="toc" select="subhead/title"/>
+      </xsl:element>
+    </li>
+    <xsl:if test="not(@tocleaf='yes')">
+      <xsl:if test="subsubsubsect">
+        <ul>
+          <xsl:apply-templates mode="toc" select="subsubsubsect"/>
+        </ul>
+      </xsl:if>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template mode="toc" match="subsubsubsect">
+    <li>
+      <xsl:element name="a">
+        <xsl:attribute name="href">
+          <xsl:call-template name="getRef"/>
+        </xsl:attribute>
+        <xsl:apply-templates mode="ref" select="."/>
+        <xsl:text> </xsl:text>
+        <xsl:apply-templates mode="toc" select="subhead/title"/>
+      </xsl:element>
+    </li>
+  </xsl:template>
+
+
+  <!-- section numbering -->
+
+  <xsl:template mode="ref" match="sect">
+    <xsl:number count="sect"/>
+  </xsl:template>
+
+  <xsl:template mode="ref" match="appendices/sect">
+    <xsl:number count="sect" format="A"/>
+  </xsl:template>
+
+  <xsl:template mode="ref" match="subsect">
+    <xsl:apply-templates mode="ref" select=".."/>
+    <xsl:text>.</xsl:text>
+    <xsl:number count="subsect"/>
+  </xsl:template>
+
+  <xsl:template mode="ref" match="subsubsect">
+    <xsl:apply-templates mode="ref" select=".."/>
+    <xsl:text>.</xsl:text>
+    <xsl:number count="subsubsect"/>
+  </xsl:template>
+
+  <xsl:template mode="ref" match="subsubsubsect">
+    <xsl:apply-templates mode="ref" select=".."/>
+    <xsl:text>.</xsl:text>
+    <xsl:number count="subsubsubsect"/>
+  </xsl:template>
+
+
+  <!-- named section reference -->
+
+  <xsl:template mode="nameref" match="sect|subsect|subsubsect|subsubsubsect">
+    <xsl:apply-templates mode="nameref" select="subhead/title"/>
+  </xsl:template>
+
+  <xsl:template mode="nameref" match="appendices">
+    <xsl:text>Appendices</xsl:text>
+  </xsl:template>
+
+  <xsl:template mode="nameref" match="title">
+    <xsl:apply-templates mode="nameref"/>
+  </xsl:template>
+
+  <xsl:template mode="nameref" match="abstract">
+    <xsl:text>Abstract</xsl:text>
+  </xsl:template>
+
+  <xsl:template mode="nameref" match="docbody|docinfo">
+    <xsl:text>Top</xsl:text>
+  </xsl:template>
+
+  <!-- section type description -->
+
+  <xsl:template mode="sectype" match="sect|subsect|subsubsect|subsubsubsect">
+    <xsl:choose>
+      <xsl:when test="ancestor::appendices">
+        <xsl:text>Appendix</xsl:text>
+      </xsl:when>
+      <xsl:when test="ancestor-or-self::sect">
+        <xsl:text>Section</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:text>item??</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- subroutines -->
+
+  <xsl:template name="lastPart">
+    <xsl:param name="text"/>
+    <xsl:choose>
+      <xsl:when test="contains($text, '.')">
+        <xsl:call-template name="lastPart">
+          <xsl:with-param name="text" select="substring-after($text, '.')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$text"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="getId">
+    <xsl:param name="node" select="."/>
+    <xsl:choose>
+      <xsl:when test="$node/@id">
+        <xsl:value-of select="$node/@id"/>
+      </xsl:when>
+      <xsl:when test="name($node)='abstract'">
+        <xsl:text>abstract</xsl:text>
+      </xsl:when>
+      <xsl:when test="name($node)='sun' or
+                      name($node)='docinfo' or
+                      name($node)='docbody'">
+        <xsl:text>sun</xsl:text>
+        <xsl:value-of select="/sun/docinfo/docnumber"/>
+      </xsl:when>
+      <xsl:when test="name($node)='sect' or
+                      name($node)='subsect' or
+                      name($node)='subsubsect' or
+                      name($node)='subsubsubsect'">
+        <xsl:text>sec</xsl:text>
+        <xsl:apply-templates mode="ref" select="$node"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="generate-id($node)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="getRef">
+    <xsl:param name="node" select="."/>
+    <xsl:text>#</xsl:text>
+    <xsl:call-template name="getId">
+      <xsl:with-param name="node" select="$node"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="pageFooter">
+    <hr/>
+    <i>
+      <xsl:apply-templates select="/sun/docinfo/title"/>
+      <br/>
+      <xsl:value-of select="$DOCTYPE"/>
+      <xsl:apply-templates select="/sun/docinfo/docnumber"/>
+      <br/>
+      <xsl:apply-templates select="/sun/docinfo/contactlist"/>
+    </i>
+  </xsl:template>
+
+  <xsl:template name="getVersion">
+    <xsl:choose>
+      <xsl:when test="/sun/docinfo/softwareversion">
+        <xsl:apply-templates select="/sun/docinfo/softwareversion"/>
+      </xsl:when>
+      <xsl:when test="$VERSION">
+        <xsl:value-of select="$VERSION"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:text>???</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="docRefText">
+    <xsl:param name="doc"/>
+    <xsl:param name="loc"/>
+    <xsl:choose>
+      <xsl:when test="$doc='sun243'">
+        <xsl:text>SUN/243</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun252'">
+        <xsl:text>SUN/252</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun253'">
+        <xsl:text>SUN/253</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun256'">
+        <xsl:text>SUN/256</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:message terminate="yes">
+          <xsl:text>Unknown document ID $doc</xsl:text>
+        </xsl:message>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="docRefUrl">
+    <xsl:param name="doc"/>
+    <xsl:param name="loc"/>
+    <xsl:choose>
+      <xsl:when test="$doc='sun243'">
+        <xsl:text>http://www.starlink.ac.uk/star/docs/sun243.htx/sun243.html</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun252'">
+        <xsl:text>http://www.starlink.ac.uk/stil/sun252/</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun253'">
+        <xsl:text>http://www.starlink.ac.uk/topcat/sun253/</xsl:text>
+      </xsl:when>
+      <xsl:when test="$doc='sun256'">
+        <xsl:text>http://www.starlink.ac.uk/stilts/sun256/</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:message terminate="yes">
+          <xsl:text>Unknown document ID $doc</xsl:text>
+        </xsl:message>
+      </xsl:otherwise>
+    </xsl:choose>
+    <xsl:if test="$loc">
+      <xsl:value-of select="$loc"/>
+      <xsl:text>.html</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template name="outImg">
+    <xsl:param name="src"/>
+    <xsl:param name="alt"/>
+    <xsl:element name="img">
+      <xsl:attribute name="src">
+        <xsl:value-of select="$src"/>
+      </xsl:attribute>
+      <xsl:attribute name="alt">
+        <xsl:value-of select="$alt"/>
+      </xsl:attribute>
+      <xsl:attribute name="align">
+        <xsl:text>middle</xsl:text>
+      </xsl:attribute>
+      <xsl:if test="function-available('ImageIcon:getIconWidth')">
+        <xsl:variable name="srcFile" select="File:new($BASEDIR,$src)"/>
+        <xsl:variable name="srcLoc" select="string(java:toString($srcFile))"/>
+        <xsl:variable name="icon" select="ImageIcon:new($srcLoc)"/>
+        <xsl:variable name="width" select="java:getIconWidth($icon)"/>
+        <xsl:variable name="height" select="java:getIconHeight($icon)"/>
+        <xsl:if test="$width&gt;=0">
+          <xsl:attribute name="width">
+            <xsl:value-of select="$width"/>
+          </xsl:attribute>
+        </xsl:if>
+        <xsl:if test="$height&gt;=0">
+          <xsl:attribute name="height">
+            <xsl:value-of select="$height"/>
+          </xsl:attribute>
+        </xsl:if>
+      </xsl:if>
+    </xsl:element>
+  </xsl:template>
+
+  <xsl:template name="cssStylesheet">
+    <xsl:if test="$CSS_HREF">
+      <xsl:element name="link">
+        <xsl:attribute name="rel">stylesheet</xsl:attribute>
+        <xsl:attribute name="type">text/css</xsl:attribute>
+        <xsl:attribute name="href">
+          <xsl:value-of select="$CSS_HREF"/>
+        </xsl:attribute>
+      </xsl:element>
+    </xsl:if>
+  </xsl:template>
+
+</xsl:stylesheet>
