Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function script:invoke and according example not working #19

Open
cforney opened this issue Jan 18, 2022 · 4 comments
Open

Function script:invoke and according example not working #19

cforney opened this issue Jan 18, 2022 · 4 comments

Comments

@cforney
Copy link

cforney commented Jan 18, 2022

Hello, and first of all, thank you for making this fantastic framework available to the XML community 馃檹

After installing xslweb-ready-to-run-v4.2.0-windows-x64 I noticed that the example for script:invoke (script extension function) is not working.

To reproduce:

Obviously, the reason for the "404" is that this example is actually missing in examples/xsl/request-dispatcher.xsl.

But when I locally added the following template

<xsl:template name="script-example" match="/req:request[req:path = '/script.html']">
   <pipeline:pipeline>
     <pipeline:transformer name="script" xsl-path="script/script.xsl" log="true"/>
   </pipeline:pipeline>
</xsl:template>

it complains about an Error evaluating ((attr{id=...}, ...)).

I suppose this second error lies in the function itself, but unfortunately my knowledge of Java is so poor that further research from my side would not be useful.

My platform: Windows 10

@maartenkroon
Copy link
Contributor

Hi,

Thanks for reporting this issue (and your kind words about XSLWeb ;-). Somehow the pipeline definition for the script example was removed from request-dispatcher.xsl. This is now restored in the master.

When I execute this example in my development environment, everything works fine. But when I try it in a "ready-to-run" distribution, I indeed get the same error. The reason is that I try to make the "ready-to-run" distribution download as small as possibly by making use of the "modules" mechanism of Java, by only including the Java modules that are actually needed by XSLWeb. So I did include the module "java.scripting" but forgot to include the module "jdk.scripting.nashorn", the actual Javascript implementation for the scripting engine. I will make sure the next versions of XSLWeb will include this necessary module. For now, as a quick fix, you can download https://armatiek.nl/downloads/xslweb/windows-x64.zip and unzip its contents in your existing "{install-dir}\jre" directory, overwriting the existing files. This will add the module "jdk.scripting.nashorn" to your installation.

I do realize that the extension function script:invoke() is not (yet) documented in the XSLWeb documentation. This is because I once read that the Java scripting engine would be deprecated, but that does not seem to be the case anymore (?). I will try to find some time to document this function.

Kind regards,
Maarten

@cforney
Copy link
Author

cforney commented Jan 19, 2022

Dear Maarten, thank you for the prompt analysis and very helpful explanation.

It is particularly useful to know that this only affects the ready-to-run distribution. We use, of course, the WAR distribution in production and the former only for local development.

The solution you proposed worked well for me and fixing script:invoke this way was a breeze.

It would be great if you find time on occasion to document this feature a little more; as well as to have it available also in the future (if that is possible despite the deprecation of Nashorn). In our specific case, we use this functionality of XSLWeb mainly for Markdown-to-HTML Rendering, but its possibilities are endless.

Kind regards from Switzerland,
Chris

@maartenkroon
Copy link
Contributor

Hi Chris,

I added some documention for the script:invoke() function, see Javascript extension function. I also fixed a bug in this function, sometimes a exception was thrown returning a single object (not an array) from the Javascript function.

Kind regards,
Maarten

@cforney
Copy link
Author

cforney commented Jan 24, 2022

Dear Maarten, the description of script:invoke in the documentation is very informative, thank you!

It's great to read that the Nashorn Engine has found a new home in OpenJDK and the feature continues in XSLWeb.

Kind regard, Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants