JavaScript Call in stylesheet and Saxon

2007-06-25
2012-10-08
  • Serge Emmanuel

    Serge Emmanuel - 2007-06-25

    Hello all Saxon Gurus,

    I am making some performance enhancemnt in some stylesheets written for XALAN Processor. The deal is to change XALAN
    with SAXON and to see how fast saxon can be in comparison to xalan.
    Now this the situation, I figure out that some stylesheets have javascript extension (xmlns:js="http://www.mozila.org/rhino", ...)
    and then call javascript method through this extension. the question now is, how can change the javascript namespace so that I can use it with SAXON
    or what is the best practices to solve this problem without grandiose change in may stylesheet.

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:js="http://www.mozila.org/rhino"
    xmlns:math="http://exslt.org/math"
    ...
    extension-element-prefixes="js"
    version="1.0"
    exclude-result-prefixes=""
    >

         &lt;!-- ******************************************* --&gt;
    &lt;!-- JavaScript functions                        --&gt;
    &lt;lxslt:component prefix=&quot;js&quot; elements=&quot;&quot; functions=&quot;&quot; &gt;
        &lt;lxslt:script lang=&quot;javascript&quot; src=&quot;JavaScriptCode.js&quot; /&gt;
    &lt;/lxslt:component&gt;
    
        &lt;!-- Lookup a db param and make it to the output --&gt;  
    &lt;xsl:template name=&quot;someParam&quot;&gt;
        &lt;xsl:param name=&quot;PName&quot; /&gt;
    
        &lt;!-- lookup that parameter --&gt;        
        &lt;xsl:variable name=&quot;PNode&quot; select=&quot;@*[local-name()=$PName]&quot; /&gt;
    
        &lt;!-- parameter is present --&gt;
        &lt;xsl:if test=&quot;boolean($PNode)&quot; &gt;
            &lt;!-- set the db field in the appropriate global variable --&gt;
            &lt;xsl:variable name=&quot;tmp&quot; select=&quot;js:setFunctions(local-name(),$PName,string($PNode))&quot; /&gt;
        &lt;/xsl:if&gt;
                .....
    
    &lt;/xsl:template&gt;
    

    <xsl:stylesheet/>

    Thanks for advance.

     
    • Michael Kay

      Michael Kay - 2007-06-25

      Saxon doesn't have any direct capability to call out to Javascript. You've got a number of options

      (a) rewrite the Javascript in XSLT (often possible given XSLT 2.0's extra power)

      (b) rewrite the Javascript in Java

      (c) call the Javascript via a Java wrapper.

      Michael Kay
      http://www.saxonica.com/

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks