所以我尝试将 css 类名连接在一起,这是我的 XSL 片段:
<xsl:variable name="btnClass">
<xsl:choose>
<xsl:when test="$type = 'hello'">myClass</xsl:when>
<xsl:when test="$type = 'world'">myOtherClass</xsl:when>
<xsl:otherwise>stuff</xsl:otherwise>
</xsl:choose>
<xsl:if test="$additionalClass != ''"> l<xsl:value-of select="$additionalClass"/></xsl:if>
</xsl:variable>
它会给我,例如:
myClass extraClass
然而,在 HTML 中检查它,它实际上是:
myClass extraClass
因此,css 从未启动。如果我删除
并在其中放置一个实际空间,那么该类将按预期工作。
我尝试将 XSL 调整为(仅使用常规空格):
<xsl:if test="$additionalClass != ''"> <xsl:value-of select="$additionalClass"/></xsl:if>
但这只会给我:
myClassextraClass
如何在我的字符串中添加一个普通空格?哈哈
最佳答案
您可以用 xml:text
填充额外的空间,如下所示:
<xsl:if test="$additionalClass != ''">
<xsl:text> </xsl:text><xsl:value-of select="$additionalClass"/>
</xsl:if>
(显然你不希望
直接出现在 class='xy'
html 中)
你也可以使用像concat
这样的函数:
<xsl:value-of select="concat(' ', $additionalClass)"/>
关于html - XSL 中空白的奇怪 CSS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23246675/