GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
1
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
nigel.stanger
/
XML
Browse code
• Added support for question sets to (X)HTML as well (oops).
master
1 parent
71eb2a5
commit
8733b0da66368bf6fc8d527f1c46b1f6d02f84e9
Nigel Stanger
authored
on 19 Jul 2016
Patch
Showing
1 changed file
modules/titling.xml
Ignore Space
Show notes
View
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="index-of(('assignment', 'project', 'question set'), /document/@class)"> <xsl:if test="$showanswers='yes'">Sample Solution for </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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() and (/document/@class != 'question set')"> <xsl:text>: \\</xsl:text> </xsl:if> </xsl:if> <xsl:apply-templates /> <!-- Process the subtitle, if any. If there is no author specified, then we can appropriate the \author, otherwise, append it to the main title. --> <xsl:if test="/document/subtitle and /document/author"> <xsl:text>\\[0.25\baselineskip] \large </xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> </xsl:if> <xsl:text>}</xsl:text> <xsl:if test="/document/subtitle and not( /document/author )"> <xsl:text>\author{</xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> <xsl:text>}</xsl:text> </xsl:if> </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="index-of(('tutorial', 'laboratory', 'assignment', 'project', 'question set'), /document/@class)"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="index-of(('tutorial', 'laboratory'), /document/@class)"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="index-of(('assignment', 'project', 'question set'), /document/@class)"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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() and (/document/@class != 'question set')"> <xsl:text>: </xsl:text> </xsl:if> </xsl:if> <xsl:apply-templates mode="strip" /> </common> </template> <!-- Document subtitle. This template exists only to trap the general apply-templates and prevent the subtitle being output twice. The actual processing of this element (for LaTeX only) is done in the preamble-title template above. --> <template name="preamble-subtitle" match="document/subtitle" mode="preamble" /> <!-- 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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</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="index-of(('tutorial', 'laboratory', 'assignment', 'project', 'question set'), /document/@class)"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="index-of(('tutorial', 'laboratory'), /document/@class)"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="index-of(('assignment', 'project', 'question set'), /document/@class)"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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() and (/document/@class != 'question set')"> <xsl:text>: </xsl:text> </xsl:if> </xsl:if> <xsl:apply-templates /> <!-- If there’s a subtitle, add it to the end of the title. --> <xsl:if test="/document/subtitle"> <xsl:text>: </xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> </xsl:if> </h1> </common> </template> <!-- Document subtitle. This template exists only to catch any embdedded markup within the subtitle. Note that this is also used by the LaTeX preamble above. --> <template name="document-subtitle-title" match="document/subtitle" mode="title"> <common> <xsl:apply-templates /> </common> </template> <!-- This template exists only to trap the general apply-templates and prevent the subtitle being output twice. The actual processing of this element is done in the document-title template above. --> <template name="document-subtitle-unmoded" match="document/subtitle" /> <!-- Document author. --> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"> <p> <xsl:apply-templates /> </p> </common> </template> <!-- Document date at the start of an (X)HTML document. This is irrelevant for (Xe)LaTeX, as the (title) date is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). --> <template name="document-date-title" match="document/date" mode="title"> <common formats="/html/xhtml/"> <p><xsl:apply-templates /></p> </common> </template> <!-- 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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</xsl:message> </xsl:if> <xsl:apply-templates /> </common> </template> <!-- Empty templates to catch any un-moded attempts to process the date, due date or title. --> <template name="document-due-date-unmoded" match="document/due-date" /> <template name="document-title-unmoded" match="document/title" /> <template name="document-date-unmoded" 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>
<?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="index-of(('assignment', 'project', 'question set'), /document/@class)"> <xsl:if test="$showanswers='yes'">Sample Solution for </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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() and (/document/@class != 'question set')"> <xsl:text>: \\</xsl:text> </xsl:if> </xsl:if> <xsl:apply-templates /> <!-- Process the subtitle, if any. If there is no author specified, then we can appropriate the \author, otherwise, append it to the main title. --> <xsl:if test="/document/subtitle and /document/author"> <xsl:text>\\[0.25\baselineskip] \large </xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> </xsl:if> <xsl:text>}</xsl:text> <xsl:if test="/document/subtitle and not( /document/author )"> <xsl:text>\author{</xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> <xsl:text>}</xsl:text> </xsl:if> </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="index-of(('tutorial', 'laboratory', 'assignment', 'project'), /document/@class)"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="index-of(('tutorial', 'laboratory'), /document/@class)"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="index-of(('assignment', 'project'), /document/@class)"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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 mode="strip" /> </common> </template> <!-- Document subtitle. This template exists only to trap the general apply-templates and prevent the subtitle being output twice. The actual processing of this element (for LaTeX only) is done in the preamble-title template above. --> <template name="preamble-subtitle" match="document/subtitle" mode="preamble" /> <!-- 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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</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="index-of(('tutorial', 'laboratory', 'assignment', 'project'), /document/@class)"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="index-of(('tutorial', 'laboratory'), /document/@class)"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="index-of(('assignment', 'project'), /document/@class)"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> </xsl:text> <xsl:value-of select="infosci:title-case(/document/@class)" /> <xsl:text> </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 /> <!-- If there’s a subtitle, add it to the end of the title. --> <xsl:if test="/document/subtitle"> <xsl:text>: </xsl:text> <xsl:apply-templates select="/document/subtitle" mode="title" /> </xsl:if> </h1> </common> </template> <!-- Document subtitle. This template exists only to catch any embdedded markup within the subtitle. Note that this is also used by the LaTeX preamble above. --> <template name="document-subtitle-title" match="document/subtitle" mode="title"> <common> <xsl:apply-templates /> </common> </template> <!-- This template exists only to trap the general apply-templates and prevent the subtitle being output twice. The actual processing of this element is done in the document-title template above. --> <template name="document-subtitle-unmoded" match="document/subtitle" /> <!-- Document author. --> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"> <p> <xsl:apply-templates /> </p> </common> </template> <!-- Document date at the start of an (X)HTML document. This is irrelevant for (Xe)LaTeX, as the (title) date is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). --> <template name="document-date-title" match="document/date" mode="title"> <common formats="/html/xhtml/"> <p><xsl:apply-templates /></p> </common> </template> <!-- 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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</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="not(index-of(('assignment', 'project', 'question set'), /document/@class))"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment", "project", or "question set".</xsl:message> </xsl:if> <xsl:apply-templates /> </common> </template> <!-- Empty templates to catch any un-moded attempts to process the date, due date or title. --> <template name="document-due-date-unmoded" match="document/due-date" /> <template name="document-title-unmoded" match="document/title" /> <template name="document-date-unmoded" 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>
Show line notes below