xsl transform as a string in Javascript

wxdqz

New Member
Is it possible to return the results of an xml/xsl transform as a string using Javascript. I have found XSLTProcessor which provides very useful methods to set parameters in the xsl file which I will need but this doesn't work on IE and earlier versions of Netscape. Here's my code so far

XML File
<?xml version="1.0" ?>
<products category="big stuff">
<item id="123">
<name ref="abc3">Unnamed Item1</name>
<des>C_Description not available</des>
</item>
<item id="456">
<name ref="abc1">Unnamed Item2</name>
<des>B_Description not available</des>
</item>
<item id="789">
<name ref="abc2">Unnamed Item3</name>
<des>A_Description not available</des>
</item>
</products>

Simple XSL File
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="products/item">
<p>
<xsl:value-of select="name"/>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Here's the section of my Javascript (at the bottom) that I wish to have the transformation returned as a string. All it does so far is successfully read in the xml file.


function initatepage(itemcategory, startPos) {
myxmlfile = 'xmls/'+itemcategory+'.xml';

if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument('', '', null);
xmlDoc.addEventListener('load', loadHandler, false);
xmlDoc.load(myxmlfile);
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function() {
if(xmlDoc.readyState == 4) loadHandler()
};
xmlDoc.load(myxmlfile);
}
else
{
alert(getIncompatMsg());
return;
}

function loadHandler () {
// here's where I want to get the transformation as a string
so that I can pass it as a result to another function to add it to a page

} // end loadHandler

} // end initatepage


Hope you can help

Carl
 
Back
Top