你可以把动作文本作为变量。这个变量仍然出现在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
tag,你可以用
<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>
(在Firefox中,如果我们设置
$tagname
对于空字符串,则根本不会应用该元素。但处理器也可以
raise an error
,所以不要依赖它。)