我有一个使用 xslt 转换编写的 html 表,如下所示
<table>
<xsl:for-each select="someNode">
<xsl:if test="testThis">
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>something</td>
</tr>
</xsl:if>
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>this is always displayed</td>
</tr>
<xsl:if test="testThis2">
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>something 2</td>
</tr>
</xsl:if>
....
</xsl:for-each>
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>this is always displayed</td>
</tr>
</table>
我需要一种方法将不同类的 dRow/evenRow 应用于 tr 元素。
<tr class="evenRow"> or <tr class="oddRow">
我尝试在每个
elem 之后使用这样的模板
<xsl:template name="conditionalRowStyle">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="(count(../preceding-sibling::tr) mod 2) = 0">oddrow</xsl:when>
<xsl:otherwise>evenrow</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
但这不起作用。
任何想法?
你可能可以逃脱这样做just css http://www.sftcc.com/007/evenodd.html
tr:nth-child(odd) {
/*...*/
}
tr:nth-child(odd) {
/*...*/
}
如果你不能,你可以做类似的事情
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="(position() mod 2) != 1">
<xsl:text>evenRow</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>oddRow</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
请注意,我在 SO 文本框中写了此内容,但尚未对其进行测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)