在xsl中调用具有某些参数的javascript函数

Calling a javascript function in xsl having some argument

本文关键字:参数 javascript 函数 xsl 调用      更新时间:2023-09-26

我是xsl的新手,我想调用函数podInfo(<agr>),参数是我在xsl中捕获的xml文档的一些属性值。但是函数调用不正确,有人能建议我吗。下面是的片段

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

您需要使用<xsl:attribute>元素,这将使您能够轻松地编写onclick,即通过使用<xsl:value-of>等元素。以下是有关此元素的XSLT2规范。

它可能类似于:

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

有关其他示例,请参见此答案。