xslt - XSL Transformation with Javascript - Stack Overflow

I looking for a good example how inject javascript inside of XSLT file and then will be transformed int

I looking for a good example how inject javascript inside of XSLT file and then will be transformed into html. My transformation works very well, but when I following every documentation about adding Script occur error [ERROR]: Cannot find class 'randomString'. [ERROR]: Cannot find external method 'randomString.getZoom' (must be public).

<xsl:stylesheet version="1.0" xmlns:xsl=";
                xmlns:exsl=";
                extension-element-prefixes="exsl"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="randomString">

    <msxsl:script language="JScript" implements-prefix="user">
        function getZoom() {
        return "#zoom=100";
        }
    </msxsl:script>
<body>
  <xsl:value-of select="user:getZoom()"/>
</body>

Many guys put there some kind of example inside of xmlns:user,but that namespace should be everything,right ? Anyway I need get that string "#zoom=100" into my html body, how ?

I tried get that String into html body.

I looking for a good example how inject javascript inside of XSLT file and then will be transformed into html. My transformation works very well, but when I following every documentation about adding Script occur error [ERROR]: Cannot find class 'randomString'. [ERROR]: Cannot find external method 'randomString.getZoom' (must be public).

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3./1999/XSL/Transform"
                xmlns:exsl="http://exslt./common"
                extension-element-prefixes="exsl"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="randomString">

    <msxsl:script language="JScript" implements-prefix="user">
        function getZoom() {
        return "#zoom=100";
        }
    </msxsl:script>
<body>
  <xsl:value-of select="user:getZoom()"/>
</body>

Many guys put there some kind of example inside of xmlns:user,but that namespace should be everything,right ? Anyway I need get that string "#zoom=100" into my html body, how ?

I tried get that String into html body.

Share Improve this question asked Jan 29 at 8:00 MichalMichal 11 bronze badge 8
  • This may depend on the Xslt processor you are using - msxsl:script will only work with Microsoft, so if you are using Saxon or Xalan you'll have to adopt their flavor of inline scripting. – Filburt Commented Jan 29 at 9:03
  • 2 'I need get that string "#zoom=100" into my html body": why would you need JScript or JavaScript or anything else but XSLT to achieve that? Which software do you use exactly that gives that error message? Provide enough information to allow anyone to reproduce the problem. – Martin Honnen Commented Jan 29 at 9:19
  • so when I add to pom saxon or xalan depedencie ,that should work ? I using transformation from inteljic idea ,which is embeded – Michal Commented Jan 29 at 9:23
  • I don't think Saxon has any support for running JavaScript or JScript from XSLT. And it supported version 10, 11, 12 are all XSLT 3 processors anyway, since XSLT 2 you have xsl:function as part of the XSLT language instead of needing to delegate work to functions in a proprietary/platform specific scripting language. – Martin Honnen Commented Jan 29 at 9:26
  • 1 Don't expect JavaScript run inside of XSLT to know anything about web page properties like the zoom factor; if supported at all it is a pure J(ava)Script core engine with Number, Date, String, Regex. Perhaps using JavaScript inside an HTML document rendered in a browser allows that but then that has nothing to do with XSLT, the HTML can be created anyway, whether it is the result of XSLT or not, and there is no interaction between script run in the transformation result and code executed to produce the transformation result. – Martin Honnen Commented Jan 29 at 9:36
 |  Show 3 more comments

1 Answer 1

Reset to default 0

Summarising what we have learned from the comments thread.

You appear to be using the XSLT processor bundled with the IntelliJ Java IDE, which is probably the version of Xalan that ships with the JDK. This is an XSLT 1.0 processor and it has no support for the Microsoft msxsl:script extension, which is available only in Microsoft XSLT processors.

You appear to be trying to generate an HTML page that contains Javascript functions to implement behaviours such as detecting the user zoom level. Generating HTML that contains Javascript code is no different from generating any other HTML, you don't need Javascript in the XSLT in order to generate Javascript in the HTML.

An alternative design would be to run XSLT within the browser. Take a look at SaxonJS (disclaimer: my company's product). This allows you to write XSLT code that responds directly to user events in the browser, rather than the indirect approach of writing XSLT to generate Javascript to respond to the events.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745305735a4621697.html

相关推荐

  • xslt - XSL Transformation with Javascript - Stack Overflow

    I looking for a good example how inject javascript inside of XSLT file and then will be transformed int

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信