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

标签 javascript xml xslt

我是 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> 的元素等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一些额外的例子。

关于javascript - 在具有某些参数的 xsl 中调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20115246/

相关文章:

javascript - 使用 Angular 更改 Webview URL

javascript - 如何使用多个不断变化的样式表在网站上制作主题?

java - 如何用 JAXB 将空值表示为空元素?

java - 将 java.sql.Time 对象注入(inject)到 bean 中 - spring xml 依赖注入(inject)

arrays - 轻松将xml中的字符串更改为xml中的数组

css - 如何使用 XSLT 文件在 ASP.net 页面中显示 CMS 集合

javascript - 显示与原始密码字符数相同的虚拟密码文本

javascript - 尝试使用 React 单击时更改数组中的 img src

xml - DocBook:指定代码或标记

java 。将 XSL 样式表内部嵌入到 XML 文档中