我想通过 CSS 在转换后的 HTML 中对特定类别的表格进行不同的样式设置。
例如在 XML 中:
<table>
<row role="label">
<cell>
Manuscrit Bodmer
</cell>
<cell>
Manuscrit fr. 1457
</cell>
</row>
<row>
<cell>
<lb/>Début <supplied><locus from="1r">fol. 1</locus></supplied> :
</cell>
<cell>
<note><lb/><supplied>fol. 6vᵒ, ligne 15</supplied> :</note>
</cell>
</row>
</table>
在 XSL 中:
<xsl:template match="tei:table[not(. = '')]">
<xsl:param name="sprache"/>
<xsl:element name="table">
<xsl:apply-templates><xsl:with-param name="sprache" select="$sprache"/></xsl:apply-templates>
</xsl:element>
</xsl:template>
为了实现这一点,我正在考虑将特定的 CSS 类应用于该表,例如。在生成的 HTML 中
<table class="comparison-table">
并在 CSS 中设置样式。这可能吗?我怎样才能做到这一点呢?
--- 更新感谢@zx485,我将 XML 和 XSL 更新为:
<xsl:template match="tei:table[@rend='comparison-table']">
<xsl:param name="sprache"/>
<xsl:copy>
<xsl:attribute name="class"><xsl:text>comparison-table</xsl:text></xsl:attribute>
<xsl:apply-templates><xsl:with-param name="sprache" select="$sprache"/></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:table[not(. = '')]">
<xsl:param name="sprache"/>
<xsl:element name="table">
<xsl:apply-templates><xsl:with-param name="sprache" select="$sprache"/></xsl:apply-templates>
</xsl:element>
</xsl:template>
在我的 XML 中:
<table rend="comparison-table">
<row role="label">
<cell>
Manuscrit Bodmer
</cell>
<cell>
Manuscrit fr. 1457
</cell>
</row>
....
但在生成的 HTML 文件中,表格没有 css 类名“比较表”。
=== 更新 2:正如@zx485 在讨论室中建议的那样,我只需要更改为
<xsl:template match="tei:table">