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

<!--
	Various "global" elements that are frequently used across all documents. Some are passed in as arguments to the stylesheet (e.g., paper number), while others are things that don't change that often, and are thus hard coded (e.g., Oracle version). One or two are dynamic, based on elements within the document (e.g., the due date for an assignment).
	
	The "strip" mode forms of the templates are for use in the context of an HTML <title> element (so the mode is only relevant to the HTML formats). Embedding HTML markup inside the <title> element causes the markup to appear verbatim in the window title, i.e., <title><em>foo</em> bar</title> will appear in the window title as "<em>foo</em> bar", not "foo bar". Putting the stylesheet into strip mode means that it will only output text nodes unless otherwise specified for a particular element. Generally the "strip" templates will simply call-template to the original, unless the original contains markup that needs to be eliminated (e.g., see OracleServer below).
	
	The downside of this approach, of course, is that you need "strip" mode templates for quite a lot of things, but that can't really be helped.
-->

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

	<!--
		Subject code (e.g., "INFO").
	-->
	<template name="SubjectCode" match="SubjectCode">
		<common>
			<xsl:value-of select="$subject-code" />
		</common>
	</template>

	<template name="SubjectCode-strip" match="SubjectCode" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="SubjectCode" />
		</common>
	</template>

	<!--
		Paper number (e.g., "212").
	-->
	<template name="PaperNumber" match="PaperNumber">
		<common>
			<xsl:value-of select="$paper-number" />
		</common>
	</template>

	<template name="PaperNumber-strip" match="PaperNumber" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="PaperNumber" />
		</common>
	</template>

	<!--
		Complete paper code (e.g., "INFO 212").
	-->
	<template name="PaperCode" match="PaperCode">
		<common>
			<xsl:value-of select="$subject-code" />
			<xsl:text> </xsl:text>
			<xsl:value-of select="$paper-number" />
		</common>
	</template>

	<template name="PaperCode-strip" match="PaperCode" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="PaperCode" />
		</common>
	</template>
	
	<!--
		Year in which the paper is offered, plus or minus some offset.
		
		@offset: Output the year +/- some integer value. The input value is truncated and defaults to zero if not supplied.
	-->
	<template name="PaperYear" match="PaperYear">
		<common>
			<xsl:variable name="add" as="xs:integer">
				<xsl:value-of select="if ( @offset ) then floor( @offset ) else 0" />
			</xsl:variable>
			<!--
				It appears that we need an explicit type cast for $paper-year to keep everyone happy?!?! Even if you declare $paper-year to be xs:integer, XML Exchanger Editor still thinks you can't add a string ($paper-year) to an integer ($add). Stupid.
			-->
			<xsl:value-of select="xs:integer( $paper-year ) + $add" />
		</common>
	</template>

	<template name="PaperYear-strip" match="PaperYear" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="PaperYear" />
		</common>
	</template>

	<!--
		Period in which a paper is offered (e.g., "Semester 2").
	-->
	<template name="PaperPeriod" match="PaperPeriod">
		<common>
			<xsl:value-of select="$period-string" />
		</common>
	</template>

	<template name="PaperPeriod-strip" match="PaperPeriod" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="PaperPeriod" />
		</common>
	</template>

	<!--
		The name of the currently used Oracle server.
	-->
	<template name="OracleServer" match="OracleServer">
		<common formats="/latex/xelatex/">Oracle11\textit{g}</common>
		<common formats="/html/xhtml/">Oracle11<i>g</i></common>
	</template>

	<template name="OracleServer-strip" match="OracleServer" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:text>Oracle11g</xsl:text>
		</common>
	</template>

	<!--
		The release number of the currently used Oracle server.
	-->
	<template name="OracleServerRelease" match="OracleServerRelease">
		<common>2</common>
	</template>

	<template name="OracleServerRelease-strip" match="OracleServerRelease" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="OracleServerRelease" />
		</common>
	</template>

	<!--
		The version number of the currently used Oracle server.
	-->
	<template name="OracleServerVersion" match="OracleServerVersion">
		<common>11.2</common>
	</template>

	<template name="OracleServerVersion-strip" match="OracleServerVersion" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="OracleServerVersion" />
		</common>
	</template>

	<!--
		A link to Blackboard.
	-->
	<template name="Blackboard" match="Blackboard">
		<common>
		    <xsl:variable name="BlackboardLink">
		        <xsl:element name="hyperlink">
		            <xsl:attribute name="url">
		                <xsl:text>https://blackboard.otago.ac.nz/</xsl:text>
		            </xsl:attribute>
		            <xsl:text>Blackboard</xsl:text>
		        </xsl:element>
		    </xsl:variable>
			<xsl:apply-templates select="$BlackboardLink" />
		</common>
	</template>

	<template name="Blackboard-strip" match="Blackboard" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:text>Blackboard</xsl:text>
		</common>
	</template>
	
	<!--
		Assignment due date. Obviously this is only relevant if /document/@class is "assignment". The code seems a little inelegant, but there isn't really any other way to do it.
		
		@style: Additional formatting to apply to the due date when displayed. It should be a delimited list (it doesn't really matter what the delimiter is) containing one or more of the following values: "bold", "italic", "underline". Anything unrecognised is ignored.
	-->
	<template name="DueDate" match="DueDate">
		<common>
			<!-- There must be a due-date element for this to work! -->
			<xsl:if test="not( /document/due-date )">
				<xsl:message terminate="yes">The due date for this assignment has not been specified (use /document/due-date).</xsl:message>
			</xsl:if>
		</common>
		<common formats="/latex/xelatex/">
			<xsl:if test="contains( @style, 'bold' )">
				<xsl:text>\textbf{</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'italic' )">
				<xsl:text>\emph{</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'underline' )">
				<xsl:text>\underline{</xsl:text>
			</xsl:if>
			<xsl:apply-templates select="/document/due-date" mode="inline" />
			<!-- It doesn't actually matter in what order we generate the closing braces. -->
			<xsl:if test="contains( @style, 'underline' )">
				<xsl:text>}</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'italic' )">
				<xsl:text>}</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'bold' )">
				<xsl:text>}</xsl:text>
			</xsl:if>
		</common>
		<common formats="/html/xhtml/">
			<!--
				Unfortunately, we have to generate the formatting elements as raw text rather than proper elements because otherwise the XSLT code would not be well-formed.
			-->
			<xsl:if test="contains( @style, 'bold' )">
				<xsl:text disable-output-escaping="yes">&lt;strong&gt;</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'italic' )">
				<xsl:text disable-output-escaping="yes">&lt;em&gt;</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'underline' )">
				<xsl:text disable-output-escaping="yes">&lt;ul&gt;</xsl:text>
			</xsl:if>
			<xsl:apply-templates select="/document/due-date" mode="inline" />
			<xsl:if test="contains( @style, 'underline' )">
			<!-- We must close the elements in the correct order! -->
				<xsl:text disable-output-escaping="yes">&lt;/ul&gt;</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'italic' )">
				<xsl:text disable-output-escaping="yes">&lt;/em&gt;</xsl:text>
			</xsl:if>
			<xsl:if test="contains( @style, 'bold' )">
				<xsl:text disable-output-escaping="yes">&lt;/strong&gt;</xsl:text>
			</xsl:if>
		</common>
	</template>
	
	<!--
		It seems pretty unlikely that someone will want to put the due date in the HTML document title, but I'm paranoid :).
	-->
	<template name="DueDate-strip" match="DueDate" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:apply-templates select="/document/due-date" mode="inline" />
		</common>
	</template>

	<!--
		Sequence number for the document. Obviously there must be a sequence-number attribute in the document element for this to work!
	-->
	<template name="SequenceNumber" match="SequenceNumber">
		<common>
			<xsl:if test="not( /document/@sequence-number )">
				<xsl:message terminate="yes">The sequence number for this document has not been specified (use /document/@sequence-number).</xsl:message>
			</xsl:if>
		    <xsl:value-of select="/document/@sequence-number" />
		</common>
	</template>


</stylesheet>