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>
			<!--
				Note that tutorials and labs have their own special macros, which is why they're not included here (see the TODO in the "chapter-title" template below).
			-->
			<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/">
			<xsl:text>\author{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
	</template>

	<!-- Document date. This only makes sense for LaTeX. -->
	<template name="preamble-date" match="document/date" mode="preamble">
		<common formats="/latex/xelatex/">
			<xsl:text>\date{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
	</template>
	
	<!-- Assignment due date. This only makes sense for assignments in LaTeX. -->
	<template name="preamble-due-date" match="document/due-date" mode="preamble">
		<common formats="/latex/xelatex/">
			<xsl:if test="/document/@class != 'assignment'">
				<xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment".</xsl:message>
			</xsl:if>
			<xsl:if test="/document/date">
				<xsl:message terminate="yes">You can't include both a due-date and a date element in an assignment.</xsl:message>
			</xsl:if>
			<xsl:choose>
				<xsl:when test="/document/author">
					<xsl:text>\date{DUE DATE: </xsl:text>
					<xsl:apply-templates />
					<xsl:text>}</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>\author{DUE DATE: </xsl:text>
					<xsl:apply-templates />
					<xsl:text>}</xsl:text>
					<xsl:text>\date{}</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</common>
	</template>
	

	<!-- Items appearing in the document body. -->
	
	<!-- Document title. -->
	<template name="document-title" match="document/title">
		<!--
			This template is irrelevant for LaTeX, as the document title is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl).
		-->
		<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" />
	
	<!-- Assignment due date. This only makes sense for assignments. -->
	<template name="document-due-date" match="document/due-date">
		<common formats="/html/xhtml/">
			<xsl:if test="/document/@class != 'assignment'">
				<xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment".</xsl:message>
			</xsl:if>
			<p>
				<xsl:text>DUE DATE: </xsl:text>
				<xsl:value-of select="." />
			</p>
		</common>
	</template>
	

	<!--
		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>