Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 传递值<;xsl:value of>;添加到java脚本函数_Javascript_Xslt - Fatal编程技术网

Javascript 传递值<;xsl:value of>;添加到java脚本函数

Javascript 传递值<;xsl:value of>;添加到java脚本函数,javascript,xslt,Javascript,Xslt,我想做这项工作: 我有一个xml文件,我想用xslt将其转换为HTML文件。看起来是这样的: <article id="3526"> <name>Orange</name> <preis stueckpreis="true">15.97</preis> <lieferant>Fa.k</lieferant> </article> 您必须了解,虽然某些XSLT处理器(如Mi

我想做这项工作:

我有一个xml文件,我想用xslt将其转换为HTML文件。看起来是这样的:

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

您必须了解,虽然某些XSLT处理器(如Microsoft的MSXML)支持在XSLT内部使用JScript中实现的扩展函数,但您只需访问JScript引擎实现的对象和方法即可<代码>警报不是JScript函数,它是在浏览器内部向JScript公开的函数

因此,在XSLT的JScript扩展函数中没有可用的
alert
,您可以在中记录对象、函数和方法

举个例子,是一个引用XSLT1.0样式表的XML文档,Mozilla使用一些EXSLT扩展函数,IE使用JScript中实现的扩展函数

样式表如下所示:

<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>

函数simfunc(msg)
{
返回消息。替换(/^Fa./,'');
}
贝斯皮尔
贝斯皮尔


您好,谢谢您的完整回答。据我所知,在XSL文件中调用
函数firstfun{alert(Hallo);}
然后调用这个java脚本函数或传递一个值是不可能的,正确吗?
是在HTML或SVG中使用脚本的方式。如果XSLT生成HTML或SVG,当然可以在生成的HTML或SVG中使用脚本。如果您想在XSLT代码本身中使用脚本,那么在浏览器世界中,某些XSLT处理器支持使用MSXML作为XSLT处理器,并且支持使用JScript或VBScript,就像我在示例(针对JScript)中显示的那样。但是您可以访问脚本引擎实现和提供的对象和函数<代码>警报是由浏览器而不是脚本引擎公开的功能,因此您无权访问它。
<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>