- Images
- "Inner" code blocks
- Tables
<img src="..." title="A title" />
<!-- images - by default, I want to center them horizontally -->
<xsl:template match="img">
<!-- Trick for centering images by placing them in a container.
From: http://www.netmechanic.com/news/vol7/html_no10.htm -->
<div class="image-container">
<img>
<xsl:attribute name="src"><xsl:value-of select="@src" />
</xsl:attribute>
</img>
<!-- add title= if one is given -->
<xsl:if test="string-length(@title)">
<div class="image-title">
<xsl:value-of select="@title" />
</div>
</xsl:if>
</div>
</xsl:template>
div.image-container {
margin-top: 1em;
margin-bottom: 1em;
padding: 0;
text-align: center;
}
div.image-title {
font-weight: bold;
}
<xsl:template match="note//code|warn//code">
<!-- <code> container inside of a <warn> or <note> gets
different styling to make it look better in those containers -->
<xsl:template match="warn//code|note//code">
<!-- Put title+content in a parent container -->
<div class="inner-code-container">
<!-- Add title, if user provided one -->
<xsl:if test="string-length(@title)">
<div class="inner-code-title">
<xsl:value-of select="@title" />
</div>
</xsl:if>
<!-- Include code as preformatted block -->
<div class="inner-code-content">
<!-- ugh - substring() hack is to remove leading \n at start
of code block. Without this hack, it looks okay when
run through xsltproc, but has a gap when viewing the XML
directly in Firefox.
-->
<pre><xsl:value-of select="substring(.,2)" /></pre></div>
</div>
</xsl:template>
/*
This is for <code> tags inside either a <warn> or <note> container.
Just like the normal <code>, this creates 3 divs:
inner-code-container: Overall container.
inner-code-title: Title (optional).
inner-code-content: The code itself.
*/
div.inner-code-container {
font-size: 1em;
margin-left: 1em;
margin-right: 1em;
background: #bbbb00;
margin-top: 1em;
margin-bottom: 1em;
}
/* The title for the code box */
div.inner-code-title {
background: #555555;
color: #ffff00;
font-size: .9em;
padding-left: .8em;
padding-right: .8em;
padding-top: 0.2em;
padding-bottom: 0.2em;
border: 1px dashed black;
}
/* The code itself */
div.inner-code-content {
background: #dddddd;
padding-left: .8em;
padding-right: .8em;
border: 1px dashed black;
/* hide any text that falls outside the bounding box */
overflow: hidden;
}
<!-- Basically the same as an HTML table, but the title is
given as the title= attribute -->
<xsl:template match="table">
<!-- Place inside outer container, as done with <code>, etc. -->
<div class="table-container">
<!-- use label= if user gave it. I like using a <div> instead of
relying on the CAPTION tag working the way I expect -->
<xsl:if test="string-length(@title)">
<div class="table-title">
<xsl:value-of select="@title" />
</div>
</xsl:if>
<!-- Table is built with <tr>, <th>, <td> as usual ... -->
<table class="table-body"><xsl:apply-templates /></table>
</div>
</xsl:template>
<!-- Pass along a number of standard HTML tags as-is -->
<xsl:template match="p|i|b|tt|ul|ol|li|tr|th|td">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
div.table-container {
margin-top: 2em;
margin-bottom: 2em;
}
div.table-title {
margin-left: 6em;
margin-right: 6em;
font-size: 1.2em;
font-weight: bold;
padding-bottom: 1em;
text-align: center;
}
table.table-body {
border: 1px solid #888888;
border-collapse: collapse;
padding: 0;
margin: 0;
background: #ddf3ff;
margin-left: auto;
margin-right: auto;
font-size: 1em;
}
tr {
border: 1px solid #888888;
border-collapse: collapse;
padding: 0;
margin: 0;
}
th {
border: 1px solid #888888;
border-collapse: collapse;
padding-left: .2em;
padding-right: .2em;
margin: 0;
background: #eeeead;
text-align: center;
}
td {
border: 1px solid #888888;
border-collapse: collapse;
margin: 0;
padding-left: 0.5em;
padding-right: 0.5em;
text-align: center;
}