- Added new mechanism for better handling of assignment due dates.
- Made more consistent use of xsl:text.
1 parent afa0201 commit 4bf6af11c3e95291f5319d632b755670cc0a306f
nstanger authored on 24 Apr 2012
Showing 3 changed files
View
67
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).
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.
<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 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:value-of select="/document/due-date" />
<!-- 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:value-of select="/document/due-date" />
<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:value-of select="/document/due-date" />
</common>
</template>
 
 
</stylesheet>
View
85
modules/titling.xml
</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>
<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/">\date{<xsl:apply-templates />}</common>
</template>
<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. -->
</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.
View
4
xml2xslt.xsl
<xsl-out:apply-templates select="title" mode="preamble" />
<xsl-out:call-template name="newline-internal" />
<xsl-out:apply-templates select="author" mode="preamble" />
<xsl-out:call-template name="newline-internal" />
<xsl-out:apply-templates select="date" mode="preamble" />
<xsl-out:apply-templates select="date|due-date" mode="preamble" />
<xsl-out:call-template name="newline-internal" />
 
<xsl-out:text>
\begin{document}
<xsl:copy-of select="common[not(@formats)]/node()" />
<!-- Copy across code that is specific to the current format. -->
<xsl:copy-of select="common[contains(@formats, concat('/', $target-format, '/'))]/node()" />
<xsl:copy-of select="*[name(.)=$target-format]/node()" />
<xsl:copy-of select="*[name(.) = $target-format]/node()" />
</xsl-out:template>
</xsl:template>