Newer
Older
XML / format-master.xml
nstanger on 11 Dec 2003 12 KB - Added basic table processing.
<?xml version="1.0"?>
<!-- This will mostly be a list of element names to match, along with the corresponding HTML and LaTeX handling XSLT code. -->
<stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<hyperlink>
		<element>OraAdmin</element>
		<url>http://info-nts-05.otago.ac.nz/docs/oracle9i/server.920/a96521/toc.htm</url>
		<label>test<!--<xsl:call-template name="OracleServer"/> Database Administrator<xsl:call-template name="apostrophe"/>s Guide--></label>
	</hyperlink>

	<template name="PaperCode" match="PaperCode">
		<latex><xsl:text>{\PaperCode}</xsl:text></latex>
		<html>INFO&#160;321</html>
	</template>

	<template name="OracleServer" match="OracleServer">
		<latex><xsl:text>{\OracleServer}</xsl:text></latex>
		<html>Oracle9<I>i</I></html></template>


	<template name="paragraph" match="paragraph">
		<latex><xsl:text>


</xsl:text><xsl:apply-templates/><xsl:text>
	
		
</xsl:text></latex>
		<!-- 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 one option might simply be not to output it. -->
		<html><P><xsl:apply-templates/></P></html>
	</template>
	<alias source="para" target="paragraph"/>
	<alias source="p" target="paragraph"/>
	
	
	<!-- 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! -->
	<template name="newline" match="newline"><latex>
