gpt4 book ai didi

javascript - 传递值 to a java script function

转载 作者:行者123 更新时间:2023-11-30 06:30:36 26 4
gpt4 key购买 nike

我想做这份工作:

我有一个 xml 文件,我想用 xslt 将它转换成一个 HTML 文件。它看起来像这样:

<article id="3526">
<name>Orange</name>
<preis stueckpreis="true">15.97</preis>
<lieferant>Fa.k</lieferant>
</article>

我想在 HTML 文件中显示 lieferant。如果用户单击该名称,将出现一个警告并显示 preis

我不知道,如何将 preis 的值传递到 java 脚本代码中。我试图编写一个非常简单的代码来仅显示带有 javascript 警报的 lieferant,但我无法做到这一点。你能帮我解决这个问题吗:

 <msxsl:script language="JScript" implements-prefix="user">
function simfunc(msg)
{
alert(msg);
}
</xsl:script>
</head>
<xsl:for-each select="//artikel">
<div>
<p id='p1' >
<xsl:value-of select="user:simfunc(lieferant)"/>
</p>
</div>
<br/>
</xsl:for-each>

最佳答案

您必须了解,虽然某些 XSLT 处理器(如 Microsoft 的 MSXML)支持在 XSLT 内部使用以 JScript 实现的扩展函数,但您只需访问 JScript 引擎实现的对象和方法即可。 alert 不是 JScript 函数,它是在浏览器内部暴露给 JScript 的函数。

因此在 XSLT 的 JScript 扩展函数中没有可用的 alert,您拥有 http://msdn.microsoft.com/en-us/library/hbxc2t98%28v=vs.84%29.aspx 中记录的对象、函数和方法.

举个例子,http://home.arcor.de/martin.honnen/xslt/test2013072701.xml是引用 XSLT 1.0 样式表的 XML 文档,Mozilla 使用一些 EXSLT 扩展函数,IE 使用 JScript 中实现的扩展函数。

样式表 http://home.arcor.de/martin.honnen/xslt/test2013072701.xsl如下:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:user="http://example.com/user"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:regexp="http://exslt.org/regular-expressions"
extension-element-prefixes="ms"
exclude-result-prefixes="user ms regexp"
version="1.0">

<xsl:output method="html" version="4.01" encoding="UTF-8"/>

<ms:script language="JScript" implements-prefix="user">
function simfunc(msg)
{
return msg.replace(/^Fa./, '');
}
</ms:script>

<xsl:template match="/">
<html lang="de">
<head>
<title>Beispiel</title>
</head>
<body>
<h1>Beispiel</h1>

<xsl:for-each select="//artikel">
<div>
<p id="{generate-id()}">
<xsl:choose>
<xsl:when test="function-available('regexp:replace')">
<xsl:value-of select="regexp:replace(lieferant, '^Fa\.', '', '')"/>
</xsl:when>
<xsl:when test="function-available('user:simfunc')">
<xsl:value-of select="user:simfunc(string(lieferant))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="lieferant"/>
</xsl:otherwise>
</xsl:choose>
</p>
</div>
</xsl:for-each>

</body>
</html>
</xsl:template>

</xsl:stylesheet>

关于javascript - 传递值 <xsl :value-of> to a java script function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17897251/

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