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
- Calendar templates now working apart from some (moderately complex to achieve)
formatting tweaks to cell borders in LaTeX output.
master
1 parent
d290b7a
commit
f6c8a0cd9b788a7d1c4521834fa566019a2d8d1f
nstanger
authored
on 15 Jun 2012
Patch
Showing
2 changed files
format-master.xml
modules/paper-calendar.xml
Ignore Space
Show notes
View
format-master.xml
<?xml version="1.0" encoding="utf-8"?> <!-- This will mostly be a list of element names to match, along with the corresponding HTML and LaTeX handling XSLT code. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- 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). --> <include href="modules/global-elements.xml" /> <!-- Output a string containing the date that the document was last built. --> <include href="modules/build-date.xml" /> <!-- Basic page layout elements: paragraphs, page breask, etc. --> <include href="modules/basic-page-elements.xml" /> <!-- Special characters. --> <include href="modules/special-characters.xml" /> <!-- Greek characters. --> <include href="modules/greek-characters.xml" /> <!-- Miscellaneous symbols. --> <include href="modules/miscellaneous-symbols.xml" /> <!-- Emoticons. --> <include href="modules/emoticons.xml" /> <!-- Mathematical operators and symbols. --> <include href="modules/mathematical-symbols.xml" /> <!-- Relational algebra operators. --> <include href="modules/relational-algebra.xml" /> <!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. --> <include href="modules/menus.xml" /> <!-- Basic text formatting (emphasis, bold, etc.). --> <include href="modules/basic-text-formatting.xml" /> <!-- Inline code and code blocks. --> <include href="modules/code-formatting.xml" /> <!-- Fonts and typefaces. --> <include href="modules/fonts.xml" /> <!-- Quoted text. --> <include href="modules/quotations.xml" /> <!-- Lists (itemised, enumerated, definition). --> <include href="modules/lists.xml" /> <!-- Obsolete items (in order to provide informative error messages). --> <include href="modules/obsolete.xml" /> <!-- Text of questions and sample answers. --> <include href="modules/q-and-a.xml" /> <!-- Footnotes. --> <include href="modules/footnotes.xml" /> <!-- "Titling" elements, e.g., title, author, date. --> <include href="modules/titling.xml" /> <!-- Sections, subsections, etc. --> <include href="modules/sectioning.xml" /> <!-- Meta-elements. --> <include href="modules/meta-elements.xml" /> <!-- Tabular structures (LaTeX {tabular}, HTML <table>). --> <include href="modules/tabular.xml" /> <!-- Hyperlinks. --> <include href="modules/hyperlinks.xml" /> <!-- Cross-references. --> <include href="modules/cross-references.xml" /> <!-- "Floating" items such as figures and tables. --> <include href="modules/floaters.xml" /> <!-- Images. --> <include href="modules/images.xml" /> <!-- Include other documents. --> <include href="modules/inclusions.xml" /> <!-- LaTeX-specific stuff. --> <include href="modules/latex.xml" /> <!-- Embedding raw LaTeX or HTML code. --> <include href="modules/native-code.xml" /> <!-- Conditional processing depending on the format. --> <include href="modules/conditional-processing.xml" /> <!-- Mathematics. --> <include href="modules/maths.xml" /> <!-- Otago-specific items. --> <include href="modules/otago-specific.xml" /> <!-- Multi-column page layouts. --> <include href="modules/multi-column.xml" /> <!-- Bibliographies and reference lists. --> <include href="modules/bibliography.xml" /> <!-- Format numbers. --> <include href="modules/number-formatting.xml" /> <!-- Paper calendar and teaching dates. --> <include href="modules/paper-calendar.xml" /> <include href="modules/paper-calendar-dates.xml" /> </stylesheet>
<?xml version="1.0" encoding="utf-8"?> <!-- This will mostly be a list of element names to match, along with the corresponding HTML and LaTeX handling XSLT code. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- 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). --> <include href="modules/global-elements.xml" /> <!-- Output a string containing the date that the document was last built. --> <include href="modules/build-date.xml" /> <!-- Basic page layout elements: paragraphs, page breask, etc. --> <include href="modules/basic-page-elements.xml" /> <!-- Special characters. --> <include href="modules/special-characters.xml" /> <!-- Greek characters. --> <include href="modules/greek-characters.xml" /> <!-- Miscellaneous symbols. --> <include href="modules/miscellaneous-symbols.xml" /> <!-- Emoticons. --> <include href="modules/emoticons.xml" /> <!-- Mathematical operators and symbols. --> <include href="modules/mathematical-symbols.xml" /> <!-- Relational algebra operators. --> <include href="modules/relational-algebra.xml" /> <!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. --> <include href="modules/menus.xml" /> <!-- Basic text formatting (emphasis, bold, etc.). --> <include href="modules/basic-text-formatting.xml" /> <!-- Inline code and code blocks. --> <include href="modules/code-formatting.xml" /> <!-- Fonts and typefaces. --> <include href="modules/fonts.xml" /> <!-- Quoted text. --> <include href="modules/quotations.xml" /> <!-- Lists (itemised, enumerated, definition). --> <include href="modules/lists.xml" /> <!-- Obsolete items (in order to provide informative error messages). --> <include href="modules/obsolete.xml" /> <!-- Text of questions and sample answers. --> <include href="modules/q-and-a.xml" /> <!-- Footnotes. --> <include href="modules/footnotes.xml" /> <!-- "Titling" elements, e.g., title, author, date. --> <include href="modules/titling.xml" /> <!-- Sections, subsections, etc. --> <include href="modules/sectioning.xml" /> <!-- Meta-elements. --> <include href="modules/meta-elements.xml" /> <!-- Tabular structures (LaTeX {tabular}, HTML <table>). --> <include href="modules/tabular.xml" /> <!-- Hyperlinks. --> <include href="modules/hyperlinks.xml" /> <!-- Cross-references. --> <include href="modules/cross-references.xml" /> <!-- "Floating" items such as figures and tables. --> <include href="modules/floaters.xml" /> <!-- Images. --> <include href="modules/images.xml" /> <!-- Include other documents. --> <include href="modules/inclusions.xml" /> <!-- LaTeX-specific stuff. --> <include href="modules/latex.xml" /> <!-- Embedding raw LaTeX or HTML code. --> <include href="modules/native-code.xml" /> <!-- Conditional processing depending on the format. --> <include href="modules/conditional-processing.xml" /> <!-- Mathematics. --> <include href="modules/maths.xml" /> <!-- Otago-specific items. --> <include href="modules/otago-specific.xml" /> <!-- Multi-column page layouts. --> <include href="modules/multi-column.xml" /> <!-- Bibliographies and reference lists. --> <include href="modules/bibliography.xml" /> <!-- Format numbers. --> <include href="modules/number-formatting.xml" /> <!-- Paper calendar and teaching dates. --> <!-- <include href="modules/paper_calendar.xml" /> --> <include href="modules/paper-calendar-dates.xml" /> </stylesheet>
Ignore Space
Show notes
View
modules/paper-calendar.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Elements for generating a teaching calendar for a paper. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- The top level calendar element. @number-of-weeks: The duration of the paper in weeks. [required] @lectures-per-week: The number of lectures per week in the paper. Each lecture is assumed to occupy exactly one row in the resulting table, so this effectively determines the number of rows in the resulting table that each week occupies. [required] --> <template match="calendar"> <common formats="/latex/xelatex/"> <xsl:if test="not( @number-of-weeks )"> <xsl:message terminate="yes"> <xsl:text>Required attribute "number-of-weeks" has not been supplied in calendar.</xsl:text> </xsl:message> </xsl:if> <xsl:if test="not( @lectures-per-week )"> <xsl:message terminate="yes"> <xsl:text>Required attribute "lectures-per-week" has not been supplied in calendar.</xsl:text> </xsl:message> </xsl:if> <!-- This is used in a few places to set the width of column cells, etc., that contain numbers. I can't remember why I decided to pick twice the number of weeks as the size, other than to ensure a decent spacing around the numbers? --> <xsl:text>\newlength{\numberwidth}</xsl:text> <xsl:text>\settowidth{\numberwidth}{</xsl:text> <xsl:number value="@number-of-weeks * 2" /> <xsl:text>}</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\begin{center}</xsl:text> <xsl:call-template name="newline-internal" /> <!-- TODO: Probably not if standalone! --> <xsl:text>\begin{sideways}</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\resizebox{24cm}{!}{%</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\begin{tabular}{|c|c|c|c|l|c|c|c|c|c|c|}</xsl:text> <xsl:call-template name="newline-internal" /> <!-- Calendar heading. We can't use generate-content-cell for this, because we're doing more complex processing of the cell contents than is possible with generate-content-cell. Here, we're calling three separate templates interspersed with text, whereas generate-content-cell can only accept a simple list of nodes to apply-templates to. --> <xsl:text>\multicolumn{11}{c}{\LARGE\textbf{</xsl:text> <xsl:call-template name="PaperCode" /> <xsl:text> Paper Calendar, </xsl:text> <xsl:call-template name="PaperPeriod" /> <xsl:text>, </xsl:text> <xsl:call-template name="PaperYear" /> <xsl:text>}} \\</xsl:text> <xsl:call-template name="newline-internal" /> <!-- Note that using generate-empty-cell here requires about three time as much code as just doing it inline :), but we gain in terms of output consistency. --> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">11</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="column-format">c</xsl:with-param> </xsl:call-template> <xsl:text> \\</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\hline</xsl:text> <xsl:call-template name="newline-internal" /> <!-- The calendar itself. --> <xsl:apply-templates select="header" /> <xsl:call-template name="newline-internal" /> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:apply-templates select="body" /> <xsl:call-template name="newline-internal" /> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:apply-templates select="footer" /> <xsl:call-template name="newline-internal" /> <xsl:text>\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\end{tabular}%</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>}</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\end{sideways}</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\end{center}</xsl:text> <xsl:call-template name="newline-internal" /> </common> <common formats="/html/xhtml/"> <!-- Calendar heading. --> <h2> <xsl:call-template name="PaperCode" /> <xsl:text> Paper Calendar, </xsl:text> <xsl:call-template name="PaperPeriod" /> <xsl:text>, </xsl:text> <xsl:call-template name="PaperYear" /> </h2> <!-- The calendar itself. --> <div class="sans"> <table class="small calendar" summary="Paper calendar with relevant links" cellspacing="0"> <!-- I was going to generate COL elements here, but they don't seem to be supported by all browsers. Damn. The same applies for THEAD/TFOOT/TBODY, but I may as well leave them in for the browsers that do support them. --> <thead class="calendar"> <xsl:apply-templates select="header" /> </thead> <tfoot class="calendar"> <xsl:apply-templates select="footer" /> </tfoot> <tbody class="calendar"> <xsl:apply-templates select="body" /> </tbody> </table> </div> </common> </template> <!-- Header/footer rows for the calendar table. To get proper table headings/footings, use HEADING/FOOTING. For other text, use NOTE. --> <template match="header|footer"> <common formats="/latex/xelatex/"> <xsl:apply-templates /> <xsl:text> \\</xsl:text> <!-- It's left to the parent template to add horizontal rules after the last header/footer element, as what gets output may vary depending on position in the table (e.g., double rule after the last header, but single rule after the last footer). --> <xsl:if test="position() != last()"> <xsl:text> \hline</xsl:text> </xsl:if> <xsl:call-template name="newline-internal" /> </common> <common formats="/html/xhtml/"> <tr> <xsl:apply-templates /> </tr> </common> </template> <!-- A table heading or footing, bolded, centered, etc. Headings and footings are assumed to occupy a single row only. @columns: The number of columns that the heading or footing spans. --> <template match="heading|footing"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-content-cell"> <!-- I'm slightly amazed that this actually works! --> <xsl:with-param name="columns" select="if ( @columns ) then @columns else 1" /> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="style">\bfseries</xsl:with-param> </xsl:call-template> <xsl:if test="position() != last()"> <xsl:call-template name="tabular-column-separator" /> </xsl:if> </common> <common formats="/html/xhtml/"> <!-- We can't use generate-content-cell here because we need TH rather than TD. This is a one-off anyway. --> <th class="calendar"> <xsl:if test="@columns"> <xsl:attribute name="colspan"> <xsl:value-of select="@columns" /> </xsl:attribute> </xsl:if> <xsl:apply-templates /> </th> </common> </template> <!-- A miscellaneous piece of text to be inserted somewhere in the calendar table. Notes are assumed to occupy a single row only. This is particularly true for LaTeX where we're working within a tabular environment, which means there's no automatic wrapping of long lines anyway. @columns: The number of columns that the heading or footing spans. --> <template match="note"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns" select="if ( @columns ) then @columns else 1" /> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="align">left</xsl:with-param> <xsl:with-param name="column-format">|l|</xsl:with-param> </xsl:call-template> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns" select="if ( @columns ) then @columns else 1" /> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="align">left</xsl:with-param> </xsl:call-template> </common> </template> <!-- A week in the calendar. Each week has an associated number (automatically generated) and a date range, and spans some defined number of rows (default 2). The week number and date range are only generated for the first of these rows. --> <template match="week"> <common formats="/latex/xelatex/"> <xsl:for-each select="row"> <!-- If we're going to start a new section on this row, draw a rule under the previous section to separate them (editorial: tabular borders in LaTeX are pretty awful compared to HTML). The horrible XPath logic is as follows: * the current row contains at least one section element; and * either * there is at least one week preceding the current week; and * the immediately preceding week /isn't/ a holiday; * or * this is not the first row of the current week; and * the current week is the first week in the calendar; or * the immediately preceding week /is/ a holiday. (YOUR HEAD ASPLODE.) --> <xsl:if test="child::section and ( ( ( count( ../preceding-sibling::week ) > 0 ) and ( not( ../preceding-sibling::week[1]/@holiday ) ) ) or ( ( position() > 1 ) and ( ( count( ../preceding-sibling::week ) = 0 ) or ( ../preceding-sibling::week[1]/@holiday ) ) ) )"> <xsl:text>\cline{3-3}</xsl:text> </xsl:if> <!-- Output the week number and dates columns, but only on the first row of the week. --> <xsl:choose> <xsl:when test="position() = 1"> <!-- Week number. --> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="number" select="1 + count( preceding::week[not( @holiday )] )" /> </xsl:call-template> <xsl:call-template name="tabular-column-separator" /> <!-- Date range. --> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="nodes" select="../dates" /> </xsl:call-template> <xsl:call-template name="tabular-column-separator" /> </xsl:when> <xsl:otherwise> <xsl:call-template name="tabular-column-separator" /> <xsl:call-template name="tabular-column-separator" /> </xsl:otherwise> </xsl:choose> <!-- We have to apply each of the sub-templates manually, not so much to ensure the correct ordering, but so that we can correctly output empty cells when a lecture, laboratory or tutorial element is missing. --> <xsl:apply-templates select="section" /> <xsl:call-template name="tabular-column-separator" /> <!-- Lecture cells span two columns, so we need to explicitly output a two-column empty cell if there's no lecture element for the current row. --> <xsl:apply-templates select="lecture" /> <xsl:if test="count( lecture ) = 0"> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="column-format">c|</xsl:with-param> </xsl:call-template> </xsl:if> <xsl:call-template name="tabular-column-separator" /> <xsl:apply-templates select="reading" /> <xsl:call-template name="tabular-column-separator" /> <!-- Labs and tutorials are similar to lectures, except that they span two columns and all rows for the week, so only the the first row of the week will have a laboratory or tutorial element, empty or otherwise. If this laboratory or tutorial element has content (i.e., isn't empty), then we need to skip over these cells for the remaining rows of the week. If this element is empty (or there's no element at all) then we output a two-column empty cell for all rows. Note that we use "../row[1]" rather than one of the "preceding" axes, as the latter are effectively indexed in reverse. --> <xsl:apply-templates select="laboratory" /> <xsl:if test="count( laboratory ) = 0"> <xsl:choose> <xsl:when test="not( ../row[1]/laboratory/node() )"> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="column-format">c|</xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="tabular-column-separator" /> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:call-template name="tabular-column-separator" /> <xsl:apply-templates select="tutorial" /> <xsl:if test="count( tutorial ) = 0"> <xsl:choose> <xsl:when test="not( ../row[1]/tutorial/node() )"> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="column-format">c|</xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="tabular-column-separator" /> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:call-template name="tabular-column-separator" /> <!-- Assessments always span a single column and span all rows for a week, so no additional special handling is required for missing elements. --> <xsl:apply-templates select="assessment" /> <!-- Note assumption that a lecture is always a single row. --> <xsl:text> \\</xsl:text> <!-- TODO: Need horrible logic similar to sections above. --> <xsl:if test="( count( ../following-sibling::week ) > 0 ) and ( not( ../following-sibling::week[1]/@holiday ) )"> <xsl:text> \cline{4-5}</xsl:text> </xsl:if> <!-- <xsl:if test="position() = ancestor::calendar/@lectures-per-week"> <xsl:text>\cline{1-2}\cline{6-6}\cline{11-11}</xsl:text> <xsl:if test="not( preceding::row[1]/laboratory/@rows )"> <xsl:text>\cline{7-8}</xsl:text> </xsl:if> <xsl:if test="not( preceding::row[1]/tutorial/@rows )"> <xsl:text>\cline{9-10}</xsl:text> </xsl:if> </xsl:if> --> <xsl:call-template name="newline-internal" /> </xsl:for-each> </common> <common formats="/html/xhtml/"> <xsl:variable name="current" select="@current" /> <xsl:for-each select="row"> <tr> <!-- Output the week number and dates columns. --> <xsl:if test="position() = 1"> <!-- Week number, first row only. --> <xsl:call-template name="generate-number-cell"> <!-- TODO: Can this be compressed using XPath? --> <xsl:with-param name="colour"> <xsl:choose> <xsl:when test="$current = 'yes'">red</xsl:when> <xsl:otherwise>white</xsl:otherwise> </xsl:choose> </xsl:with-param> <xsl:with-param name="number" select="1 + count( preceding::week[not( @holiday )] )" /> </xsl:call-template> <!-- Date range, first row only. --> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="nodes" select="../dates" /> </xsl:call-template> </xsl:if> <!-- Apply each of the sub-templates in the correct order. --> <xsl:apply-templates select="section" /> <xsl:apply-templates select="lecture" /> <xsl:apply-templates select="reading" /> <xsl:apply-templates select="laboratory" /> <xsl:apply-templates select="tutorial" /> <xsl:apply-templates select="assessment" /> </tr> </xsl:for-each> </common> </template> <!-- Weeks that are holidays have no week number or date range, just a text description. --> <template match="week[@holiday]"> <common formats="/latex/xelatex/"> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns">11</xsl:with-param> <xsl:with-param name="rows">2</xsl:with-param> <xsl:with-param name="column-format">|c|</xsl:with-param> <xsl:with-param name="style">\LARGE\sffamily\bfseries</xsl:with-param> </xsl:call-template> <xsl:text> \\</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">11</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="column-format">|c|</xsl:with-param> </xsl:call-template> <xsl:text> \\</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> </common> <common formats="/html/xhtml/"> <tr> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns">11</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="colour">blue-ou large</xsl:with-param> <xsl:with-param name="style">border: 2px solid #777777; font-style: italic; font-weight: bold;</xsl:with-param> </xsl:call-template> </tr> </common> </template> <!-- Output a calendar entry for a lecture. Note that lectures are always assumed to span a single row. Lectures are automatically numbered. --> <template match="lecture[node() and not( @holiday )]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="number" select="1 + count( preceding::lecture[node() and not( @holiday )] )" /> </xsl:call-template> <xsl:call-template name="tabular-column-separator" /> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="align">left</xsl:with-param> </xsl:call-template> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="colour">ltgrey</xsl:with-param> <xsl:with-param name="number" select="1 + count( preceding::week[not( @holiday )] )" /> </xsl:call-template> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="colour">ltgrey</xsl:with-param> <xsl:with-param name="align">left</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output a calendar entry for a lecture that occurs on a holiday. These aren't numbered. --> <template match="lecture[@holiday]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="style">\sffamily\bfseries</xsl:with-param> </xsl:call-template> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows">1</xsl:with-param> <xsl:with-param name="colour">blue-ou</xsl:with-param> <xsl:with-param name="style">font-style: italic; font-weight: bold;</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output an empty lecture cell. --> <template match="lecture[not( node() )]"> <common> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">2</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output a calendar entry for a laboratory. Laboratories are automatically numbered. --> <template match="laboratory[node()]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="number" select="1 + count( preceding::laboratory[node()] )" /> </xsl:call-template> <xsl:call-template name="tabular-column-separator" /> <xsl:call-template name="generate-content-cell" /> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="colour">ltblue</xsl:with-param> <xsl:with-param name="number" select="1 + count( preceding::laboratory[node()] )" /> </xsl:call-template> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="colour">ltblue</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output a calendar entry for a tutorial. Tutorials are automatically numbered. --> <template match="tutorial[node()]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="number" select="1 + count( preceding::tutorial[node()] )" /> </xsl:call-template> <xsl:call-template name="tabular-column-separator" /> <xsl:call-template name="generate-content-cell" /> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-number-cell"> <xsl:with-param name="colour">medgreen</xsl:with-param> <xsl:with-param name="number" select="1 + count( preceding::tutorial[node()] )" /> </xsl:call-template> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="colour">medgreen</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output an empty laboratory/tutorial cell. --> <template match="laboratory[not( node() )]|tutorial[not( node() )]"> <common> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="columns">2</xsl:with-param> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> </xsl:call-template> </common> </template> <!-- Output a calendar entry for a section, reading or asssement. All use the same formatting in (Xe)LaTeX, but assessments are displayed using a different colour in (X)HTML, hence the separate template for those. --> <template match="calendar//section[node()]|reading[node()]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> </xsl:call-template> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> </xsl:call-template> </common> </template> <template match="assessment[node()]"> <common formats="/latex/xelatex/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> </xsl:call-template> </common> <common formats="/html/xhtml/"> <xsl:call-template name="generate-content-cell"> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> <xsl:with-param name="colour">peach</xsl:with-param> </xsl:call-template> </common> </template> <!-- Output an empty section, reading or assessment cell. --> <template match="calendar//section[not( node() )]|reading[not( node() )]|assessment[not( node() )]"> <common> <xsl:call-template name="generate-empty-cell"> <xsl:with-param name="rows" select="if ( @rows ) then @rows else ancestor::calendar/@lectures-per-week" /> </xsl:call-template> </common> </template> <!-- Generate a link. --> <template match="link|assessment//link"> <common formats="/latex/xelatex/"> <xsl:apply-templates /> </common> <common formats="/html/xhtml/"> <a href="{@href}"><xsl:apply-templates /></a> </common> </template> <!-- <template match=""> <common formats="/latex/xelatex/"> </common> <common formats="/html/xhtml/"> </common> </template> <template match=""> <common formats="/latex/xelatex/"> </common> <common formats="/html/xhtml/"> </common> </template> --> <template name="generate-number-cell"> <common> <xsl:param name="columns" as="xs:integer">1</xsl:param> <xsl:param name="rows" as="xs:integer" select="ancestor::calendar/@lectures-per-week" /> <!-- No data type for this one, as there isn't a single top-level numeric primitive type in XML Schema :(. --> <xsl:param name="number">0</xsl:param> </common> <common formats="/latex/xelatex/"> <xsl:param name="column-format" as="xs:string">c|</xsl:param> <xsl:if test="$columns > 1"> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="$columns" /> <xsl:text>}{</xsl:text> <xsl:value-of select="$column-format" /> <xsl:text>}{</xsl:text> </xsl:if> <xsl:if test="$rows > 1"> <xsl:text>\multirow{</xsl:text> <xsl:value-of select="$rows" /> <xsl:text>}{*}{</xsl:text> </xsl:if> <xsl:text>\makebox[\numberwidth][c]{</xsl:text> <xsl:value-of select="$number" /> <xsl:text>}</xsl:text> <xsl:if test="$rows > 1"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="$columns > 1"> <xsl:text>}</xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <xsl:param name="colour" as="xs:string">white</xsl:param> <td class="{$colour} center calendar" colspan="{$columns}" rowspan="{$rows}"> <xsl:value-of select="$number" /> </td> </common> </template> <!-- Note when using pre-code in LaTeX to provide formatting: because of the tabular environment, use the declaration forms, not the macros. --> <template name="generate-content-cell"> <common> <xsl:param name="columns" as="xs:integer">1</xsl:param> <xsl:param name="rows" as="xs:integer" select="ancestor::calendar/@lectures-per-week" /> <xsl:param name="align" as="xs:string">center</xsl:param> <!-- Hmm, it appears that if you specify a parameter as xs:string, you can't supply an empty default value. Even a blank doesn't work! The only way to have an empty default is to not specify a data type. That's pretty damn stupid :(. --> <xsl:param name="style" /> <xsl:param name="nodes" select="node()" /> </common> <common formats="/latex/xelatex/"> <xsl:param name="column-format" as="xs:string">c|</xsl:param> <!-- <xsl:message> <xsl:text>////////// Value of rows = [</xsl:text> <xsl:value-of select="$rows" /> <xsl:text>] //////////</xsl:text> </xsl:message> --> <xsl:if test="$columns > 1"> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="$columns" /> <xsl:text>}{</xsl:text> <xsl:value-of select="$column-format" /> <xsl:text>}{</xsl:text> </xsl:if> <xsl:if test="$rows > 1"> <xsl:text>\multirow{</xsl:text> <xsl:value-of select="$rows" /> <xsl:text>}{*}{</xsl:text> </xsl:if> <!-- We need to apply any styling outside the tabular so that it applies to all lines of the tabular (style declarations only last until the next & or \\ in a tabular). Wrap everything up in a group to ensure that it reverts back to the original styling at the end (that should happen anyway, but I'm paranoid). --> <xsl:text>{</xsl:text> <xsl:value-of select="$style" /> <xsl:text>\begin{tabular}{</xsl:text> <xsl:value-of select="substring( $align, 1, 1 )" /> <xsl:text>}</xsl:text> <xsl:apply-templates select="$nodes" /> <xsl:text>\end{tabular}</xsl:text> <xsl:text>}</xsl:text> <xsl:if test="$rows > 1"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="$columns > 1"> <xsl:text>}</xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <xsl:param name="colour" as="xs:string">white</xsl:param> <!-- Alignment is slightly odd in that it's done via a CSS class rather than explicitly. --> <td class="{$colour} {$align} calendar" style="{$style}" colspan="{$columns}" rowspan="{$rows}"> <xsl:apply-templates select="$nodes" /> </td> </common> </template> <template name="generate-empty-cell"> <common> <xsl:param name="columns" as="xs:integer">1</xsl:param> <xsl:param name="rows" as="xs:integer" select="ancestor::calendar/@lectures-per-week" /> </common> <common formats="/latex/xelatex/"> <xsl:param name="column-format" as="xs:string">c|</xsl:param> <xsl:if test="$columns > 1"> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="$columns" /> <xsl:text>}{</xsl:text> <xsl:value-of select="$column-format" /> <xsl:text>}{</xsl:text> </xsl:if> <xsl:if test="$rows > 1"> <xsl:text>\multirow{</xsl:text> <xsl:value-of select="$rows" /> <xsl:text>}{*}{</xsl:text> </xsl:if> <xsl:call-template name="non-breaking-space" /> <xsl:if test="$rows > 1"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="$columns > 1"> <xsl:text>}</xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <xsl:param name="colour" as="xs:string">medgrey</xsl:param> <td class="{$colour} center calendar" colspan="{$columns}" rowspan="{$rows}"> <xsl:call-template name="non-breaking-space" /> </td> </common> </template> </stylesheet>
<?xml version="1.0" encoding="utf-8"?> <!-- Teaching calendar elements. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <template match="calendar"> <common formats="/latex/xelatex/"> <xsl:text> \begin{center} \begin{sideways} \resizebox{24cm}{!}{% \begin{tabular}{|c|c|c|c|l|c|c|c|c|c|c|} </xsl:text> <!-- Calendar heading. --> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="$number-of-columns" /> <xsl:text>}{c}{\LARGE\textbf{</xsl:text> <xsl:apply-templates select="paper" /> <xsl:text> Paper Calendar, </xsl:text> <xsl:apply-templates select="period" /> <xsl:text>, </xsl:text> <xsl:apply-templates select="year" />}} \\ <xsl:call-template name="newline-internal" /> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="$number-of-columns" /> <xsl:text>}{c}{} \\</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:text>\hline</xsl:text> <xsl:call-template name="newline-internal" /> <!-- The calendar itself. --> <xsl:apply-templates select="header" /> <xsl:call-template name="newline-internal" /> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:apply-templates select="body" /> <xsl:call-template name="newline-internal" /> <xsl:text>\hline\hline</xsl:text> <xsl:call-template name="newline-internal" /> <xsl:apply-templates select="footer" /> <xsl:call-template name="newline-internal" /> <xsl:text> \end{tabular}% } \end{sideways} \end{center} </xsl:text> </common> <common formats="/html/xhtml/"> <!-- Page heading. --> <h2> <xsl:apply-templates select="paper" /> <xsl:text> Paper Calendar, </xsl:text> <xsl:apply-templates select="period" /> <xsl:text>, </xsl:text> <xsl:apply-templates select="year" /> </h2> <!-- The calendar itself. --> <div class="sans"> <table class="small" summary="Paper calendar with relevant links" cellspacing="0"> <!-- I was going to generate COL elements here, but they don't seem to be supported by all browsers. Damn. The same applies for THEAD/TFOOT/TBODY, but I may as well leave them in for the browsers that do support them. --> <thead> <xsl:apply-templates select="header" /> </thead> <tfoot> <xsl:apply-templates select="footer" /> </tfoot> <tbody> <xsl:apply-templates select="body" /> </tbody> </table> </div> </common> </template> <template name="SubjectCode" match="SubjectCode"> <common> <xsl:value-of select="$subject-code" /> </common> </template> <template name="PaperNumber" match="PaperNumber"> <common> <xsl:value-of select="$paper-number" /> </common> </template> <template name="PaperCode" match="PaperCode"> <common> <xsl:value-of select="$subject-code" /> <xsl:text> </xsl:text> <xsl:value-of select="$paper-number" /> </common> </template> <xsl:template name="PaperYear" match="PaperYear"> <common> <!-- @offset lets us output the year +/- some integer value. The input value is truncated and defaults to zero if not supplied. --> <xsl:variable name="add"> <xsl:value-of select="floor(@offset)" /> <xsl:if test="not(@offset)">0</xsl:if> </xsl:variable> <xsl:value-of select="$paper-year + $add" /> </common> </xsl:template> <xsl:template name="PaperPeriod" match="PaperPeriod"> <common> <xsl:value-of select="$paper-period" /> </common> </xsl:template> <!-- Header/footer rows for the calendar table. To get proper table headings/footings, use HEADING/FOOTING. For other text, use NOTE. --> <xsl:template match="header|footer"> <common formats="/latex/xelatex/"> <xsl:apply-templates /> <xsl:text>\\ \hline</xsl:text> </common> <common formats="/html/xhtml/"> <tr> <xsl:apply-templates /> </tr> </common> </xsl:template> <!-- A table heading or footing, bolded, centered, etc. --> <xsl:template match="heading|footing"> <common formats="/latex/xelatex/"> <xsl:if test="@columns"> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="@columns" /> <xsl:text>}{|c|}{</xsl:text> </xsl:if> <xsl:text>\textbf{</xsl:text> <xsl:apply-templates /> <xsl:text>}</xsl:text> <xsl:if test="@columns"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="position() != last()"> <xsl:text> & </xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <th> <xsl:if test="@columns"> <xsl:attribute name="colspan"> <xsl:value-of select="@columns" /> </xsl:attribute> </xsl:if> <xsl:apply-templates /> </th> </common> </xsl:template> <!-- A miscellaneous piece of text to be inserted somewhere in the calendar table. --> <xsl:template match="note"> <common formats="/latex/xelatex/"> <xsl:if test="@columns"> <xsl:text>\multicolumn{</xsl:text> <xsl:value-of select="@columns" /> <xsl:text>}{|l|}{</xsl:text> </xsl:if> <xsl:apply-templates /> <xsl:if test="@columns"> <xsl:text>}</xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <td> <xsl:if test="@columns"> <xsl:attribute name="colspan"> <xsl:value-of select="@columns" /> </xsl:attribute> </xsl:if> <xsl:apply-templates /> </td> </common> </xsl:template> </stylesheet>
Show line notes below