- Creating modules for special characters, basic page elements and in-text
menus.
1 parent 6f8c275 commit 124187b862c0c7858806d7d2d64802fd080b5dcd
nstanger authored on 1 Sep 2011
Showing 4 changed files
View
322
format-master.xml
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.
-->
<!-- Output a string containing the date that the document was last built. -->
<include href="modules/build-date.xml" />
 
 
<!--
Plain paragraph.
@indent: Whether or not to indent this paragraph (probably only relevant in LaTeX).
'no' => don't indent.
otherwise => apply standard paragraph formatting. [default]
@align: How to align the paragraph. Note that these are potentially distinct from the default action, e.g., specifying align="left" will produce a flushleft environment in LaTeX, which is not the same effect as not specifying an alignment.
'left' => left alignment
'center' => centered alignment
'right' => right alignment
 
@border: Whether or not to draw a border around the paragraph.
'yes' => draw a border.
otherwise => apply standard paragraph formatting. [default]
-->
<template name="paragraph" match="paragraph|para|p|P">
<common formats="/latex/xelatex/">
<xsl:text>
 
 
</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>\begin{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}</xsl:text>
</xsl:when>
<xsl:when test="@align = 'center'">
<xsl:text>\begin{center}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{center}</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@indent = 'no'">\noindent </xsl:if>
<xsl:if test="@border = 'yes'">
<xsl:text>\fbox{</xsl:text>
</xsl:if>
<xsl:apply-templates />
<xsl:if test="@border = 'yes'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</common>
<!-- HTML is weird about what things you cannot include inside paragraphs (e.g. lists of any kind). However, the end P tag is optional, so one option might simply be not to output it. -->
<common formats="/html/xhtml/">
<!--
The HTMLStyle parameter is an Ugly Hack(tm) to ensure that paragraphs are indented correctly inside definition lists in HTML. I tried modes first, but they didn't work correctly. Fortunately this only needs to be done with paragraphs, so this will work fine.
-->
<xsl:param name="HTMLStyle" />
<p>
<xsl:if test="@border = 'yes'">
<xsl:attribute name="style">border: 1px solid black;</xsl:attribute>
</xsl:if>
<xsl:if test="$HTMLStyle">
<xsl:attribute name="class">
<xsl:value-of select="$HTMLStyle" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
</p>
</common>
</template>
<!-- Special characters (should maybe all be named, in case they need to be called explicitly with xsl:call-template) -->
<!-- I'd like to use the Unicode names for these; will look them up some time! -->
<template name="newline" match="newline|line-break|br">
<common formats="/latex/xelatex/"><xsl:text> \\
</xsl:text></common>
<common formats="/html/xhtml/"><br /></common>
</template>
 
<!--
Whereas newline|line-break is for line breaks intended to be output into the final document, this is for additional linebreaks in the generated latex or HTML source (for stuff like avoiding "\end{verbatim}\item" all on one line).
-->
<template name="newline-internal" match="newline-internal">
<common formats="/latex/xelatex/"><xsl:text>
</xsl:text></common>
<common formats="/html/xhtml/"><xsl:text>
</xsl:text></common>
</template>
<template name="page-break" match="page-break|new-page|newpage|pagebreak">
<common formats="/latex/xelatex/">\newpage</common>
</template>
<!--
Insert a space. Useful for the occasional case where two elements occur next to each other with only a space separating them (e.g., an <emph> immediately following a <quote>), and the space gets gobbled by XSLT, producing non-separated words in the output. It doesn't seem very consistent as to when it does and doesn't happen, unfortunately, but when it does happen, inserting a <space /> will fix the problem.
This is analogous to putting a \ at the end of macros in LaTeX to ensure that spaces after the macro aren't gobbled, and indeed, this is what the LaTeX version of the markup produces.
-->
<template name="space" match="space">
<common formats="/latex/xelatex/"><xsl:text>\ </xsl:text></common>
<!-- U+0020 SPACE -->
<common formats="/html/xhtml/"><xsl:text> </xsl:text></common>
</template>
 
<template name="space-strip" match="space" mode="strip">
<common formats="/html/xhtml/">
<xsl:call-template name="space" />
</common>
</template>
 
<template name="non-breaking-space" match="non-breaking-space|nbsp|no-break-space">
<common formats="/latex/xelatex/">~</common>
<common formats="/html/xhtml/"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></common>
<!-- Could use U+00A0 NO-BREAK SPACE for XHTML? -->
</template>
<template name="thin-space" match="thin-space|thinspace">
<common formats="/latex/xelatex/">\,</common>
<common formats="/html/xhtml/"><xsl:text disable-output-escaping="yes">&amp;thinsp;</xsl:text></common>
<!-- Could use U+2009 THIN SPACE for XHTML? -->
</template>
<!--
Insert a discretionary hyphen. Only relevant for LaTeX output.
-->
<template name="discretionary-hyphen" match="hyphen">
<common formats="/latex/xelatex/">\-</common>
<!-- Could use U+00AD SOFT HYPHEN for XHTML? -->
</template>
<!-- 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. -->
<template name="LaTeX-strip" match="LaTeX|latex" mode="strip">
<common formats="/html/xhtml/">LaTeX</common>
</template>
 
<!-- Note: no equivalent of \triangleright in HTML, use right arrow instead. -->
<template name="menu-separator" match="menu-separator|menusep|menu/separator">
<common formats="/latex/xelatex/"> \ensuremath{\triangleright} </common>
<!-- Need spaces for HTML as they seem to get munched otherwise. -->
<html><xsl:text disable-output-escaping="yes"> &amp;rarr; </xsl:text></html>
<!-- U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE -->
<xhtml><span class="unicode"><xsl:text></xsl:text></span></xhtml>
</template>
 
<template name="menu-separator-strip" match="menu-separator|menusep|menu/separator" mode="strip">
<common formats="/html/xhtml/">
<xsl:call-template name="menu-separator" />
</common>
</template>
 
<template name="menu-item" match="menu/item">
<common formats="/latex/xelatex/">\textbf{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><b><xsl:apply-templates /></b></common>
</template>
<!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. -->
<include href="modules/menus.xml" />
 
<!-- Special styles -->
<template name="emph" match="emph|em">
<common formats="/latex/xelatex/">\emph{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><em><xsl:apply-templates /></em></common>
View
120
modules/basic-page-elements.xml 0 → 100755
<?xml version="1.0" encoding="utf-8"?>
 
<!--
Basic page layout elements, like paragraphs, page breaks, etc.
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 space 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">
 
<!--
Plain paragraph.
@indent: Whether or not to indent this paragraph (probably only relevant in LaTeX).
'no' => don't indent.
otherwise => apply standard paragraph formatting. [default]
@align: How to align the paragraph. Note that these are potentially distinct from the default action, e.g., specifying align="left" will produce a flushleft environment in LaTeX, which is not the same effect as not specifying an alignment.
'left' => left alignment
'center' => centered alignment
'right' => right alignment
 
@border: Whether or not to draw a border around the paragraph.
'yes' => draw a border.
otherwise => apply standard paragraph formatting. [default]
-->
<template name="paragraph" match="paragraph|para|p|P">
<common formats="/latex/xelatex/">
<xsl:text>
 
 
</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>\begin{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}</xsl:text>
</xsl:when>
<xsl:when test="@align = 'center'">
<xsl:text>\begin{center}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{center}</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@indent = 'no'">\noindent </xsl:if>
<xsl:if test="@border = 'yes'">
<xsl:text>\fbox{</xsl:text>
</xsl:if>
<xsl:apply-templates />
<xsl:if test="@border = 'yes'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</common>
<!--
HTML is weird about what things you cannot include inside paragraphs (e.g. lists of any kind). However, the end P tag is optional, so one option might simply be not to output it (not for XHTML, though!).
-->
<common formats="/html/xhtml/">
<!--
The HTMLStyle parameter is an Ugly Hack(tm) to ensure that paragraphs are indented correctly inside definition lists in HTML. I tried modes first, but they didn't work correctly. Fortunately this only needs to be done with paragraphs, so this will work fine.
-->
<xsl:param name="HTMLStyle" />
<p>
<xsl:if test="@border = 'yes'">
<xsl:attribute name="style">border: 1px solid black;</xsl:attribute>
</xsl:if>
<xsl:if test="$HTMLStyle">
<xsl:attribute name="class">
<xsl:value-of select="$HTMLStyle" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
</p>
</common>
</template>
<!-- New line. -->
<template name="newline" match="newline|line-break|br">
<common formats="/latex/xelatex/"><xsl:text> \\
</xsl:text></common>
<common formats="/html/xhtml/"><br /></common>
</template>
 
<!--
Whereas newline|line-break is for line breaks intended to be output into the final document, this is for additional linebreaks in the generated LaTeX or HTML markup (for stuff like avoiding "\end{verbatim}\item" all on one line, not that this really matters in general).
-->
<template name="newline-internal" match="newline-internal">
<common formats="/latex/xelatex/"><xsl:text>
</xsl:text></common>
<common formats="/html/xhtml/"><xsl:text>
</xsl:text></common>
</template>
<!-- Page break. -->
<template name="page-break" match="page-break|new-page|newpage|pagebreak">
<common formats="/latex/xelatex/">\newpage</common>
</template>
</stylesheet>
View
modules/menus.xml 0 → 100755
View
modules/special-characters.xml 0 → 100755