How to import Javascript object in xslt script

拟墨画扇 提交于 2020-01-22 03:42:07

问题


I am using XSLT stylesheet to generate jUnit HTML report which will be sent as an email. Here I want to create Hyperlink in xslt stylesheet and the value of a link is available in the output of javascript "cur['adm-lib']" as mentioned below.

 <script type="text/javascript" language="JavaScript">
        var TestCases = new Array();
        var cur;
        <xsl:for-each select="./testsuite">
            <xsl:apply-templates select="properties"/>
        </xsl:for-each>

<xsl:template match="properties">
    cur = TestCases['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array();
    <xsl:for-each select="property">
    <xsl:sort select="@name"/>
        cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>';
    </xsl:for-each>
  </xsl:template>

Output of above code

<script type="text/javascript" language="JavaScript">
        var TestCases = new Array();
        var cur;

    cur = TestCases['com.hyperion.planning.AllJunitTestCase_DTE'] = new Array();

        cur['adm-lib'] = '/scratch/aime1/planning/ADF/Planning/ModelTest/HspAdmDriver/lib';

I want to make use of value "cur['adm-lib']" as href in below-mentioned code.

<tr>
    <td align="right">Designed for use with <a href="http://www.junit.org">JUnit</a> </td>
</tr>

I have tried something like this but its not working

 <tr>
    <td align="right">Designed for use with <a <xsl:attribute name="href">javascript:returnHyperlink();</xsl:attribute> >JUnit</a> </td>
 </tr>

Can some one please help me with this?


回答1:


Your XSLT code is generating Javascript code: that part is fine. But until the stylesheet has finished execution, and the generated Javascript is executed, the objects and values created by the Javascript code don't exist yet. The XSLT code therefore can't access any of these JS values.

So your XSLT code can't access the value of cur['adm-lib']. It can, however, access data in your original source document: which as far as I can see is simply @value.



来源:https://stackoverflow.com/questions/59517980/how-to-import-javascript-object-in-xslt-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!