首页 > 解决方案 > XSL 选择样式文本和 td

问题描述

我正在使用 XSLT 选择来设置单元格内容的样式。出于某种原因,它同时设置了文本和 td 的样式。如果我然后尝试<td>用 CSS 重新着色它只会让它完全消失。

<td>
    <xsl:attribute name="style">
        <xsl:choose>
            <xsl:when test="@status = 'OPEN'">
                <xsl:text>color: limegreen;</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>color: red;</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:attribute>
    <xsl:value-of select="@status" />
</td>

我只想让它着色value-of select,而不是单元格边框。

标签: cssxslt

解决方案


使用上面的代码,您可以为整个<td>.
如果您只想设置文本样式,请将其应用于<span>(或其他),如下所示:

<td>
    <span>
        <xsl:attribute name="style">
            <xsl:choose>
                <xsl:when test="@status = 'OPEN'">
                    <xsl:text>color: limegreen;</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>color: red;</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
        <xsl:value-of select="@status" />
    </span>
</td>

这应该只着色文本而不是边框​​。


推荐阅读