www.webdeveloper.com
Results 1 to 4 of 4

Thread: Using Javascript in XSL

  1. #1
    Join Date
    Nov 2003
    Location
    Bangalore, India
    Posts
    2

    Using Javascript in XSL

    Am relatively new to XML and XSL. Below is an excerpt of the code that I am using.

    I am trying to perform a transformation from XML to HTML and doing some validation in Javascript embedded in XSL file. Whenever I use the statement "if (i>100)" as in below code it throws error, but when I use the statement "if ('i>100')" i.e. the condition present within single quotes, it does not give errors but returns true for the condition even if it is logically false. In other words maybe it does not evaluate the condition ? Any, insights on how to solve this since I have to base decisions on value being higher or lesser ?

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" result-ns="">
    <xsl:template match="/">
    <html>
    <head>
    <script language="javascript">
    var l_index=0;
    ...
    ...
    function pop_array()
    {
    ...
    ...
    if (i>100)
    break;
    if ('i>100')
    break;
    l_index=l_index+1;
    }
    ...
    ...
    </script>
    </head>
    <body>
    <xsl:apply-templates select="linkdetails"/>
    <script language="javascript">
    ...
    ...
    </script>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="linkdetails">
    <xsl:apply-templates select="linkrow"/>
    </xsl:template>
    ...
    ...
    </xsl:stylesheet>

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    put javascript code between <xsl:text> tag something like below

    <script type="text/javascript>
    <xsl:text>

    javascript here

    </xsl:text>

    </script>
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    37
    or..u could do this...

    <xsl:comment><![CDATA[
    function pop_array()
    { .....

    }

    ]]> </xsl:comment>

    This should fix the problem ur having...

    HTH

  4. #4
    Join Date
    Nov 2003
    Location
    Bangalore, India
    Posts
    2
    Thanks for the reply. That solved the problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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



Recent Articles