</latex><html><BR/></html></template>
<template name="non-breaking-space" match="non-breaking-space"><latex>~</latex><html>&#160;</html></template>	
<alias source="nbsp" target="non-breaking-space"/>

	<template name="ellipsis-sign" match="ellipsis-sign">	<latex><xsl:text>{\ldots}</xsl:text></latex>	<html><xsl:text>&#8230;</xsl:text></html></template>
	
	<alias source="etc" target="ellipsis-sign"/>
	<alias source="ellipsis" target="ellipsis-sign"/>

	<!-- Misc typographic symbols -->
	<template name="endash" match="endash">				<latex><xsl:text>--</xsl:text></latex>			<html><xsl:text>&#8211;</xsl:text></html></template>
	<alias source="en-dash" target="endash"/>
	<template name="emdash" match="emdash">				<latex><xsl:text>---</xsl:text></latex>			<html><xsl:text>&#8212;</xsl:text></html></template>
	<alias source="em-dash" target="emdash"/>
	<template name="apostrophe" match="apostrophe">		<latex><xsl:text>'</xsl:text></latex>			<html><xsl:text>&#8217;</xsl:text></html></template>
	<template name="dollar" match="dollar">				<latex><xsl:text>\$</xsl:text></latex>			<html><xsl:text>$</xsl:text></html></template>
	<template name="percent-sign" match="percent-sign">	<latex><xsl:text>\%</xsl:text></latex>			<html><xsl:text>%</xsl:text></html></template>
	<template name="ampersand" match="ampersand">		<latex><xsl:text>\&amp;</xsl:text></latex>		<html><xsl:text>&amp;</xsl:text></html></template>
	<template name="trademark-sign" match="trademark-sign">		<latex><xsl:text>(TM)</xsl:text></latex>		<html><xsl:text>&#8482;</xsl:text></html></template>
	<alias source="trademark" target="trademark-sign"/>
	<template name="copyright-sign" match="copyright-sign">	<latex><xsl:text>\copyright</xsl:text></latex>		<html><xsl:text>&#169;</xsl:text></html></template>
	<!--	<alias source="copyright" target="copyright-sign"/> -->
	<template name="degree-sign" match="degree-sign">	<latex><xsl:text>deg</xsl:text></latex>			<html><xsl:text>&#176;</xsl:text></html></template>
	<template name="section-sign" match="section-sign">	<latex><xsl:text>{\S}</xsl:text></latex>		<html><xsl:text>&#167;</xsl:text></html></template>
	<template name="paragraph-sign" match="paragraph-sign">	<latex><xsl:text>{\P}</xsl:text></latex>	<html><xsl:text>&#182;</xsl:text></html></template>
	<template name="pi" match="pi">						<latex><xsl:text>{\pi}</xsl:text></latex>		<html><xsl:text>&#960;</xsl:text></html></template>
	<template name="LaTeX" match="LaTeX">				<latex><xsl:text>{\latex}</xsl:text></latex>	<html><xsl:text>LaTeX</xsl:text></html></template>
	<alias source="latex" target="LaTeX"/>

	<!-- Special styles -->
	<template name="emph" match="emph"><latex><xsl:text>\emph{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text></latex><html><EM><xsl:apply-templates/></EM></html></template>
	<template name="italic" match="italic"><latex><xsl:text>\textit{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text></latex><html><I><xsl:apply-templates/></I></html></template>
	<template name="quote" match="quote"><latex><xsl:text>``{</xsl:text><xsl:apply-templates/><xsl:text>}''</xsl:text></latex><html><xsl:text>&#8220;</xsl:text><xsl:apply-templates/><xsl:text>&#8221;</xsl:text></html></template>
	<template name="term" match="term"><latex>\term<xsl:apply-templates/>}</latex><html><I CLASS="term"><xsl:apply-templates/></I></html></template>
	<template name="foreign" match="foreign"><latex><xsl:text>\foreign{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text></latex><html><I CLASS="foreign"><xsl:apply-templates/></I></html></template>
	<template name="code" match="code">
		<latex><xsl:text>\code{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text></latex>
		<html><CODE><xsl:apply-templates/></CODE></html>
	</template>

	<template name="code-block" match="code-block">
		<latex>
			<xsl:text>\begin{verbatim}</xsl:text>
				<xsl:apply-templates/>
			<xsl:text>\end{verbatim}</xsl:text>
		</latex>
		<html>
			<PRE CLASS="code"><xsl:apply-templates/></PRE>
		</html>
	</template>
	
	<!-- Environments (in the LaTeX terminology): enumerated, ordered, and numbered lists. -->

	<!-- Unordered lists -->
	
	<template name="itemised-list" match="itemised-list">
		<latex>
			\begin{itemize}
			<xsl:apply-templates/>
			\end{itemize}
		</latex>
		<html>
			<UL>
				<xsl:apply-templates/>
			</UL>
		</html>
	</template>
	
	<alias source="itemize" target="itemised-list"/>
	<alias source="unordered-list" target="itemised-list"/>
	<alias source="bulleted-list" target="itemised-list"/>
	<alias source="bullet-list" target="itemised-list"/>
	<alias source="bullet-points" target="itemised-list"/>


	<!-- Ordered lists -->
	
	<template name="enumerated-list" match="enumerated-list">
		<latex><xsl:text>
			\begin{enumerate}
				<xsl:apply-templates/>
			\end{enumerate}
		</xsl:text></latex>
		<html>
			<OL>
				<xsl:apply-templates/>
			</OL>
		</html>
	</template>

	<alias source="enumerate" target="enumerated-list"/>
	<alias source="ordered-list" target="enumerated-list"/>
	<alias source="numbered-list" target="enumerated-list"/>
	
	
	<!-- Definition or description lists. -->
	<template name="definition-list" match="definition-list">
		<latex><xsl:text>
			\begin{description}
				<xsl:apply-templates/>
			\end{description}
		</xsl:text></latex>
		<html>
			<DL>
				<xsl:apply-templates/>
			</DL>
		</html>
	</template>
	
	<alias source="description-list" target="definition-list"/>


	<!-- List elements -->
	<template name="item" match="item">
		<latex><xsl:text>\item </xsl:text><xsl:apply-templates/></latex>
		<html><LI><xsl:apply-templates/></LI></html>
	</template>

	<template name="definition-item" match="definition-list/item">
		<latex><xsl:text>\item[</xsl:text><xsl:apply-templates select="keyword"/><xsl:text>]</xsl:text> <xsl:apply-templates select="definition"/></latex>
		<html>
			<DT><xsl:apply-templates select="keyword"/></DT>
			<DD><xsl:apply-templates select="definition"/></DD>
		</html>
	</template>
	
	<template name="keyword" match="keyword">
		<latex><xsl:apply-templates/></latex>
		<html><STRONG><xsl:apply-templates/></STRONG></html>
	</template>
	
	<template name="definition" match="definition">
		<latex><xsl:apply-templates/></latex>
		<html><xsl:apply-templates/></html>
	</template>
	
	<alias source="topic" target="keyword"/>
	<alias source="description" target="definition"/>
	<alias source="discourse" target="definition"/>
	
	
	<!-- Sections, subsections, subsubsections, ... -->
	<template name="section" match="section">
		<latex>
			<xsl:apply-templates/>
		</latex>
		<html>
			<xsl:apply-templates/>
		</html>
	</template>

	<!--
		Generate some number of "sub" so we can produce, e.g., "subsubsection"
		for LaTeX.
		
		Parameter: $depth
		Meaning: the number of repetitions (normally <= 2)
	-->
	<template name="generate-subs">
		<latex>
			<xsl:param name="depth">0</xsl:param>
			<xsl:if test="$depth &gt; 0">
				<xsl:text>sub</xsl:text>
				<xsl:call-template select="generate-subs">
					<xsl:with-param><xsl:value-of select="$depth - 1"/></xsl:with-param>
				</xsl:call-template>
			</xsl:if>
		</latex>
	</template>
	
	<template name="window-title" match="document/title" mode="window-title">
		<html>
			<xsl:apply-templates/>
		</html>
	</template>

	<template name="document-title" match="document/title">
	<!-- Need to do something sensible for LaTeX here. -->
<!-- 		<latex><xsl:apply-templates/></latex> -->
		<html>
			<H1><xsl:apply-templates/></H1>
		</html>
	</template>

	<template name="section-title" match="section/title">
		<latex>
			<xsl:text>\</xsl:text>
			<!-- Depth calculation for LaTeX hasn't been tested! -->
			<xsl:call-template name="generate-subs">
				<xsl:with-param name="depth">
					<xsl:number value="count(ancestor::section)"/>
					<xsl:if test="count(ancestor::section) > 2">2</xsl:if>
				</xsl:with-param>
			</xsl:call-template>
			<xsl:text>section</xsl:text>
			<xsl:apply-templates/><xsl:text>}

</xsl:text></latex>
		<html>
			<xsl:variable name="depth">
				<xsl:number value="1 + count(ancestor::section)"/>
				<xsl:if test="1 + count(ancestor::section) &gt; 6">6</xsl:if>
			</xsl:variable>
			<xsl:text disable-output-escaping="yes">&lt;H</xsl:text><xsl:number value="$depth"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
			<xsl:number count="section" level="multiple" format="1.1.1.1.1.1"/>
			<xsl:text> </xsl:text>
			<xsl:apply-templates/>
			<xsl:text disable-output-escaping="yes">&lt;/H</xsl:text><xsl:number value="$depth"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
		</html>
	</template>


	<!-- A quotation. -->
	<template name="quotation" match="quotation">
		<latex>\begin{flushright}\itshape <xsl:apply-templates/>\end{flushright}</latex>
		<html>
			<P align="right"><I><xsl:apply-templates/></I></P>
		</html>
	</template>
	
	
	<!--
		Anything inside an ID element is ignored completely. (More accurately,
		we pick bits out of it manually as required; it's only ignored by
		apply-templates.)
	-->
	<template name="id" match="id"/>
	
	
	<!--
		Anything inside an OMIT element is also ignored completely.
	-->
	<template name="omit" match="omit"/>
	
	
	<!-- Tables (equivalent to a tabular in LaTeX terms). -->
	<template name="table" match="table">
		<latex></latex>
		<html>
			<TABLE>
				<xsl:attribute name="BORDER">
					<xsl:value-of select="@border"/>
					<xsl:if test="not(@border)">0</xsl:if>
				</xsl:attribute>
				<xsl:apply-templates/>
			</TABLE>
		</html>
	</template>
	
	<template name="table-body" match="table-body">
		<latex></latex>
		<html>
			<TBODY>
				<xsl:apply-templates/>
			</TBODY>
		</html>
	</template>

	<template name="row" match="row">
		<latex></latex>
		<html>
			<TR>
				<xsl:apply-templates/>
			</TR>
		</html>
	</template>

	<template name="cell" match="cell">
		<latex></latex>
		<html>
			<xsl:variable name="column-no">
				<xsl:number/>
			</xsl:variable>
			<TD>
				<xsl:attribute name="ALIGN">
					<xsl:value-of select="ancestor::table/columns/column[position()=$column-no]/@align"/>
					<xsl:if test="not(ancestor::table/columns/column[position()=$column-no]/@align)">left</xsl:if>
				</xsl:attribute>
				<xsl:attribute name="COLSPAN">
					<xsl:value-of select="@columns"/>
					<xsl:if test="not(@columns)">1</xsl:if>
				</xsl:attribute>
				<xsl:attribute name="ROWSPAN">
					<xsl:value-of select="@rows"/>
					<xsl:if test="not(@rows)">1</xsl:if>
				</xsl:attribute>
				<xsl:apply-templates/>
			</TD>
		</html>
	</template>


</stylesheet>