Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2006, 02:44 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default apply xsl format to an xmlhttp request

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!

 
Old September 2nd, 2006, 03:27 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old September 2nd, 2006, 09:53 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to NotesSensei Send a message via Yahoo to NotesSensei
Default

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!
 
Old September 5th, 2006, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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(sty lesheet));
            }

        }
    }
}

 
Old September 5th, 2006, 07:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's because you're using load instead of loadXML. Either do:
Code:
source.loadXML(req.responseText);
or preferably:
Code:
source.load(req.responseXML);
The latter requires that responseXML holds an XML document.

--

Joe (Microsoft MVP - XML)
 
Old September 5th, 2006, 08:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much, that was the bit needed!






Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Request Post XMLHttp : Need Help Kyum BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 5 July 5th, 2007 09:51 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
XmlHttp Request??? firebirdjohn61 Ajax 11 June 4th, 2007 01:11 PM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.