gpt4 book ai didi

javascript - 在 XSL 中包含带有大括号 {} 的内联 JavaScript

转载 作者:可可西里 更新时间:2023-11-01 01:30:20 24 4
gpt4 key购买 nike

我正在尝试通过 XSL 文件将 XML 转换为 HTML。不幸的是,它不允许我使用 JavaScript 花括号 {}。以下是一个简单的示例,但我的实际代码要大得多。

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output media-type="text/html; charset=UTF-8" encoding="UTF-8"/>
<xsl:template match='/'>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Page Title</title>
</head>
<body onload="javascript: if(confirm('Are you sure?')) { return true;} else { return false;}">
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Visual Studio 给我以下错误:

Expected token '}', found 'true'.  ...firm('Are you sure?')) { return  -->true<-- ;} else { return false;}  

有什么方法可以在 XSL 中包含内联 JavaScript 吗?我知道你可以使用 <![CDATA[ ]]>转义 Javascript block 。但是如何转义内联 JavaScript?我的实际代码太大,无法将所有内联 JavaScript 重写为脚本 block 。

最佳答案

文字结果元素属性中的花括号用于“属性值模板”,包含 XPath 表达式。所以如果你想生成包含 curl 的属性,你需要通过加倍来转义它们:

<body onload="javascript: if(confirm('Are you sure?')) {{ return true;}} else {{ return false;}}">

但是,无论如何最好避免在 onXXX 属性中包含大块 Javascript:相反,只需包含对 <script> 中定义的代码的函数调用。 .

关于javascript - 在 XSL 中包含带有大括号 {} 的内联 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17198163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com