生成的HTML页面包含有时在我的页面中不存在的引用链接。我应该将这个链接显示为一个简单的标签。目前已完成此操作:
<xsl:choose>
<xsl:when test="$nb_action != 0">
<a href="#action">Action (offensive, defensive, reconnaissance)</a>
</xsl:when>
<xsl:otherwise>
Action (offensive, defensive, reconnaissance)
</xsl:otherwise>
</xsl:choose>我想知道如何简化我的代码,如何停用节点<a></a>?
我的第一个想法是委托一个特殊的css类:
<a href="#action">
<xsl:if test="$nb_action = 0">
<xsl:attribute name="class">inactive</xsl:attribute>
</xsl:if>Action (offensive, defensive, reconnaissance)
</a>但它仍然是一个纽带。
以下是一种解决方法:
<a><xsl:if test="$nb_action != 0">
<xsl:attribute name="href">#action</xsl:attribute>
</xsl:if>Action (offensive, defensive, reconnaissance)</a>在没有href的情况下编写html <a>标签是正确的吗?
发布于 2010-07-21 23:04:51
您可以将该Action文本作为变量。这个变量仍然出现在3个地方。
<xsl:variable name="textval">
Action (offensive, defensive, reconnaissance)</xsl:variable>
<xsl:choose>
<xsl:when test="0">
<a href="#action"><xsl:copy-of select="$textval"/></a>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$textval"/>
</xsl:otherwise>
</xsl:choose>编辑:或者,如果您不介意额外的、无用的span标记,您可以使用
<xsl:variable name="condition" select="---condition-here---"/>
<xsl:variable name="tagname">
<xsl:choose>
<xsl:when test="$condition">a</xsl:when>
<xsl:otherwise>span</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$tagname}">
<xsl:if test="$condition">
<xsl:attribute name="href">#action</xsl:attribute>
</xsl:if>
Action (offensive, defensive, reconnaissance)
</xsl:element>(在火狐中,如果我们将$tagname设置为空字符串,那么该元素将不会被应用。但是处理器也可以raise an error,所以不要依赖它。)
发布于 2010-07-21 23:03:35
什么不存储字符串Action(..)放到一个变量中,然后放到代码中?
https://stackoverflow.com/questions/3300645
复制相似问题