我希望将变量'vari'的前几个字符连接到String abc ='here:
href="{concat('abc=', substring-before('vari', '='))}"
以下是整个片段:
<xsl:template match="report:subelement">
<tr>
<td>
<message>
<xsl:variable name="vari" select="."></xsl:variable>
<xsl:copy-of select="." />
</message>
</td>
<td>
<button type="button" onclick="window.location.href=this.getAttribute('href')" href="{concat('abc=', substring-before('vari', '='))}" >Kill thread</button>
</td>
</tr>
</xsl:template>
这可能是一个微不足道的问题,但我只是在学习xslt。
答案 0 :(得分:0)
你很亲密,但是:
要访问变量的值,您必须使用美元($
)作为前缀。不要将变量名称放在撇号中
因此,试试:
href="{concat('abc=', substring-before($vari, '='))}
这将导致错误,因为您的变量声明与使用情况不在同一上下文中。
变量声明必须位于同一元素或祖先中。将声明放在子元素模板的顶部或<tr
元素中。
更新了工作模板:
<xsl:template match=""report:subelement">
<xsl:variable name="vari" select="."></xsl:variable>
<tr>
<td>
<message>
<xsl:copy-of select="." />
</message>
</td>
<td>
<button type="button" onclick="window.location.href=this.getAttribute('href')"
href="{concat('abc=', substring-before($vari, '='))}" >Kill thread</button>
</td>
</tr>
</xsl:template>