Newer
Older
XML / 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.
			'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>