2017-09-14 129 views
0

我想通過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&#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"> 

回答

2

更改爲

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

非常感謝! 有沒有辦法將css-classname限制爲只有名稱爲「compare-table」的標識符的表?現在修改所有的html-table都會得到類名「比較表」。 – StandardNerd

+0

我用你的給定模板。因此,簡單地創建符合這些特定「表」的匹配條件的模板就足夠了(使用謂詞,比如'match =「table [predicate]」'。 – zx485

+0

啊,好的,我該如何在XML中編寫標識符,例如

StandardNerd

0

我重構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>