Javascript 通过JQuery将XSLT表上XML标记的值与链接结合起来?
我在.xsl文件中有一个表,其中包含以下内容:Javascript 通过JQuery将XSLT表上XML标记的值与链接结合起来?,javascript,jquery,xml,xslt,Javascript,Jquery,Xml,Xslt,我在.xsl文件中有一个表,其中包含以下内容: <table> <xsl:for-each select="xmlfile/example"> <tr class="clickable"> <td><xsl:value-of select="example_name"/></td> </tr> </xsl:for-each> </table> 我希望表行打开一个带有Google搜
<table>
<xsl:for-each select="xmlfile/example">
<tr class="clickable">
<td><xsl:value-of select="example_name"/></td>
</tr>
</xsl:for-each>
</table>
我希望表行打开一个带有Google搜索查询的选项卡/窗口,通过JQuery将“example_name”的值添加到链接中;类似这样的,但它实际工作的地方:
$(".clickable").click(function(){
window.open("https://www.google.com/search?q=" + "<xsl:value-of select="example_name"/>");
});
$(“.clickable”)。单击(函数(){
窗口打开(“https://www.google.com/search?q=" + "");
});
提前感谢。您不能像示例中的click handler(*)那样从JavaScript调用XSLT或从XSLT调用JavaScript。如果您在服务器端使用XSLT,那么使用XSLT有什么问题
<td><a>
<xsl:attribute name="href">
<xsl:value-of select="concat('https://www.google.com/search?q=', example_name)"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="example_name"/>
</a></td>
如果您必须使用JavaScript打开一个新窗口,那么由于嵌套引用的级别太多,您将陷入麻烦。例如
<td><a>
<xsl:attribute name="href">
<!-- INVALID XML ATTRIBUTE SPECIFICATION
just for demonstrating the problem with nesting single quotes
into single quoted literals into double quoted attributes -->
<xsl:value-of select="concat('javascript:window.open("https://www.google.com/search?q=", example_name)"/>
</xsl:attribute>
<xsl:value-of select="example_name"/>
</a></td>
请参阅此处以获取帮助的技巧
*)许多年前,EXSLT允许XSLT通过JavaScript自定义函数进行扩展,尽管它从未在浏览器中运行。还有Sarissa项目(如2006年左右)将XSLT引入浏览器,此外还有
和特定于浏览器的调用XSLT处理的方法。我相信Saxonica最新的XSLT引擎也已被证明可以运行浏览器端,并且还具有集成功能,如JSON解析,可在此类环境中使用。使用
<table>
<xsl:for-each select="xmlfile/example">
<tr class="clickable" data-query="{example_name}">
<td><xsl:value-of select="example_name"/></td>
</tr>
</xsl:for-each>
</table>
谢谢你的帮助!
$(".clickable").click(function(){
window.open("https://www.google.com/search?q=" + $(this).data('query'));
});