XSLT:在html标记中添加文本
可以将xsl变量中的文本添加到html标记的内部吗XSLT:在html标记中添加文本,xslt,Xslt,可以将xsl变量中的文本添加到html标记的内部吗 <xsl:variable name="selected"> <xsl:if test="@class = 'selected'"> class="selected"</xsl:if> </xsl:variable> <li{$selected}></li> class=“已选定” 您不应该尝试将其作为文本编写,而应该查看xsl:element和xsl:att
<xsl:variable name="selected">
<xsl:if test="@class = 'selected'"> class="selected"</xsl:if>
</xsl:variable>
<li{$selected}></li>
class=“已选定”
您不应该尝试将其作为文本编写,而应该查看xsl:element和xsl:attribute。粗略的例子:
<xsl:element name="li">
<xsl:attribute name="class">
<xsl:value-of select="$selected" />
</xsl:attribute>
</xsl:element>
试试这个:
<xsl:element name="li">
<xsl:if test="@class = 'selected'">
<xsl:attribute name="class">
selected
</xsl:attribute>
</xsl:if>
</xsl:element>
挑选出来的
或者,如果需要
class=”“
,则可以将xsl:if
嵌套在xsl:attribute
中,而不是反过来嵌套。如前所述,将其作为文本编写是不明智的。请注意,如果您足够小心地将其作为第一个孩子,您可以直接在标记中使用
,而不是使用
挑选出来的
为了可读性,最好避免不必要的xsl:element调用,并直接嵌入li元素。
<li>
<xsl:if test="$selected">
<!-- Will refer to the last opened element, li -->
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<!-- Anything else must come _after_ xsl:attribute -->
</li>