如何在XSLT中将变量(部分)连接到String

时间:2013-05-21 13:14:40

标签: string variables xslt string-concatenation

我希望将变量'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。

1 个答案:

答案 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>
相关问题