Newer
Older
XML / xml2html.xsl
nstanger on 10 Dec 2003 18 KB - Added XML authoring stuff.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<!-- Whether sample answers should be included in output.  This could be an xsl:param rather than an xsl:variable, maybe. -->
	<!--/nts-05
	<xsl:variable name="showanswers" select="'yes'"/>
	-->
	<xsl:param name="showanswers" select="'no'"/>
	<xsl:output method="html" encoding="ISO-8859-1" media-type="text/html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
	
	<!-- Make <omit>s (and aliases) disappear. -->
	<xsl:template match="omit"/>
	<xsl:template match="omission"/>
	<xsl:template match="excluded"/>
	<xsl:template match="exclusion"/>
	
	<!-- Carry comments through to the output document.  (Kind of: "It is an error if instantiating the content of xsl:comment creates nodes other than text nodes.") -->
	<xsl:template match="comment">
		<xsl:comment>
			<xsl:apply-templates/>
		</xsl:comment>
	</xsl:template>
	
	<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
	<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>

	
	


	<xsl:variable name="web-server-dns" select="'info-nts-05.otago.ac.nz'"/>
	<xsl:variable name="web-course-path" select="/info321"/>
	<xsl:variable name="web-tut-path" select="$web-course-path/materials"/>
	<xsl:variable name="web-lab-path" select="$web-course-path/materials"/>


	<xsl:template name="paper" match="paper"><xsl:apply-templates select="subject-code"/>&#160;<xsl:apply-templates select="paper-number"/></xsl:template>

	<xsl:template name="PaperCode" match="PaperCode">INFO&#160;321</xsl:template>
	<xsl:template name="OracleServer" match="OracleServer">Oracle9<I>i</I></xsl:template>
	
	
	<!-- Oracle Documentation Links: DO NOT EDIT: generated automatically from Excel -->

