1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<?xml version="1.0" encoding="utf-8"?>
<!--
/=====================================================================\
| LaTeXML-tabular-xhtml.xsl |
| Converting tabular to xhtml |
|=====================================================================|
| Part of LaTeXML: |
| Public domain software, produced as part of work done by the |
| United States Government & not subject to copyright in the US. |
|=====================================================================|
| Bruce Miller <bruce.miller@nist.gov> #_# |
| http://dlmf.nist.gov/LaTeXML/ (o o) |
\=========================================================ooo==U==ooo=/
-->
<xsl:stylesheet
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:ltx = "http://dlmf.nist.gov/LaTeXML"
xmlns:f = "http://dlmf.nist.gov/LaTeXML/functions"
extension-element-prefixes="f"
exclude-result-prefixes = "ltx f">
<!-- ======================================================================
Tabulars
====================================================================== -->
<!-- LaTeXML allows tabular in both block & inline contexts, but HTML does not;
In inline contexts, we just generate span (but with appropriate CSS).
See the CONTEXT discussion in LaTeXML-common -->
<xsl:strip-space elements="ltx:tabular ltx:thead ltx:tbody ltx:tfoot ltx:tr"/>
<xsl:preserve-space elements="ltx:td"/>
<xsl:template match="ltx:tabular">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,'table')}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes"/>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="ltx:thead">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,'thead')}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes"/>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="ltx:tbody">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,'tbody')}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes"/>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="ltx:tfoot">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,'tfoot')}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes"/>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="ltx:tr">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,'tr')}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes"/>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="ltx:td">
<xsl:param name="context"/>
<xsl:text>
</xsl:text>
<xsl:element name="{f:blockelement($context,f:if(@thead,'th','td'))}" namespace="{$html_ns}">
<xsl:call-template name="add_id"/>
<!-- generally, align & width should be covered by CSS -->
<xsl:call-template name="add_attributes">
<xsl:with-param name="extra_classes">
<xsl:if test="@thead">
<xsl:value-of select="concat('ltx_th ',f:class-pref('ltx_th_',@thead))"/>
</xsl:if>
<xsl:if test="@thead and @border">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="@border">
<xsl:value-of select="f:class-pref('ltx_border_',@border)"/>
</xsl:if>
<!-- attempt to simulate rowspan when simulating table.
Actually, I think we need empty <td> for the spanned cells! -->
<xsl:if test="@rowspan and $context = 'inline'">
<xsl:if test="@thead or @border">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:text>ltx_rowspan</xsl:text>
</xsl:if>
</xsl:with-param>
<xsl:with-param name="extra_style">
<xsl:if test="starts-with(@align,'char:')">
<xsl:text>text-align:"</xsl:text>
<xsl:value-of select="substring-after(@align,'char:')"/>
<xsl:text>";</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="ancestor::ltx:tabular[@rowsep and @colsep]">
<xsl:value-of select="concat('padding:',f:half(ancestor::ltx:tabular/@rowsep),' ',
ancestor::ltx:tabular/@colsep,';')"/>
</xsl:when>
<xsl:when test="ancestor::ltx:tabular/@rowsep">
<xsl:value-of select="concat('padding-top:',f:half(ancestor::ltx:tabular/@rowsep),';')"/>
<xsl:value-of select="concat('padding-bottom:',f:half(ancestor::ltx:tabular/@rowsep),';')"/>
</xsl:when>
<xsl:when test="ancestor::ltx:tabular/@colsep">
<xsl:value-of select="concat('padding-left:',ancestor::ltx:tabular/@colsep,';')"/>
<xsl:value-of select="concat('padding-right:',ancestor::ltx:tabular/@colsep,';')"/>
</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:if test="@colspan">
<xsl:attribute name='colspan'><xsl:value-of select='@colspan'/></xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan">
<xsl:attribute name='rowspan'><xsl:value-of select='@rowspan'/></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|