[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT interacting with Javascript

Subject: XSLT interacting with Javascript
From: Robert G <nyjets3422@xxxxxxxxx>
Date: Tue, 2 Jun 2009 10:18:48 -0700 (PDT)
 XSLT interacting with Javascript
I have a single html page start with random information on it, then replaces a <div> with new info, which it gets via client-side javascript. The Javascript takes my XSL and XML file and transforms it fine but when I want to add more javascript to using my xsl file it puts the javascript in the html page code but is not runnable. I have tried a bunch of things to get the javascript to work but nothing seems to work. Only the html pages javascript works. I am trying to get this to work on Firefox.

Heres the code. In this example, the button that is on the screen does not work, and the error console says the function is not defined. I have tried putting CDATA tag around the javascript, and tried setting trythis=function() but none of that worked.

HTML Page

<html>

<head>
<script>
function displayResult()
{
// code for IE
if (window.ActiveXObject)
  {
       **** TRYING ON FIREFOX FIRST*****************
  }
           
 // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation && document.implementation.createDocument)
{
              
    xml=document.implementation.createDocument("","",null);
    xml.async=false;
    xml.load("test.xml");

    xsl = document.implementation.createDocument("","",null);
    xsl.async=false;
    xsl.load("newer.xsl");
        
    var xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    xsltProcessor.setParameter(null,"type","html");
    xsltProcessor.setParameter(null,"type2","java"); 
  
    var result= xsltProcessor.transformToDocument(xml);
    var serial= new XMLSerializer();
    var out= serial.serializeToString(result.documentElement);
    var output= document.getElementById("example");
    output.innerHTML=out;
               
}
}
</script>
<title>Another Test Page </title>
</head>

<body onLoad='displayResult()'>
<p>Before change <p>

<div id="example">THis is GONE! </div>

<p>After change </p>

</body>
</html>



XSL file

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="type"/>
<xsl:param name="type2"/>
<xsl:output method="html"/>
<xsl:template match="/">
                
                <xsl:apply-templates select="page/content"/>

</xsl:template>
        <xsl:template match="content">
        
         <xsl:if test="$type2 = 'java'">
                <script type="text/javascript">
                function trythis(){
                        alert("IT WORKS!") 
                }
                </script>
          </xsl:if>
          
          <xsl:if test="$type = 'html'">
                <h2> Heres a Page </h2>
                <p> A paragraph </p>
                <p> More paragraphs </p>
                <input type="button" value='try' onclick='trythis()'/>             
          </xsl:if>
        
        </xsl:template>
</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.