Newer
Older
XML / modules / titling.xml
<?xml version="1.0" encoding="utf-8"?>

<!--
	Elements for generating "titling" components, such as title, author, date, in various contexts.
-->

<stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


	<!-- Items appearing in the document "preamble", i.e., the preamble section in LaTeX and the <head> element in HTML. -->
	
	<!-- Document title. -->
	<template name="preamble-title" match="document/title" mode="preamble">
		<common formats="/latex/xelatex/">
			<xsl:text>\title{</xsl:text>
			<xsl:if test="/document/@class = 'assignment'">
				<xsl:if test="$showanswers='yes'">Sample Solution for </xsl:if>
				<xsl:call-template name="PaperCode" />
				<xsl:text> Assignment </xsl:text>
				<xsl:value-of select="/document/@sequence-number" />
				<xsl:text>: \\</xsl:text>
			</xsl:if>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<!--
			For the HTML title, strip out any markup (e.g., emphasis), as this is not interpreted within the <title> tag, resulting in raw HTML markup in the window title. Ick. We do this by switching to "strip" mode.
		-->
		<common formats="/html/xhtml/">
			<xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )">
				<xsl:if test="$showanswers='yes'">
					<xsl:choose>
						<xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )">
							<xsl:text>Selected Answers for </xsl:text>
						</xsl:when>
						<xsl:when test="/document/@class = 'assignment'">
							<xsl:text>Sample Solution for </xsl:text>
						</xsl:when>
					</xsl:choose>
				</xsl:if>
				<xsl:call-template name="PaperCode" />
				<xsl:choose>
					<xsl:when test="/document/@class = 'tutorial'">
						<xsl:text> Tutorial </xsl:text>
					</xsl:when>
					<xsl:when test="/document/@class = 'laboratory'">
						<xsl:text> Lab </xsl:text>
					</xsl:when>
					<xsl:when test="/document/@class = 'assignment'">
						<xsl:text> Assignment </xsl:text>
					</xsl:when>
				</xsl:choose>
				<xsl:value-of select="/document/@sequence-number" />
				<xsl:text>: </xsl:text>
			</xsl:if>
			<xsl:apply-templates mode="strip" />
		</common>
	</template>

	<!-- Document author. This only makes sense for LaTeX. -->
	<template name="preamble-author" match="document/author" mode="preamble">
		<common formats="/latex/xelatex/">\author{<xsl:apply-templates />}</common>
	</template>

	<!-- Document date. This only makes sense for LaTeX. -->
	<template name="preamble-date" match="document/date" mode="preamble">
		<common formats="/latex/xelatex/">\date{<xsl:apply-templates />}</common>
	</template>
	

	<!-- Items appearing in the document body. -->
	
	<!-- Document title. -->
	<template name="document-title" match="document/title">
		<!-- Need to do something sensible for LaTeX here. -->
		<common formats="/latex/xelatex/">
			<!--
				Under the LaTeX framework, the rest of the chapter title text is generated by LaTeX macros, so this is pretty simple. I think this is broken?
				
				In fact, I think that for LaTeX documents, this template isn't called at all?? Looking at xml2xslt.xsl, if the document is standalone, "preamble-title" is used, and otherwise, "chapter-title" is used.
			-->
			<xsl:if test="/document/@standalone = 'yes'"><xsl:apply-templates /></xsl:if>
		</common>
		<common formats="/html/xhtml/">
			<h1>
				<xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )">
					<xsl:if test="$showanswers='yes'">
						<xsl:choose>
							<xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )">
								<xsl:text>Selected Answers for </xsl:text>
							</xsl:when>
							<xsl:when test="/document/@class = 'assignment'">
								<xsl:text>Sample Solution for </xsl:text>
							</xsl:when>
						</xsl:choose>
					</xsl:if>
					<xsl:call-template name="PaperCode" />
					<xsl:choose>
						<xsl:when test="/document/@class = 'tutorial'">
							<xsl:text> Tutorial </xsl:text>
						</xsl:when>
						<xsl:when test="/document/@class = 'laboratory'">
							<xsl:text> Lab </xsl:text>
						</xsl:when>
						<xsl:when test="/document/@class = 'assignment'">
							<xsl:text> Assignment </xsl:text>
						</xsl:when>
					</xsl:choose>
					<xsl:value-of select="/document/@sequence-number" />
					<xsl:text>: </xsl:text>
				</xsl:if>
				<xsl:apply-templates />
			</h1>
		</common>
	</template>

	<!-- Document author. -->
	<template name="document-author" match="document/author">
		<common formats="/html/xhtml/"><p><xsl:apply-templates /></p></common>
	</template>
	
	<!-- Document date. -->
	<template name="document-date" match="document/date" />
	

	<!--
		Chapter titles for tutorials and labs, which are essentially chapters when included in a course book, but are marked up as documents in themselves.
	-->
	<template name="chapter-title" match="document/title" mode="chapter">
		<!--
			TODO: For LaTeX, filling in the "INFO XXX Tutorial", etc., is currently done in the LaTeX layer in the infrastructure (coursehandbook.cls) surrounding the \lab and \tutorial macros (i.e., it's magic). This derives from the historical origins of the handbook, and should be moved here for consistency. An initial attempt to just replace calls to \tutorial, etc., with \chapter didn't work properly, as the \tutorial, etc., macros do other things as well, including internal munging of chapter handling. This Will Be Complicated :(.
		-->
		<common formats="/latex/xelatex/">
			<xsl:choose>
				<xsl:when test="/document/@class = 'tutorial'">
					<xsl:text>\tutorial{</xsl:text>
				</xsl:when>
				<xsl:when test="/document/@class = 'laboratory'">
					<xsl:text>\lab{</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<!-- maybe we should assume that we're in a book documentclass and issue a \chapter here? -->
					<xsl:text>\general{</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:choose>
				<xsl:when test="/document/@class = 'tutorial'">
					<h1><xsl:call-template name="PaperCode" /> Tutorial <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1>
				</xsl:when>
				<xsl:when test="/document/@class = 'laboratory'">
					<h1><xsl:call-template name="PaperCode" /> Lab <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1>
				</xsl:when>
				<xsl:otherwise>
					<h1><xsl:apply-templates /></h1>
				</xsl:otherwise>
			</xsl:choose>
		</common>
	</template>
	

</stylesheet>