0

我想通过 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&#7506;, 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">
4

2 回答 2

2

Change your template to

<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>
于 2017-09-14T09:23:37.647 回答
0

我用 xsl:if 重构了 zx485 的解决方案,它可能更具可读性并遵循 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>
于 2017-09-14T12:47:55.547 回答