Search code examples
htmlxmlxslttei

TEI-P5: how to add a css classname to html table tag?


I'd like to style a specific class of tables differently in transformed HTML via CSS.

For example in 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>

In 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>

To achieve that I'm thinking of applying a specific CSS class to that table eg. in generated HTML

<table class="comparison-table">

and style it in css. Is this possible? And how can I achieve that exactly?

--- Update Thanks to @zx485 I updated XML & XSL to:

<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>

And in my XML:

<table rend="comparison-table">
    <row role="label">
        <cell>
            Manuscrit Bodmer
        </cell>
        <cell>
            Manuscrit fr. 1457
        </cell>
    </row>
  ....

But in the generated HTML file the tables don't have css classname "comparison-table".

=== Update 2: As @zx485 suggested in the discussion room I just had to change to

<xsl:template match="tei:table">

Solution

  • 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>