JavaScript function within XSL


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JavaScript function within XSL

  1. #1
    Igor Guest

    JavaScript function within XSL


    Hi folks,
    I would like to execute javaScript function within xsl file and display the
    result.
    Please see my sample xsl file below.

    <?xml version="1.0"?>
    <HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <BODY BGCOLOR="#ffffff">
    <head>
    <xsl:script language="JavaScript">
    <![CDATA[
    function convertComments(comments)
    {
    var decodeMsg = comments.replace(/%6/g,"\r\n");
    var decodeMsg = decodeMsg.replace(/%8/g,"\r");
    var decodeMsg = decodeMsg.replace(/%22/g,"\"");
    var decodeMsg = decodeMsg.replace(/%27/g,"'");
    var decodeMsg = decodeMsg.replace(/%7C/g,"|");
    var decodeMsg = decodeMsg.replace(/~/g," ");
    convertComments = decodeMsg;
    }
    ]]>
    </xsl:script>
    </head>
    <xsl:for-each select="RowSet/Row">
    <TABLE border="0" cellPadding="0" cellSpacing="0" width="535">
    <TD width="45" valign="top">Comments :
    <xsl:eval>convertComments('+<xsl:value-of select="comments"/>+'); </xsl:eval>
    </TD>
    <TR><TD colspan="3"><hr></hr></TD></TR></TR>
    </TABLE>

    </xsl:for-each>
    </BODY>
    </HTML>

    All I actually need to do is pass <xsl:value-of select="comments"/> to the
    JavaScript function and display the result. The above example would not work
    saying that I cannot use <xsl:value> within <xsl:eval>. I can use to display
    JavaScript variable that has been set within function, but how to pass value
    to JavaScript.
    Please advise.
    Thanks
    Igor


  2. #2
    Robert Guest

    Re: JavaScript function within XSL


    I would like to know also. I'm trying to pass a JavaScript variable to a
    XSLT variable.

    Robert



    "Igor" <irodionov@hotmail.com> wrote:
    >
    >Hi folks,
    >I would like to execute javaScript function within xsl file and display

    the
    >result.
    >Please see my sample xsl file below.
    >
    ><?xml version="1.0"?>
    ><HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    ><BODY BGCOLOR="#ffffff">
    ><head>
    ><xsl:script language="JavaScript">
    >[CDATA[
    >function convertComments(comments)
    >{
    > var decodeMsg = comments.replace(/%6/g,"\r\n");
    > var decodeMsg = decodeMsg.replace(/%8/g,"\r");
    > var decodeMsg = decodeMsg.replace(/%22/g,"\"");
    > var decodeMsg = decodeMsg.replace(/%27/g,"'");
    > var decodeMsg = decodeMsg.replace(/%7C/g,"|");
    > var decodeMsg = decodeMsg.replace(/~/g," ");
    > convertComments = decodeMsg;
    >}
    >]]
    ></xsl:script>
    ></head>
    ><xsl:for-each select="RowSet/Row">
    > <TABLE border="0" cellPadding="0" cellSpacing="0" width="535">
    > <TD width="45" valign="top">Comments :
    > <xsl:eval>convertComments('+<xsl:value-of select="comments"/>+'); </xsl:eval>
    > </td>
    > <TR><TD colspan="3"><hr></hr></td></tr></tr>
    > </table>
    >
    ></xsl:for-each>
    ></body>
    ></html>
    >
    >All I actually need to do is pass <xsl:value-of select="comments"/> to the
    >JavaScript function and display the result. The above example would not

    work
    >saying that I cannot use <xsl:value> within <xsl:eval>. I can use to display
    >JavaScript variable that has been set within function, but how to pass value
    >to JavaScript.
    >Please advise.
    >Thanks
    >Igor
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center