 |
| 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
|
|
|
|

September 1st, 2006, 02:44 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

September 2nd, 2006, 03:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

September 2nd, 2006, 09:53 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

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

September 5th, 2006, 07:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

September 5th, 2006, 08:34 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you very much, that was the bit needed!
|
|
 |