string
  • variables
  • xslt
  • string-concatenation
  • 2013-05-21 35 views 0 likes 
    0

    我想看到的第一对夫妇的变量“VARI”的人物要连接到的字符串ABC =”在这里:如何连接(的一部分)变量字符串在XSLT

    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

    您非常接近,但是: 要访问变量的值,您必须使用一美元($)作为前缀。不要把变量名放在撇号中。
    因此尝试:因为你的变量声明是不是在相同的上下文中使用

    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> 
    
    +0

    感谢,但如果我声明一个变量怎么能值以后分配给它? –

    +0

    你不能。变量的值不可更改。也许你应该用更完整的例子更新你的问题。 –

    +0

    然后我不明白。如果我不能分配一个值,那我以后可以读取什么? –

    相关问题