okMonty okMonty - 6 months ago 19
Javascript Question

How can I use javascript to transform xml & xslt

I want to use JavaScript to show my XSLT, but on my server nothing is showing up in the browser.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<meta http-equiv="Content-Language" content="en-us"/>
<title>Contracting, Licensing and Compliance News</title>
<script language="javascript">
function displayMessage() {
// Load XML

var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false

// Transform


The browser can perform the tranform for you. No javascript is needed, just link the .xsl from the .xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="site-index.xsl" ?>

and just serve the xml, no html. Assuming your .xsl contains the right code, along the lines

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.01" indent="yes"/>
<xsl:output doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
<xsl:output doctype-public="-//W3C//DTD HTML 4.01//EN"/>