【问题标题】:Calling a javascript function in xsl having some argument在具有某些参数的 xsl 中调用 javascript 函数
【发布时间】:2013-11-21 07:51:28
【问题描述】:

我是 xsl 的新手,我想调用一个函数 podInfo(),参数是我在 xsl 中捕获的 xml doc 的一些属性值。但是函数调用不正确,任何人都可以建议我是对的。下面是sn-p

<xsl:variable name="xx" select="@name"/>
<td>
   <a href="#" onclick="podInfo(<xsl:value-of select="$xx"/>)">
       <xsl:value-of select="@name"/>
   </a>
</td>

【问题讨论】:

    标签: javascript xml xslt


    【解决方案1】:

    您需要使用&lt;xsl:attribute&gt; 元素,这将允许您轻松编写onclick,即通过使用&lt;xsl:value-of&gt; 等元素。Here is the XSLT2 spec 关于此元素。

    应该是这样的:

    <a href="#">
      <!-- xsl:attribute means that instead of putting it's result
           into output document, they will be placed as an attributes
           value of parent element (<a> in this case) -->
      <xsl:attribute name="onclick">
         podInfo(<xsl:value-of select="$xx"/>)
      </xsl:attribute>
      <xsl:value-of select="@name"/>
    </a>
    

    有关其他示例,请参阅 this answer

    【讨论】:

    • 另一种方式可能是 ...
    猜你喜欢
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多