Friday, July 27, 2012

Putting Javascript in an XSLT Stylesheet

There was some code from a previous developer that I had to edit. He had used XML and an XSLT stylesheet to display a form to the user. I needed to add some javascript to hide and show a div when an existing button was clicked. There was an <xsl:template tag and I had to put the script tags and the javascript in there.


<xsl:template match="/*">
    <script language="JavaScript" xmlns:msxsl="urn:schemas-microsoft-com:xslt" >

      function toggle(ID)
      {
      var element = document.getElementById(ID);

      if(element.style.display == "block")
        {
          element.style.display = "none";
        }
      else
        {
          element.style.display = "block";
        }
      }
    </script>

No comments: