Subject: apply xsl format to an xmlhttp request
Posted By: darkhalf Post Date: 9/1/2006 2:44:21 PM
Hi,

Totally new at this, so this is the issue... I get an xml feed back from an xmlhttp query

function api_PSQT(url,string)
{
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req)
    {
        req.onreadystatechange = processReqChange;
        req.open("POST",url,true);
        req.send(string);
    }
}

Now I get back the xml, but how in gods name am I supposed to apply the xsl format sheet to the xml file that I received...

The only way I know how to do it, is when I have the xml file in question, I just add the header at the top of the file.. but is there a way to apply the formatting, and output it to a div's innerHTML?

Thank you in advance!

Reply By: joefawcett Reply Date: 9/2/2006 3:27:13 AM
As your code is IE specific I presume that's your target browser. Given that you would create a msxml2.domdocument.3.0 using client-side code, load the XSLT and use the responseXML.transformNode method, passing in the DOM containing the stylesheet.
Look on msdn.com for msxml and transformNode.


--

Joe (Microsoft MVP - XML)
Reply By: NotesSensei Reply Date: 9/2/2006 9:53:38 AM
You might want to have a look at the Sarissa Library. It does all sorts of things around XMLHTTP and XSLT for you. It's well developed and cross platform: http://sourceforge.net/projects/sarissa/

Hth
:-) stw

If you think education is expensive - try ignorance!
Reply By: darkhalf Reply Date: 9/5/2006 7:31:32 AM
I took a look at the msdn site, and found a segment of code that I tried to implement, but it doesn't work, and I have no clue what I'm going wrong...  I get the error "You have an error The filename, directory name, or volume label syntax is incorrect."  I know that the xml output is fine, as I put it to a text file, changed the ext to xml, and opened it without issue.

var req;

function makeCall(url,data)
{
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req)
    {
        req.onreadystatechange = processChange;
        req.open("POST",url,true);
        req.send(data);
    }
}
function processChange()
{
    //if request shows complete
    if (req.readyState == 4)
    {
        // Load data.
        var source = new ActiveXObject("Msxml2.DOMDocument.3.0");
        source.async = false;
        source.load(req.responseText);
        if (source.parseError.errorCode != 0)
        {
            var myErr = source.parseError;
error ->>>>        alert ("You have error " + myErr.reason);
        }
        else
        {
            // Load style sheet.
            var stylesheet = new ActiveXObject("Msxml2.DOMDocument.3.0");
            stylesheet.async = false
            stylesheet.load("format.xsl");
            if (stylesheet.parseError.errorCode != 0)
            {
                var myErr = stylesheet.parseError;
                alert ("You have error " + myErr.reason);
            }
            else
            {
                // Echo back XSLT output to console
                document.body.appendChild(source.transformNode(stylesheet));
            }
    
        }
    }
}

Reply By: joefawcett Reply Date: 9/5/2006 7:57:57 AM
That's because you're using load instead of loadXML. Either do:
source.loadXML(req.responseText);

or preferably:

source.load(req.responseXML);

The latter requires that responseXML holds an XML document.

--

Joe (Microsoft MVP - XML)
Reply By: darkhalf Reply Date: 9/5/2006 8:34:23 AM
Thank you very much, that was the bit needed!


Go to topic 49293

Return to index page 184
Return to index page 183
Return to index page 182
Return to index page 181
Return to index page 180
Return to index page 179
Return to index page 178
Return to index page 177
Return to index page 176
Return to index page 175