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" />
				<!-- If the title's empty, there's no point in including the ": \\". -->
				<xsl:if test="node()">
					<xsl:text>: \\</xsl:text>
				</xsl:if>
			</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" />
				<!-- If the title's empty, there's no point in including the ": ". -->
				<xsl:if test="node()">
					<xsl:text>: </xsl:text>
				</xsl:if>
			</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 for an (X)HTML document. This template is irrelevant for LaTeX, as the document title is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). The title element is applied explicitly by xml2xslt.xsl, so we add a mode to ensure that this it isn't caught up by the following general apply-templates. Otherwise, the title would appear twice in the document body.
	-->
	<template name="document-title-title" match="document/title" mode="title">
		<!--
			
		-->
		<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" />
					<!-- If the title's empty, there's no point in including the ": ". -->
					<xsl:if test="node()">
						<xsl:text>: </xsl:text>
					</xsl:if>
				</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 (doesn't appear in normal body). -->
	<template name="document-date" match="document/date" />
	
	<!--
		Assignment due date at the start of an (X)HTML document. This is irrelevant for (Xe)LaTeX, as the (title) due date is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). This only makes sense for assignments.
	-->
	<template name="document-due-date-title" match="document/due-date" mode="title">
		<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:apply-templates />
			</p>
		</common>
	</template>
	
	<!--
		Assignment due date anywhere else in the main body of the document. We add the mode to avoid the due date being caught up by the top-level apply-templates and thus appearing as the first paragraph of the document body.
	-->
	<template name="document-due-date-inline" match="document/due-date" mode="inline">
		<common>
			<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:apply-templates />
		</common>
	</template>

	<!-- Empty template to catch any un-moded attempts to process the due date or title. -->
	<template name="document-due-date" match="document/due-date" />
	<template name="document-title" match="document/title" />
	

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