TEI-P5:如何将CSS类名添加到html表标签?
问题描述:
我想通过CSS在转换后的HTML中以不同的方式设置特定类别的表格。TEI-P5:如何将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">
答
更改为
<xsl:template match="tei:table[not(. = '')]">
<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>
答
我重构zx485与XSL解决方案:如果,它可能更具可读性并遵循DRY原则:
<xsl:template match="tei:table">
<xsl:param name="sprache"/>
<xsl:element name="table">
<xsl:if test="@rend='comparison-table'">
<xsl:attribute
name="class"><xsl:text>comparison-table</xsl:text></xsl:attribute>
</xsl:if>
<xsl:apply-templates><xsl:with-param name="sprache"
select="$sprache"/></xsl:apply-templates>
</xsl:element>
</xsl:template>
非常感谢! 有没有办法将css-classname限制为只有名称为“compare-table”的标识符的表?现在修改所有的html-table都会得到类名“比较表”。 – StandardNerd
我用你的给定模板。因此,简单地创建符合这些特定“表”的匹配条件的模板就足够了(使用谓词,比如'match =“table [predicate]”'。 – zx485
啊,好的,我该如何在XML中编写标识符,例如
我重构zx485与XSL解决方案:如果,它可能更具可读性并遵循DRY原则:
相关问题