<xsl:template match="OraAdmin"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96521/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Administrator<xsl:call-template name="apostrophe"/>s Guide</A></xsl:template>
<xsl:template match="OraAppDevOR"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/appdev.920/a96594/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Application Developer<xsl:call-template name="apostrophe"/>s Guide<xsl:call-template name="emdash"/>Object-Relational Features</A></xsl:template>
<xsl:template match="OraConcepts"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96524/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Concepts</A></xsl:template>
<xsl:template match="OraDataWarehousing"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96520/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> </A></xsl:template>
<xsl:template match="OraErrors"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96525/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Error Messages</A></xsl:template>
<xsl:template match="OraSQL"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96540/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> SQL Reference</A></xsl:template>
<xsl:template match="OraJava"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/java.920/a96656/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Java Developer<xsl:call-template name="apostrophe"/>s Guide</A></xsl:template>
<xsl:template match="OraJDBC"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/java.920/a96654/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> JDBC Developer<xsl:call-template name="apostrophe"/>s Guide and Reference</A></xsl:template>
<xsl:template match="OraGlossary"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/mix.920/a97290/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Master Glossary</A></xsl:template>
<xsl:template match="OraTuning"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96533/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Performance Tuning Guide and Reference</A></xsl:template>
<xsl:template match="OraPLSQL"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/appdev.920/a96624/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> PL/SQL User<xsl:call-template name="apostrophe"/>s Guide and Reference</A></xsl:template>
<xsl:template match="OraIndex"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/mix.920/a96625/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Master Index</A></xsl:template>
<xsl:template match="OraReference"><A><xsl:attribute name="HREF">http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96536/toc.htm</xsl:attribute><xsl:call-template name="OracleServer"/> Database Reference</A></xsl:template>

	<!-- End of Oracle Documentation Links.  That'll save a bit o' typing. -->


	
	<!-- Special characters (should maybe all be named, in case they need to be called explicitly with xsl:call-template) -->
	<!-- I'd like to use the Unicode names for these; will look them up some time! -->
	<xsl:template name="newline" match="newline"><BR/></xsl:template>
	<xsl:template name="non-breaking-space" match="non-breaking-space">&#160;</xsl:template>
	<xsl:template match="nbsp"><xsl:call-template name="non-breaking-space"/></xsl:template>
	<xsl:template name="ellipsis-sign" match="ellipsis-sign">&#8230;</xsl:template>
	<xsl:template match="etc"><xsl:call-template name="ellipsis-sign"/></xsl:template>
	<xsl:template match="ellipsis"><xsl:call-template name="ellipsis-sign"/></xsl:template>
	
	<!-- Mathematical symbols -->
	<xsl:template name="digit-group-separator" match="digit-group-separator"><xsl:call-template name="non-breaking-space"/></xsl:template>
	<xsl:template match="digitsep"><xsl:call-template name="digit-group-separator"/></xsl:template>
	<xsl:template name="multiplication-sign" match="multiplication-sign">&#215;</xsl:template>
	<xsl:template match="times"><xsl:call-template name="multiplication-sign"/></xsl:template>
	<xsl:template match="minus">-</xsl:template>
	<xsl:template match="approximately-equal-to">&#8773;</xsl:template>
	<xsl:template match="less-than-or-equal-to">&lt;=</xsl:template>
	<xsl:template match="less-than">&lt;</xsl:template>
	<xsl:template match="greater-than">&gt;</xsl:template>

	<xsl:template name="endash" match="endash">&#8211;</xsl:template>
	<xsl:template name="emdash" match="emdash">&#8212;</xsl:template>
	<xsl:template name="apostrophe" match="apostrophe">&#8217;</xsl:template>
	<xsl:template match="dollar">$</xsl:template>
	<xsl:template name="percent-sign" match="percent-sign">%</xsl:template>
	<xsl:template match="percent"><xsl:call-template name="percent-sign"/></xsl:template>
	<xsl:template match="ampersand">&amp;</xsl:template>
	<xsl:template match="trademark">&#8482;</xsl:template>
	<xsl:template name="degree-sign" match="degree-sign">&#176;</xsl:template>
	<xsl:template match="degree"><xsl:call-template name="degree-sign"/></xsl:template>
	<xsl:template match="section-sign">Section</xsl:template>
	<xsl:template match="pi">&#960;</xsl:template>

	<!-- Special styles -->
	<xsl:template match="emph"><EM><xsl:apply-templates/></EM></xsl:template>
	<xsl:template match="italic"><I><xsl:apply-templates/></I></xsl:template>
	<xsl:template match="quote">&#8220;<xsl:apply-templates/>&#8221;</xsl:template>
	<xsl:template match="term"><I CLASS="term"><xsl:apply-templates/></I></xsl:template>
	<xsl:template match="foreign"><I CLASS="foreign"><xsl:apply-templates/></I></xsl:template>

	<!-- More math stuff -->
	<xsl:template match="fraction"><SUP><xsl:apply-templates select="numerator"/></SUP>/<SUB><xsl:apply-templates select="denominator"/></SUB></xsl:template>
	<xsl:template name="equation-array" match="equation-array"><TABLE CLASS="equation" BORDER="0" ALIGN="CENTER"><xsl:apply-templates/></TABLE></xsl:template>
	<!-- No, don't put in an alias, because you'd also need one for eqnarray//row.
	<xsl:template match="eqnarray"><xsl:call-template name="equation-array"/></xsl:template> -->
	<xsl:template match="equation-array/row"><TR><TD ALIGN="RIGHT"><xsl:apply-templates select="left"/></TD><TD ALIGN="CENTER"><xsl:apply-templates select="middle"/></TD><TD ALIGN="LEFT"><xsl:apply-templates select="right"/></TD></TR></xsl:template>
	<!-- Nope, LaTeX eqnarray can have only three columns, so no need to generalise.
	<xsl:template match="equation-array/row/cell"><TD><xsl:attribute name="ALIGN"><xsl:value-of select="@align"/></xsl:attribute><xsl:apply-templates/></TD></xsl:template>
	-->

	<xsl:template match="code"><CODE><xsl:apply-templates/></CODE></xsl:template>
	<xsl:template match="code-block">
		<PRE CLASS="code">
			<xsl:apply-templates/>
		</PRE>
	</xsl:template>
	<!-- Special elements inside code blocks: -->
	<xsl:template match="code-block//parameter"><I>&lt;<xsl:apply-templates/>&gt;</I></xsl:template>
	<xsl:template match="code-block//hrule">--------------------------------</xsl:template>
	<xsl:template match="code-block/server-output"><B><xsl:apply-templates/></B></xsl:template>
	<xsl:template match="code-block/query-plan"><B><xsl:apply-templates/></B></xsl:template>

	<xsl:template match="verbatim"><PRE><xsl:apply-templates/></PRE></xsl:template>


	<!-- pass-through code -->
	<xsl:template match="html"><xsl:value-of select="."/></xsl:template>

	<!-- HTML is weird about what things you cannot include inside paragraphs (e.g. lists of any kind).  However, the end P tag is optional, so perhaps let's just not output it. -->
	<xsl:template match="paragraph"><P><xsl:apply-templates/></P></xsl:template>
	<xsl:template match="para"><P><xsl:apply-templates/></P></xsl:template>
	<xsl:template match="p"><P><xsl:apply-templates/></P></xsl:template>



	<!-- Figures and included graphics -->
	<!-- Dummy:
	<xsl:template match="figure">
	
	<pre>
		<xsl:apply-templates/>
	</pre>
	
	</xsl:template>
	-->
	
	<xsl:template match="figure">
		<DIV CLASS="figure">
			<A><xsl:attribute name="NAME">figure-<xsl:value-of select="id"/><xsl:value-of select="label"/></xsl:attribute></A>
			<xsl:apply-templates select="image"/>
			<BR/>
			<xsl:apply-templates select="caption"/>
		</DIV>
	</xsl:template>

	<xsl:template match="image">
		<A>
			<xsl:attribute name="HREF">Graphics/<xsl:value-of select="basename"/>-600dpi.png</xsl:attribute>
			<IMG BORDER="0">
				<xsl:attribute name="SRC">Graphics/<xsl:value-of select="basename"/>-72dpi.png</xsl:attribute>
				<xsl:attribute name="ALT">image:<xsl:value-of select="basename"/></xsl:attribute>
			</IMG>
		</A>
	</xsl:template>

	

	<xsl:template match="eqnarray">
		<pre>
			<xsl:apply-templates/>
		</pre>
	</xsl:template>

	
	
	<!-- Table element handling -->

	<xsl:template match="table">
		<TABLE>
		</TABLE>
	</xsl:template>

	<xsl:template match="table/row">
		<TR>
		</TR>
	</xsl:template>
	
	<xsl:template match="table/row/cell">
		<TD>
			<xsl:apply-templates/>
		</TD>
	</xsl:template>
	
	<!--	<xsl:template match="tutorial/title"><H1><xsl:apply-templates/></H1></xsl:template> -->
	<!-- Need to work out heading level based on section nesting - might be tricky (both for HTML and for LaTeX). -->
	<!-- Do we want to simply allow sections within sections, or make it explicit in the XML what level the section should be at? -->
	<xsl:template match="/tutorial/section/title">
		<H2>
			<xsl:apply-templates/>
		</H2>
	</xsl:template>
	
	<xsl:template match="/laboratory/section/title">
		<H2>
			<xsl:apply-templates/>
		</H2>
	</xsl:template>

	<xsl:template match="/tutorial/section/section/title">
		<H3>
			<xsl:apply-templates/>
		</H3>
	</xsl:template>
	
	<xsl:template match="/laboratory/section/section/title">
		<H3>
			<xsl:apply-templates/>
		</H3>
	</xsl:template>

	
	<xsl:template match="introduction">
		<h2>Introduction</h2>
		<xsl:apply-templates/>
	</xsl:template>
	
	
	<!-- Lists of various kinds -->
	
	<!-- Itemised, unordered, bullet points -->
	<xsl:template name="itemised-list" match="itemised-list">
		<UL>
			<xsl:apply-templates/>
		</UL>
	</xsl:template>
	
	<xsl:template match="itemised-list/item">
		<LI>
			<xsl:apply-templates/>
		</LI>
	</xsl:template>
	
	<!-- For LaTeX compatibility: -->
	<xsl:template match="itemize"><xsl:call-template name="itemised-list"/></xsl:template>
	<xsl:template match="unordered-list"><xsl:call-template name="itemised-list"/></xsl:template>
	<xsl:template match="bulleted-list"><xsl:call-template name="itemised-list"/></xsl:template>
	<xsl:template match="bullet-list"><xsl:call-template name="itemised-list"/></xsl:template>
	<xsl:template match="bullet-points"><xsl:call-template name="itemised-list"/></xsl:template>
	
	<xsl:template match="itemize/item">
		<LI>
			<xsl:apply-templates/>
		</LI>
	</xsl:template>


	<!-- Enumerated, ordered, numbered points -->
	<xsl:template name="enumerated-list" match="enumerated-list">
		<OL>
			<xsl:apply-templates/>
		</OL>
	</xsl:template>
	
	<xsl:template match="enumerated-list/item">
		<LI>
			<xsl:apply-templates/>
		</LI>
	</xsl:template>
	
	<!-- For LaTeX compatibility: -->
	<xsl:template match="enumerate"><xsl:call-template name="enumerated-list"/></xsl:template>
	<xsl:template match="ordered-list"><xsl:call-template name="enumerated-list"/></xsl:template>
	<xsl:template match="numbered-list"><xsl:call-template name="enumerated-list"/></xsl:template>

	
	
	<xsl:template match="question-list">
		<OL class="questions">
			<xsl:apply-templates/>
		</OL>
	</xsl:template>
	
	<xsl:template match="question-list/item">
		<LI class="question">
			<xsl:apply-templates/>
		</LI>
	</xsl:template>
	
	<xsl:template match="definition-list">
		<DL>
			<xsl:apply-templates/>
		</DL>
	</xsl:template>

	<!-- <keyword> and <term> are synonymous in the context definition-list/item -->
	<xsl:template match="definition-list/item/keyword">
		<DT><xsl:apply-templates/></DT>
	</xsl:template>
	
	<xsl:template match="definition-list/item/term">
		<DT><xsl:apply-templates/></DT>
	</xsl:template>

	<xsl:template match="definition-list/item/definition">
		<DD><xsl:apply-templates/></DD>
	</xsl:template>
	
	<!--	<xsl:template match="definition-list/item"><xsl:apply-templates/></xsl:template> -->
	<!-- This doesn't work (in Xalan v?.?) - produces a <DT></DT>...<DD></DD> for some reason. -->
	<xsl:template match="definition-list/item/keyword"><DT/><xsl:apply-templates/><DD/></xsl:template>
	
	<!--
	Processing answer sections for tutorials and labs.  If the document says that answers should be displayed, then do, otherwise do not.
	We could (i.e. should) get gnarly and make it so you can turn answers on/off for each tutorial and lab.
	-->
	<xsl:template match="answer">
		<xsl:if test="$showanswers='yes'">
			<DIV CLASS="answer">
				<xsl:apply-templates/>
			</DIV>
		</xsl:if>
	</xsl:template>



	<!-- Cross-references.  Eewww?  Getting these to work nicely in both LaTeX and HTML could be ick. -->
	<xsl:template name="reference" match="reference">
		<A>
			<xsl:if test="type='figure'">
				<xsl:attribute name="HREF">#figure-<xsl:value-of select="target"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates select="label"/>
		</A>
	</xsl:template>
	
	<!-- alias -->
	<xsl:template match="ref"><xsl:call-template name="reference"/></xsl:template>
	
	
	<!-- Links to URLs. -->
	<xsl:template match="netlink">
		<A>
			<xsl:attribute name="HREF"><xsl:value-of select="target"/></xsl:attribute>
			<xsl:apply-templates select="label"/>
		</A>
	</xsl:template>

	<!-- URLs that should appear verbatim in the output. -->
	<xsl:template match="url">
		<A>
			<xsl:attribute name="HREF"><xsl:value-of select="."/></xsl:attribute>
			<CODE><xsl:value-of select="."/></CODE>
		</A>
	</xsl:template>
	



	<!-- Menu items and paths -->
	<xsl:template match="menu/item"><B><xsl:apply-templates/></B></xsl:template>
	
	<xsl:template name="menu-separator" match="menu/separator">&#8594;</xsl:template>
	<xsl:template match="menusep"><xsl:call-template name="menu-separator"/></xsl:template>
	




	<!-- Top-level document match -->
	
	<xsl:template match="/">
		<!-- <xsl:value-of select="$showanswers"/> -->
		<!-- <xsl:message>showanswers=<xsl:value-of select="$showanswers"/>: Sample answers will be displayed.</xsl:message> -->
		<HTML>
			<HEAD>
				<LINK REL="Stylesheet" HREF="http://info-nts-05.otago.ac.nz/info321/styles.css" TYPE="text/css"/>
				<TITLE>
					<xsl:if test="name(child::node()[1])='tutorial'">
					INFO&#160;321 Tutorial <xsl:value-of select="/tutorial/id/number"/>&#160;<xsl:if test="$showanswers='yes'">Sample Answers</xsl:if>: <xsl:apply-templates select="/tutorial/title"/>
					</xsl:if>

					<xsl:if test="name(child::node()[1])='laboratory'">
					INFO&#160;321 Laboratory <xsl:value-of select="/laboratory/id/number"/>&#160;<xsl:if test="$showanswers='yes'">Sample Answers</xsl:if>: <xsl:apply-templates select="/laboratory/title"/>
					</xsl:if>
				</TITLE>
			</HEAD>
			<BODY>
				<H1>
					<!-- testing
					<xsl:value-of select="name(child::node()[1])"/>
					-->
					<xsl:if test="name(child::node()[1])='tutorial'">
					INFO&#160;321 Tutorial <xsl:value-of select="/tutorial/id/number"/>&#160;<xsl:if test="$showanswers='yes'">Sample Answers</xsl:if>: <BR/><xsl:apply-templates select="/tutorial/title"/>
					</xsl:if>
					
					<xsl:if test="name(child::node()[1])='laboratory'">
					INFO&#160;321 Laboratory <xsl:value-of select="/laboratory/id/number"/>&#160;<xsl:if test="$showanswers='yes'">Sample Answers</xsl:if>: <BR/><xsl:apply-templates select="/laboratory/title"/>
					</xsl:if>
				</H1>

				<!-- Laziness: -->
				<xsl:apply-templates select="/tutorial/introduction"/>
				<xsl:apply-templates select="/laboratory/introduction"/>

				<xsl:for-each select="/tutorial/section">
					<xsl:apply-templates/>
				</xsl:for-each>

				<xsl:for-each select="/laboratory/section">
					<xsl:apply-templates/>
				</xsl:for-each>

				<ADDRESS>
					<xsl:apply-templates select="//id/cvs-id"/>
				</ADDRESS>
			</BODY>
		</HTML>
	</xsl:template>
</xsl:stylesheet>