Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] XSLT interacting with Javascript

From: Robert G <nyjets3422@-----.--->
To: xsl-list@-----.------------.---
Date: 6/2/2009 5:19:00 PM
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>



      

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent