- Removed irrelevant comment about "strip" templates.
- Rewrote some other comments.
- Reduced generated whitespace between paragraphs for LaTeX.
- Orthogonalised processing of paragraph attributes; previously, the @align
  attribute overrode @indent and @border.
- Normalised code formatting, and made more consistent use of xsl:text.
- Used newline-internal in newline template and collapsed split LaTeX/HTML code.
- Rewrote vertical-skip to support valid LaTeX length expressions, and added
  validity check.
1 parent 693d980 commit d6336d5cff55bd088d56c7ca7b4a2be55f042d7b
nstanger authored on 6 Oct 2011
Showing 1 changed file
View
157
modules/basic-page-elements.xml
<?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.
@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 a different effect from not specifying an alignment at all.
'left' => left alignment
'center' => centered alignment
'right' => right alignment
otherwise => apply standard paragraph formatting. [default]
 
@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/">
<!--
LaTeX delimits paragraphs with vertical whitespace, so we need to ensure plenty. A blank line before and after should be sufficient.
-->
<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:when>
<xsl:when test="@align = 'center'">
<xsl:text>\begin{center}</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:if test="@indent = 'no'">
<xsl:text>\noindent </xsl:text>
</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:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<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>
<!--
<!-- 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).
<common formats="/latex/xelatex/">
<xsl:text> \\</xsl:text>
<xsl:call-template name="newline-internal" />
</common>
<common formats="/html/xhtml/">
<br />
</common>
</template>
 
<!--
Whereas the "newline" template above is for line breaks intended to be displayed in the final document, this is for additional linebreaks in the generated LaTeX or HTML markup. This is used to avoid things like "\end{verbatim}\item" all on one line, not that this really matters in general, as the generated markup will be pretty messy anyway :).
This also makes any XSLT markup that generates internal newlines a lot tidier looking!
-->
<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>
<common>
<xsl:text>
</xsl:text>
</common>
</template>
<!--
Text that shouldn't be broken across a line (i.e., LaTeX \mbox).
Only really relevant for LaTeX because we can't control this in HTML.
-->
<template name="no-break" match="no-break|mbox">
<common formats="/latex/xelatex/">\mbox{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><xsl:apply-templates /></common>
</template>
<common formats="/latex/xelatex/">
<xsl:text>\mbox{</xsl:text>
<xsl:apply-templates />
<xsl:text>}</xsl:text>
</common>
<common formats="/html/xhtml/">
<xsl:apply-templates />
</common>
</template>
<!--
Page break. This is only relevant for LaTeX formats at present.
</template>
<!--
Skip a certain amount of space vertically. Probably more relevant to LaTeX than HTML. Is it even possible to vskip a set amount in HTML??
Skip a certain amount of space vertically. Probably more relevant to LaTeX than HTML. Is it even possible to vskip a set amount in HTML?? I suppose you could create an empty <div> element with a specified height, but I'm not sure that it even makes sense in HTML to skip more than the standard paragraph separation anyway.
@size: the amount of space to skip.
missing => \vskip\baselineskip [default]
'small' => \smallskip
<template name="vertical-skip" match="vertical-skip|vskip">
<common formats="/latex/xelatex/">
<xsl:choose>
<xsl:when test="not(@size)">
\vskip\baselineskip
<xsl:text>\vskip\baselineskip</xsl:text>
</xsl:when>
<xsl:when test="@size='small'">
\smallskip
<xsl:text>\smallskip</xsl:text>
</xsl:when>
<xsl:when test="@size='medium'">
\medskip
<xsl:text>\medskip</xsl:text>
</xsl:when>
<xsl:when test="@size='large'">
\bigskip
<xsl:text>\bigskip</xsl:text>
</xsl:when>
<xsl:when test="@size='fill'">
\vfill
<xsl:text>\vfill</xsl:text>
</xsl:when>
<!-- Check for valid LaTeX length format, e.g., "2.54cm". -->
<xsl:when test="matches( @size, '^\d*\.?\d+(cm|em|ex|in|pc|pt|mm|bp)$' )">
<xsl:text>\vskip</xsl:text>
<xsl:value-of select="@size" />
</xsl:when>
<xsl:otherwise>
\vskip<xsl:value-of select="@size" />
<xsl:message terminate="yes">
<xsl:text>Invalid skip expression for LaTeX: "</xsl:text>
<xsl:value-of select="@size" />
<xsl:text>" (valid values are "small", "medium", "large", "fill", or a LaTeX length, e.g., "24pt")</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</common>
<!-- For the moment we'll just throw in a BR :) -->
<common formats="/html/xhtml/"><br clear="left" /></common>
</template>
<common formats="/html/xhtml/">
<!-- For the moment we'll just throw in a <br /> :). -->
<br clear="left" />
</common>
</template>
 
</stylesheet>