首页 > 解决方案 > 在 XSLT 中定义和调用 Javascript 函数

问题描述

我想在 XSL 文件中定义一个函数,并使用它来评估 XSL 中的页面属性。我将函数定义如下:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:jsutil="http://www.w3.org/1999/xhtml" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<xsl:output method="html" encoding="utf-8" indent="no" />
        <script type="text/javascript">
        <![CDATA[   
        ...
        function replaceTokenUrlCustomerInfo(url) {
          ...
          var server_url; 
          ...
          return server_url;
        }

在我的 XSL 中,我以这种方式调用该函数:

 ...
<xsl:element name="iframe">
  <xsl:attribute name="src">
   javascript:replaceTokenUrlCustomerInfo('<xsl:value-of select="DESC_URL"/>'); 
</xsl:attribute>

但是没有调用该函数,在浏览器控制台中我看到错误

ReferenceError:replaceTokenUrlCustomerInfo 未定义

我做错了什么?谢谢 我还有一个问题:我可以通过 Javascript 函数设置 src 属性吗?我只有 onclick 属性的经验

标签: javascriptjqueryxmlxslt

解决方案


推荐阅读